I started working on a small weather display recently using a BMP085 sensor, a ILI9340 Display and the Particle Photon connected to my local wireless network.
Everything was working really good, but then I added a request to the weather-api from yahoo to get some more information for my display:
Current implementation:
void GetDataYahoo(int mode){
//Serial.println("GetDataYahoo");
TCPClient client;
if (client.connect("query.yahooapis.com", 80))
{
client.println("GET /v1/public/yql?q=select%20atmosphere%20from%20weather.forecast%20where%20woeid%20%3D%2012835849%20and%20u%20%3D%20'c'&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys HTTP/1.0");
client.println("HOST:query.yahooapis.com\n\n");
String receivedMessage = "";
int timeout = 1000;
while ((!client.available()) && (timeout-- > 0))
delay(1);
if (timeout <= 0)
return ;
while (client.available())
{
char c = client.read();
receivedMessage += c;
}
client.stop();
client.flush();
//Serial.println(receivedMessage);
ParseYahooData(mode, receivedMessage);
}
The requests are working good for minutes, sometimes hours but then I only get a flashing cyan led and the Photon never gets back to working again.
After some research I added the following:
if (!Particle.connected()) {
while(!Particle.connected()) {
Serial.println("Particle.connecte() in Loop");
Particle.process();
}
}
This is called before the Photon hangs, but is not working. It only prints the serial message once and then hangs. If i comment out the yahoo-request the board runs fine with the same firmware. Even the “!Particle.connected()” part is called and working.
I also checked the system memory and let it print it after each loop via the serial terminal and when the “!Particle.connected()” part is run. It always shows the same amount of memory.
I put the Particle.connect() now in the code. I had this exact code from the forum. I thought that the .process() would automatically call the .connect(). (Doesn’t explain why it was working without the yahoo request).
System_Mode and System_Thread are both not changed in my code. They should be standard as defined.
@ScruffR, after two weeks of testing it seems, that the problem still occurs. I came back to my apartment today and found my photon stuck again. The LED is flashing cyan and never reconnects to the cloud.
My current code is as following:
//Connection lost -> wait till reconnected
if (!Particle.connected()) {
while(!Particle.connected()) {
Serial.println("Particle.connecte() in Loop");
Particle.connect();
Particle.process();
}
}
//Connected Loop
if (Particle.connected()) {
...
}
Any ideas?
I will test now with SYSTEM_THREAD(ENABLED) . Maybe that helps!
@ScruffR, a if (!waifFor(Particle.connected, 10000)) could also be used to implement a timeout on the attempt so the code can act accordingly (wait 5 mins before trying again for example).