I need to send 3 energy sensor readings with one single payload via MQTT.
So what I have done so far.
The 15 float values is in an array ph[0]- ph[14]
I then convert the values to String with dtostrf
char v1[10], c1[10], p1[10], e1[10], pf1[5];
char v2[10], c2[10], p2[10], e2[10], pf2[5];
char v3[10], c3[10], p3[10], e3[10], pf3[5];
// Phase 1
dtostrf(ph[0],2,2,v1);
dtostrf(ph[1],2,2,c1);
dtostrf(ph[2],2,2,p1);
dtostrf(ph[3],2,2,e1);
dtostrf(ph[4],2,2,pf1);
// Phase 2
dtostrf(ph[5],2,2,v2);
dtostrf(ph[6],2,2,c2);
dtostrf(ph[7],2,2,p2);
dtostrf(ph[8],2,2,e2);
dtostrf(ph[9],2,2,pf2);
// Phase 3
dtostrf(ph[10],2,2,v3);
dtostrf(ph[11],2,2,c3);
dtostrf(ph[12],2,2,p3);
dtostrf(ph[13],2,2,e3);
dtostrf(ph[14],2,2,pf3);
Then create a comma separated payload with sprintf
char data[160];
sprintf(data, "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", v1, c1, p1, e1, pf1, v2, c2, p2, e2, pf2, v3, c3, p3, e3, pf3);
mqtt.publish("energy/data", data);
It works for a couple of times and then the program crashes. Is there a better way of sending the info via MQTT , I have a limited amount of band width so I need to send the data with one payload.