Finding Difficulty in retrieving data from bolt cloud to process it in python

I have deployed my sensor data from arduino to bolt cloud using software serial.-

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8,9);

//Constants
//#define DHTPIN 2 // what pin we’re connected to
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
//dht.begin();
Serial.setTimeout(100);

}

String data;
uint8_t dataRead = 0;

void loop()
{

if (mySerial.available() > 0) {
delay(50);
String readData = “”;
Serial.print("Command from Bolt: ");
while (mySerial.available() > 0 ) {
readData = readData + (char)mySerial.read();
}
Serial.println(readData);
if (readData.indexOf(“RD”) != -1) {
String data = sensor_data_to_push();
mySerial.print(data);
Serial.print("Data sent to Bolt: ");
Serial.println(data);

}

}
}

String sensor_data_to_push() {
String data;
int mois = 1023-analogRead(A2);
int lig = analogRead(A3);
// temp = temp * 1.8 + 32; // convert Celsius to Farenheit
data = String(mois) + “,” + String(lig);

return data;
}

I can see this data on bolt cloud but when i want to retrieve this data how can i do it . I have tried it by doing so in python-
from boltiot import Bolt
import json, time

minimum_limit = 300
maximum_limit = 600

#Bolt credentials
api_key= “9e68c6fc-fcf7-42a2-b5a6-01837af8d57a”
device_id=“BOLT5775464”

mybolt = Bolt(api_key,device_id)
mybolt.serialBegin(‘9600’)
mybolt.serialWrite(‘RD/r’)
response= mybolt.serialRead(‘10’)
print(response)
while True:
print (“Reading sensor value”)
response = mybolt.analogRead(‘CSV0’)
print(response)
data = json.loads(response)
print(data)
print("Moisture is: " + str(data[‘value’]))
try:
sensor_value = int(data[‘value’])
print(sensor_value)
except Exception as e:
print (“Error occured: Below are the details”)
print (e)
time.sleep(10)

** I have used CSV0 inplace of bolt pins as mentioned in bolt cloud. But then it results in invalid pin . What should be the code to retrieve cloud data in python when i have used software serial. Please help

Use mybolt.analogRead(‘A0’)
CSV0 is a predefined variable in bolt cloud.
You can try this, but I am unsure if you will get the output.

Next time when uploading code snippets here, use code blocks.

I can’t used A0 as that will be the bolt’s analog pin. I am taking input through arduino. I have used that pin as while coding i have matched my variable to that pin

. I want to take dataset that i have uploaded in bolt cloud to process it in python. how can i call that data set to python. plz help.

You cannot retrieve the data that is visible in cloud. The bolt cloud platform is itself using commands like analogRead and using that data to view it on the site.

Now, if you wish to use python, then you have to separately use the bolt module to read the serial monitor and check for analog inputs in the Arduino board.

You have to write a code that functions the SAME as the bolt cloud. (Using serialRead taking inputs from the serial monitor and using the data to actuate it)

To do this, you can use UART functions on python.

If you need any other information do tell.


Sir I have to first download data set in bolt cloud then have to read it as the command stated. Is there any means by which i can automate this thing. I mean as data is sent to cloud data set in my python gets updated. Please share its code to automate it.

You can download the Bolt data from the graph page by clicking on the Data Download button. The other option is to fetch the data using the API and then save the data using in csv file using the Python code.

import csv
import json
import datetime


from boltiot import Bolt

api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
device_id  = "BOLTXXXXXX"
mybolt = Bolt(api_key, device_id)
response = mybolt.analogRead('A0')
data = json.loads(response)
sensor_data = data.get("value")

current_time = datetime.datetime.now()

with open("data.csv", "wt") as fp:
    writer = csv.writer(fp, delimiter=",")
    writer.writerow([sensor_data, current_time]) 

As I have mentioned earlier already, the python programs and the cloud platofrm does the SAME thing. You can create your separate csv file or graph from Python.

You can even create custom graphs without having to open cloud.boltiot.com.

You can even write python programs to control the module WITHOUT the boltiot module.

All of it is possible. But what you are asking is to use the python to read the graph in the cloud.boltiot.com. Which is even more difficult task to do. Because your graph is available to you with a login process only.