When writing a payload to add data to the cloud via arduino+ESP8266 we append the command message with sprintf
sprintf(payload, "{\"");
sprintf(payload, "%s%s\":%s", payload, VAR_LABEL1, A1);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL2, A2);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL3, A3);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL4, A4);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL5, A5);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL6, A6);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL6, P);
sprintf(payload, "%s,\"%s\":%s", payload, VAR_LABEL6, T);
sprintf(payload, "%s}", payload);
Variables Ai, P and T are String variables retrieved from other serial port connected to the device.
if (flow_control) {
Serial3.print("<PE?>");
flow_control = false;
}
delay(100);
if (Serial3.available()) {
while (Serial3.available() > 0) {
char inChar = Serial3.read();
Com += inChar;
flow_control = true;
}
String P = Com.substring(4, 10);
When writing the variable P in the payload an error arises in the arduino’s compilation:
cannot pass objects of non-trivially-copyable type ‘class String’ through ‘…’
Do anyone know how the data must be written in the sprintf function?
Thanks.