1

So I have successfully been able to post sensor data to thingsboard and read them in nicely using MQTT ( attached my INO code. )

I have been trying to figure out how properly use the sub/pub syntax to read now data back to a different Arduino board where I would use the CO2 sensor data to controll my AC unit (via TriAC).

I have been trying to decypher the sample here https://thingsboard.io/docs/samples/esp8266/gpio/ (and stripping out the GPIO part) but unfortenatelly without success.

This is how I transfer also the CO2 Data:

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(", CO2 PPM: ");
Serial.println(c);

String temperature = String(t);
String humidity = String(h);
String carbonmonoxide = String(c);


// Just debug messages
Serial.print( "Sending temperature, humidity and CO2 : [" );
Serial.print( temperature ); Serial.print( "," );
Serial.print( humidity ); Serial.print( "," );
Serial.print( carbonmonoxide );
Serial.print( "]   -> " );

// Prepare a JSON payload string
String payload = "{";
payload += "\"temperature\":"; payload += temperature; payload += ",";
payload += "\"humidity\":"; payload += humidity; payload += ",";
payload += "\"CO2\":"; payload += carbonmonoxide;
payload += "}";

// Send payload
char attributes[100];
payload.toCharArray( attributes, 100 );
client.publish( "v1/devices/me/telemetry", attributes );
Serial.println( attributes );
delay(5000);

0 Answers0