Data values from arduino to python

I used Arduino to connect three sensors (A0, A1, A2) and then connected the boltiot wifi module to send the data onto the cloud. I successfully completed that part, but now I want to use the values of the three sensors in python.

I tried using different ways, went through even the document of python mentioned in docs.boltiot but it didn’t work for me.

I just need the three different values of these sensors in three different variables so that I can use in python in a flexible way.

Thank you.

Hi @pagadala_sumanth,

You could use bolt python library for this purpose. You could use response = mybolt.analogRead('A0') to store value of A0 pin in variable. Do let me know about the error/problem you are facing after doing this.

Alternatively, you can fetch data using traditional method using API Calls. There are many tutorials available on fetching data from API in python. Your code will be smilar to as below

import requests
import json
response_API = requests.get('https://cloud.boltiot.com/remote/44bxxxxx-xxxxx-40e7-a27f-814b58afe008/analogRead?pin=A0&deviceName=BOLTXXXXX')
print(response_API.status_code)
data = response_API.text
parse_json = json.loads(data)

Do let me know if you need any more help regarding this.

Well, I don’t think this is what I need exactly.
Here is my clear explanation. I used the line


  int var1 = boltiot.processPushDataCommand(moistureValue);
  int var2 = boltiot.processPushDataCommand(cel);
  int var3 = boltiot.processPushDataCommand(ldrStatus);

to push the data to bolt could and I successfully did it and when it comes to the py file I wrote the code as

while(i==0):
    response = mybolt.serialBegin('9600')
    response1 = mybolt.analogRead('A0')
    response2 = mybolt.analogRead('A1')
    response3 = mybolt.analogRead('A2')
    print("Sensor value is: " +response1)
    print("Sensor value is: " +response2)
    print("Sensor value is: " +response3)

(I also changed the mybolt.analogRead to serialread but there is no change in the output)
In return, I got the output as

I didn’t get the individual outputs, all the data was clubbed together

Here is my Arduino code:

Please help to figure this out in a clear way.

Thank you.

You can see in your output value. Output is in Json format. To get the ldr value, temparature value, moisture value. You need to convert response into dictionary format. You can convert json to dictionary with the following code:

import json
while(i==0):
    response = mybolt.serialBegin('9600')
    response1 = mybolt.analogRead('A0')
    response2 = mybolt.analogRead('A1')
    response3 = mybolt.analogRead('A2')
    data = json.loads(response)
    data1 = json.loads(response1)
    data2 = json.loads(response2)
    data3 = json.loads(response3)

After that to get the integer values you need to apply string processing with data[‘value’] attribute

  1. I’m really sorry, I’m very new to the python… I tried to refer other resources, but nothing helped me. Can you please elaborate me regarding the data[‘value’] (I might sound very basic but I really need to learn this.)

  2. Also Why am I getting this notification that

{'value': '56', 'success': 1}
{'value': '48', 'success': 1}
{'value': '55', 'success': 1}
{'value': 'You have been rate limited. Try after 5 Hours:59 Minutes:59 Seconds', 'success': 0}
{'value': 'You have been rate limited. Try after 5 Hours:59 Minutes:59 Seconds', 'success': 0}
{'value': 'You have been rate limited. Try after 5 Hours:59 Minutes:58 Seconds', 'success': 0}
{'value': 'You have been rate limited. Try after 5 Hours:59 Minutes:58 Seconds', 'success': 0}
{'value': 'You have been rate limited. Try after 5 Hours:59 Minutes:58 Seconds', 'success': 0}

I literally run the code for probably one min and I started getting this. Can you please help me with this.

Thank you.

Refer to your 2nd point, You have crossed the allowed threshold of 20 hits in last 1 minute(s).
API requests for your account will be enabled in next: 6 Hours:0 Minutes:0 Seconds. You also get email from bolt cloud regarding this.
For the first point, You have to use only one processPushDataCommand such as

int sensorData1=20;
float sensorData2=20.6;
boltiot.processPushDataCommand(sensorData1,sensorData2);

For more detail read the document https://create.arduino.cc/projecthub/akshayansinha/arduino-with-bolt-iot-c91d72?ref=part&ref_id=11332&offset=4
You have to make a product on Bolt cloud that collect data through UART. Check it from above link.
After that you can use following command UART commands to read data. Refer to the documentation from https://docs.boltiot.com/docs/uart-commands .

while(i==0):
    response = mybolt.serialBegin('9600')
    response1 = mybolt.serialRead(10)
    response2 = mybolt.serialRead(10)   
    response3 = mybolt.serialRead(10)
    print("Sensor value is: " +response1)
    print("Sensor value is: " +response2)
    print("Sensor value is: " +response3)

where 10 is the ascii value of \n. Try this one. Hope it work.

1 Like