Hello,
I am testing a sketch which do some measures and them composed a String wich is sended by http client.
It works well but about once a day, the Photon restarts.
I have read some people has the same problem using HTTP Client library (Photon Problem - http.get(request, response, headers) Causing reset) and the problem could be produced by something related with the dynamic memory and the inneficient use of strings. I am using 0.4.7 firmware in the photon.
Here is the part of the code where I prepare the data before sending:
request.path = "/emoncmsmonitor/input/post.json?&apikey="APIKEY"&node="+String(NODE)+"&json={voltage:"+String(emontx.Vrms)+",iload:"+String(ct1.Irms)+",pload:"+String(ct1.realPower)+",PACKETS:"+String(packets)+",RESTARTS:"+String(restart)+"}";
delay(100);
http.get(request, response, headers);
delay(1500);
APIKEY is defined as:
#define APIKEY "1d3d56982b3754ad1a2ccf0cf98a1327"
The rest of variables and constants are:
const int NODE = 7;
float emontx.Vrms;
float ct1.Irms;
float ct1.realPower;
int packets;
int restart;
I think it could be improved with the use of sprintf but I cannot achieve to work, it compiles but the data doesn’t arrived.
Here is my try with the sprintf:
char* dataStringToSend;
sprintf(dataStringToSend, "/emoncmsmonitor/input/post.json?&apikey=%s&node=%i&json={ct1Vrms:%1f,ct1Irms:%1f,ct1realpower:%1f,PACKETS:%i}",APIKEY,NODE,emontx.Vrms,ct1.Irms,ct1.realPower,packets);
request.path = dataStringToSend;
delay(100);
http.get(request, response, headers);
delay(1500);
In this code APIKEY is define as: const char APIKEY[33] = "1d3d56982b3754ad1a2ccf0cf98a1327";
With the delays I have better stability results.
When it fails it restarts send some messages, and then restarts again some messages, etc.
Any help will be apreciated. Thanks