I have a particle photon, and my device eventually goes offline after a few days, and the only way to recover is to reboot. The main loop is blocked when this occurs, although software timers still seem to work.
I added some logic to try to reconnect to wifi and/or the particle cloud, along with some verbose serial logging to figure out exactly where it was blocking. Here are the relevant bits of my code:
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
void setup() {
WiFi.selectAntenna(ANT_AUTO);
Particle.connect();
}
void loop() {
Serial.println("Loop-de-loop");
if (!Particle.connected()) {
Serial.println("Oh Noes, Detached Connection!");
if (!WiFi.ready()) {
Serial.println("No wifi");
if (WiFi.connecting()) {
Serial.println("Wifi is connecting");
} else {
Serial.println("Connecting to wifi, please stand by");
WiFi.connect();
}
} else {
Serial.println("We gots wifi");
Serial.println("Attempting connection");
Particle.connect();
Serial.println("Waiting for connection");
waitFor(Particle.connected, 10000);
Serial.println("After connect");
}
} else {
Serial.println("We're connected. Life is good.");
}
}
And here is the serial logging I captured at the point when it disconnected/blocked:
Loop-de-loop
We're connected. Life is good.
Loop-de-loop
We're connected. Life is good.
Loop-de-loop
We're connected. Life is good.
Loop-de-loop
We're connected. Life is good.
Loop-de-loop
We're connected. Life is good.
Loop-de-loop
Oh Noes, Detached Connection!
We gots wifi
Attempting connection
At this point, the photon is blinking green, and never recovers, no matter how long I wait. After I reboot, it immediately connects to the particle cloud with no problem, and stays connected for another few days, until it disconnects and gets blocked again.
Should Particle.connect() be blocking, when the system thread is enabled? Or what is the best to way to make sure this doesn’t happen?
I’m now considering adding my own watchdog implemented as a software timer that just reboots the device if it detects the main loop getting blocked.
Also, I should probably mention this is on 0.6.3 firmware (and on many previous versions as well)