I’m working on getting my reconnect loop to work after a long sleep interval (48 minutes).
When resuming from a long sleep I attempt a Publish, if that fails I enter a reconnect loop.
3 attempts to reconnect failing triggers a system reset (which always works).
I’d really like to avoid the system reset (losing SRAM state and other retained data), however so far I cannot get this reconnect loop to work consistently.
Running in SYSTEM_MODE set to SEMI_AUTOMATIC, with SYSTEM_THREAD set to ENABLED.
The timeout for reconnect is 300000ms.
bool ready = false;
#if (PLATFORM_ID == 10)
// 16:MT silent reset (with detach from network and saving of NVM parameters), with reset of the SIM card
ready = Cellular.ready();
#elif (PLATFORM_ID == 6)
ready = WiFi.ready();
// We should be ready to Particle.publish here
System.reset(); // Scorched earth, I want this to never be called
It might be worth noting that the failure rate on the Photon is MUCH higher than the Electron.
I’m wondering if I should also be calling and waiting for Particle.connect here as well?
If you want to keep your variables in tact across a deep sleep or reset you should read about Backup RAM and
We retain timers and some state, but we have a series of startup routines that essentially reset all of our timing (protecting against power loss and getting initial config from our cloud). For this reason it would be great to avoid the reset call.
I guess the big question is what is the System.reset() doing to the modem and CPU that the reconnect logic can’t replicate? A reset always triggers a successful reconnect, but the reconnect logic often fails (forcing a System.reset).
We could check state at startup or try to record a power-loss reason (we use coin-cells for RTC backup) to mitigate the issues, but I’d really like to understand what the flaws are in this code, and improve my understanding of what these things do in the context of the network and cloud connection status.
I’ve had some success using waitFor and Particle.connect() on wake.
It works for electrons reasonably well. Seeing fewer system resets.
When I do need a full modem reset I’ve been using this code, but I don’t think it’s been hit yet:
#if (PLATFORM_ID == 10)
Serial.println("Resetting Cellular Modem");
// Give the modem time to respond
ready = waitFor(Cellular.ready, CLOUD_RECONNECTION_MODEM_TIMEOUT_MS);
// Note: Photons (platform id 6) seem to always need a system reset
// with system firmware 0.5.3