Read Arduino/DHT sensor through Bolt via Serial connection and SMS

I’ve looked and I can’t find anything specific. I think I’m really close, but am falling short on the last little bit. I want to read the serial data from the arduino and send it via SMS to my phone. I have a Twilio and Digital Ocean account setup and I can send myself text messages via SMS from python code, so I know it’s working. Now I want to take it the next step and connect to my Bolt device, get the Serial data CSV from the arduino and send it SMS to my phone. I’m a mechanical guy, so I’m muddling through most this stuff.

These are my last three lines. I figured if I could get it to read the Serial CSV, I could figure out the SMS part

mybolt = Bolt(api_key, device_id)
response = mybolt.serialBegin(‘9600’)
StringinString = mybolt.serialRead() //I think this is where I’m going wrong, it said it was missing something when I tried to run it. I looked in the Bolt IOT Python reference and it didn’t give a good example.
print(StringinString)

Thanks

So I think I’ve figured this out a little I added ‘10’ to the mybolt.serialRead() and I seem to be getting a success back, I can also pass a string in the browser too, the problem is sometimes I get the temp and humidity back, but most of the time I don’t and using the browser, I get a command time out response too. I don’t know if it’s maybe a timing thing or what. I’m a step closer though. This stuff is pretty cool.

1 Like

Hi @ksprayberry,

Try using the BoltIoT-Arduino-Helper library.

I feel that the example for CommandResponse is best for you.

To use the CommandResponse example, you will have to use the python call for serialWrite every time, just before running the serialRead function.

I think this is going to be very helpful. It’s just going to take me a bit to absorb. Thanks for the help!
Kelly

OK, So I just basically copied the DHT2Cloud program and changed a couple things about it and I am reporting my temp and humidity back to the Bolt cloud, but when I use this string in the browser to read the serial data, I get the below value

https://cloud.boltiot.com/remote/XXXXXXX/serialRead?till=10&deviceName=BOLTXXXX

{“value”: “”, “success”: “1”}

At first I thought it was because I didn’t start Serial communications, so I did this first and then enter the above second, but still got back the same string

https://cloud.boltiot.com/remote/XXXXXXX/serialBegin?baud=9600&deviceName=BOLTXXXX
{“value”: “Success”, “success”: “1”}

https://cloud.boltiot.com/remote/XXXXXXX/serialRead?till=10&deviceName=BOLTXXXX
{“value”: “”, “success”: “1”}

I’m sure it’s a PEBKAC error

Hi @ksprayberry,

I will give you instructions based on the DHT2Cloud example. I think you will be able to use it for your application accordingly.

For the DHT2Cloud example I can access the result of the String pushData(String *data) function by doing the following sequence
Use the serialWrite API to send the data string (This is the command string for the Arduino), ‘GetData’. The API call is as per below
https://cloud.boltiot.com/remote/XXXXXXX/serialWrite?data=GetData&deviceName=BOLTXXXX

Then I would run the serialRead API call as below,
https://cloud.boltiot.com/remote/XXXXXXX/serialRead?till=10&deviceName=BOLTXXXX

to get a response similar to
{“value”: “22,60,1,1”, “success”: “1”}

If I have to access the String getSensorDetail(String *data) function I would do the following.

To get the Max possible value of temperature that could be reported I would first run the serialWrite API call with the data ‘GetSensorDetails.Temperature.Max Value.’. The API call would be like the below link
https://cloud.boltiot.com/remote/XXXXXXX/serialWrite?data=GetSensorDetails.Temperature.Max Value.&deviceName=BOLTXXXX

Then I would use the serialRead API call to get a response as
{“value”: “50*C”, “success”: “1”}

NOTE: The command sent to the Arduino (data in the API call), in this case should have two arguments which are the strings Temperature and Max Value, and should be separated and terminated using the ‘.’ character. This is in accordance with the instructions boltiot.setCommandString("GetSensorDetails",getSensorDetail,2,'.'); used in the setup function.

I hope this helps.

Ahhh Maybe I’m understanding this a little better.

If I run this first
https://cloud.boltiot.com/remote/29f56b5c-c145-4e4d-b9ba-83026df935fd/serialWrite?data=GetSensorDetails.Temperature.Max%20Value.&deviceName=BOLT15015254

I get out put from running this…
https://cloud.boltiot.com/remote/29f56b5c-c145-4e4d-b9ba-83026df935fd/serialRead?till=10&deviceName=BOLT15015254

{“value”: “50.00*C\n”, “success”: “1”}

But if I just run this alone…or hit the refresh button//
https://cloud.boltiot.com/remote/29f56b5c-c145-4e4d-b9ba-83026df935fd/serialRead?till=10&deviceName=BOLT15015254

I get this. {“value”: “”, “success”: “1”}

I’m not a computer guy or even an electrical guy. I can design you a badass air conditioner, work on your car, or build you a really nice wood desk, but some of the technical computer stuff is over my head sometimes…So is this like data that’s in a buffer or something that the cloud takes in and once wrote, it is cleared until it writes it again?

Thank you for your patience!!!
Kelly

I got it! Or, at least I think I do.
thank you!

Hi @ksprayberry,

It is called a command response model.

Imagine that you want to know the time,

If you have a watch, you will look at it, and immediately find out the time.

If you don’t have a watch, you will ask someone the time, that person will check his watch and then tell you the time. This takes longer, and you have to ask for the data, but it is a much better practice for IoT.

Being able to use serialRead directly to read the data is like having a watch. The watch is continuously telling (or rather showing) you the time, regardless of whether you are listening to (or rather looking at). When you do look at the watch, you get the time directly.

If every device that you build has such a system, it will start congesting the IoT communication stream, and then decay your quality of service.

In a standard system, it’s best to ask for the latest data from your end product, so that you have fresh data, and you don’t congest your network.

1 Like

Can I get the complete code for it?
help me I am beginner.