UART Communiaction with Arduino and Bolt

#include <SoftwareSerial.h>
#include <EnvironmentCalculations.h>
#include <BME280I2C.h>
#include <Wire.h>
BME280I2C bme;
SoftwareSerial mySerial(8,9);
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
Serial.setTimeout(100);
}

String data;
uint8_t dataRead = 0;

void loop()
{
Serial.println (data);
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);
}
delay (950);
}
}

String sensor_data_to_push() {
String data;
float temp(NAN), hum(NAN), pres(NAN);

BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);

bme.read(pres, temp, hum, tempUnit, presUnit);

EnvironmentCalculations::AltitudeUnit envAltUnit = EnvironmentCalculations::AltitudeUnit_Meters;
EnvironmentCalculations::TempUnit envTempUnit = EnvironmentCalculations::TempUnit_Celsius;

float altitude = EnvironmentCalculations::Altitude(pres, envAltUnit);
float dewpoint = EnvironmentCalculations::DewPoint(temp, hum, envTempUnit);
float sealevel = EnvironmentCalculations::EquivalentSeaLevelPressure(altitude, temp, pres);
data = String(pres) + “,” + String(temp) + “,” + String(hum) + “,” + String(altitude) + “,” + String(dewpoint) + “,” + String(sealevel);
return data;
}

I have tried doing everything available on the Internet. This code is with BMP280 sensor (An I2C based sensor for the readings of temperature, pressure, humidity, dew point, sea level and altitude. I want that the values put up at at the end of the code i.e. the value of data must be read and interpreted by bolt cloud and a graph must be plotted. I tried using the library but its complex code for the DHT sensor wasn’t comprehended by me. I am using software serial pins 8 and 9.

The error I am seeing is that Bolt is communicating with Arduino (Its lights are blinking after every 5 minutes for receiving data). Arduino is also constantly sending data after every 1 second. But in the bolt cloud line graph I am not able to see anything. The serial monitor is also blank. I checked it after every 5 minutes. Only the monitor scrolls itself each time I open it but no value is registered.

All pins of sensor are accurately connected.
Library for BMP280 sensor: https://github.com/finitespace/BME280.git


You need to send float/int values to the cloud.You are sending strings and it should work if you serialRead() the values using python and then parse it.
Use this library: https://github.com/Inventrom/boltiot-arduino-helper
refer this:https://docs.boltiot.com/docs/arduino-library

#include <EnvironmentCalculations.h>
#include <BME280I2C.h>
#include <BoltIoT-Arduino-Helper.h>

/*

  • With this code the user will be able to use the SerialWrite API
  • to send commands to the Boltduino.
  • The User will also be able to parse the response of the command
  • using the SerialRead API
    */
    #ifndef API_KEY
    #define API_KEY “xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx”//your api key
    #endif
    #ifndef DEVICE_ID
    #define DEVICE_ID “BOLTxxxxxxxx”//your device name
    #endif

void setup(){
boltiot.begin(Serial);
}

void loop(){
float temp(NAN), hum(NAN), pres(NAN);

BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);

bme.read(pres, temp, hum, tempUnit, presUnit);

EnvironmentCalculations::AltitudeUnit envAltUnit = EnvironmentCalculations::AltitudeUnit_Meters;
EnvironmentCalculations::TempUnit envTempUnit = EnvironmentCalculations::TempUnit_Celsius;

float altitude = EnvironmentCalculations::Altitude(pres, envAltUnit);
float dewpoint = EnvironmentCalculations::DewPoint(temp, hum, envTempUnit);
float sealevel = EnvironmentCalculations::EquivalentSeaLevelPressure(altitude, temp, pres);
boltiot.processPushDataCommand(pres, temp, hum, altitude, dewpoint, sealevel);
}

try this.

this code will work for sending data to a server.

Thank you for the prompt reply. I tried your code but I am receiving a NAN value in the .csv file of my graph.
CSV file link

What are the connections of the sensor and the bolt to the arduino?
A5 -> SCL of sensor
A4 -> SDA of sensor
0(Rx) -> Tx of bolt
1(Tx) -> Rx of bolt

yes these are the connections

Have you tried printing the data to arduino serial monitor without bolt?
just add boltiot.begin(Serial); to setup()
remove the Serial.print() lines and add boltiot.processPushDataCommand(pres, temp, hum, altitude, dewpoint, sealevel); to loop();

if it doesnt work then the reading of data from the sensor is incorrect.

1 Like

I don’t have the bme sensor to check unfortunately

I missed the object initialization in the above code
BME280I2C bme;

Yes, without bolt the data on serial monitor shows up without any effort. But with bolt I am getting a NAN on serial monitor also when I click on ‘Push Data to Cloud’.

ya I have added that in my code

Hey guys, a new problem has just emerged. I am getting the data on serial monitor also when I click on Push Data to Cloud but the data does not plot in the graph. Also, in the .csv file there is no data.
@rahul.singh1 please help