我使用Arduino设备创建了温度传感器,该设备将温度数据写入我的ThingsBoard服务器。一切工作正常,但是我想向草图中添加一个片段,以从ThingsBoard服务器获取返回代码并将其打印到串行监视器(出于调试目的)。谁能指出我正确的方向?
这是草图的相关部分:
float t = sht30.cTemp;
float h = sht30.humidity;
String temperature = String(t);
String humidity = String(h);
// Prepare a JSON payload string
String payload = "{";
payload += "\"temperature\":";
payload += temperature;
payload += ",";
payload += "\"humidity\":";
payload += humidity;
payload += "}";
// Send payload
char attributes[100];
payload.toCharArray( attributes, 100 );
clientPsTB.publish( "v1/devices/me/telemetry", attributes );
我尝试将最后一行替换为:
int returnCodeTB = clientPsTB.publish( "v1/devices/me/telemetry", attributes );
Serial.print( "ThingsBoard Return Code: " );
Serial.println(returnCodeTB);
但这只是吐出“ 1”,所以我认为那是不正确的。