因此,我已经能够成功地将传感器数据发布到事物板上,并使用MQTT(附加了我的INO代码)很好地读取了它们。
我一直在试图弄清楚如何正确地使用sub / pub语法现在将数据读回到另一个Arduino板上,在那里我将使用CO2传感器数据来控制我的AC单元(通过TriAC)。
我一直在尝试解密https://thingsboard.io/docs/samples/esp8266/gpio/处的示例(并剥离了GPIO部分),但是很遗憾没有成功。
这也是我传输CO2数据的方式:
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);