Hello there,
I have a project where I am using a Arduino uno (with esp8266 built in). The arduino reads data from a few sensors and prints them into serial. Since the Serial bus is shared with the esp8266, I have programmed the esp to read and split what the UNO sends (0.00, 486,25.45,5.43,-127.00) (Example). However, with the code, Arduino dashboard is not updating and shows the results as 0.
code for esp8266
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
*****
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float flow_Sensor;
float tDS_Sensor;
float turbidity_Sensor;
int pH_Sensor;
int temp_Sensor;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
//Libary in Use
#include <EEPROM.h>
char rdata;
String myString;
int flowesp, tdsesp, turbesp, phesp, tempesp;
const unsigned int MAX_MESSAGE_LENGTH = 12;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
if (Serial.available() > 0 )
{
rdata = Serial.read();
myString = myString+ rdata;
// Serial.print(rdata);
if( rdata == '\n')
{
String flow = getValue(myString, ',', 0);
String tds = getValue(myString, ',', 1);
String turb = getValue(myString, ',', 2);
String ph = getValue(myString, ',', 4);
String temp = getValue(myString, ',', 5);
flowesp = flow.toInt();
tdsesp = tds.toInt();
turbesp = turb.toInt();
phesp = ph.toInt();
tempesp = temp.toInt();
pH_Sensor = phesp;
temp_Sensor = tempesp;
flow_Sensor = flowesp;
tDS_Sensor = tdsesp;
turbidity_Sensor = turbesp;
}
}
delay(1500);
}
/*
Since TempSensor is READ_WRITE variable, onTempSensorChange() is
executed every time a new value is received from IoT Cloud.
*/
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
void onTempSensorChange() {
// Add your code here to act upon TempSensor change
}
link to arduino board
https://www.jaycar.com.au/uno-with-wi-fi/p/XC4411?pos=10&queryId=c1bd1082b4704951b7f477e8203b2932&sort=relevance
thank you