Я использую esp8266 и Arduino IDE для программирования. Когда я пытаюсь опубликовать sh JSON данные через MQTT topi c из esp8266 по сети Wi-Fi, это работает для приведенного ниже кода.
void reportToServer(){
String payload = "{\"DeviceID\":"+String(devices[0].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[0].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[0].getSwitchOnTime())+","
"\"Status\":"+String(devices[0].getStatus())+"};
Serial.println(payload.c_str());
client.publish("esp/test",payload.c_str());
Serial.println("Reported to server");
}
, но когда я пытаюсь опубликовать код sh, как показано ниже, данные не принимаются в MQTT.Fx GUI клиент -
void reportToServer(){
String payload = String payload = "{{\"DeviceID\":"+String(devices[0].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[0].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[0].getSwitchOnTime())+","
"\"Status\":"+String(devices[0].getStatus())+"},"+
"{\"DeviceID\":"+String(devices[1].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[1].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[1].getSwitchOnTime())+","
"\"Status\":"+String(devices[1].getStatus())+"}}";
+"{\"DeviceID\":"+String(devices[2].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[2].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[2].getSwitchOnTime())+","
"\"Status\":"+String(devices[2].getStatus())+"},"
+"{\"DeviceID\":"+String(devices[3].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[3].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[3].getSwitchOnTime())+","
"\"Status\":"+String(devices[3].getStatus())+"},"
+"{\"DeviceID\":"+String(devices[4].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[4].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[4].getSwitchOnTime())+","
"\"Status\":"+String(devices[4].getStatus())+"},"
+"{\"DeviceID\":"+String(devices[5].getDeviceID())+","
"\"DeviceName\":"+"\""+String(devices[5].getDeviceName())+"\""+","
"\"Counter\":"+String(devices[5].getSwitchOnTime())+","
"\"Status\":"+String(devices[5].getStatus())+"}}";
Serial.println(payload.c_str());
client.publish("esp/test",payload.c_str());
Serial.println("Reported to server");
}