I’ve had an issue that pops up now and then with several of my Electrons. They get into a funky state wherein it appears they are connected to the cellular network, but not connected to the Particle cloud. This had required me to visit the site to do a full power cycle (battery & VIN) in order to clear up the situation. @rickkas7 advised me to try a double-tap of MODE. After it goes into soft-power off mode, wait 10 seconds and then press RESET to get it to successfully start up. This works! The devices are running 0.6.0 or later.
@rickkas7 indicated if the above works (MODE & RESET), I could try introducing code that would put the device into SLEEP_MODE_DEEP for 10 seconds if the device finds itself in a state where Cellular.ready() is true and Particle.connect() is false. So…armed with that suggestion, I believe I can introduce the following to mitigate this problem:
int funkyStateStartTime = 0; // timestamp when funkyState started
boolean funkyState = false; // condition of connected to the cellular network, but not connected to the Particle cloud
int funkyStateTimeLimit = 180; // number of seconds allowed to be in funkyState prior to reset
and then in loop():
if (Cellular.read() && !Particle.connected()) {
if(!funkyState) {
funkyState = true;
funkyStateStartTime = now();
}
else {
if ((now()-funkyStateStartTime)>funkyStateTimeLimit) {
System.sleep(SLEEP_MODE_DEEP, 10);
}
}
else {
funkyState = false;
}
Do I need also need to add at the top SYSTEM_THREAD(ENABLED);