I have what I think is a stable system now thanks to help from @rickkas7. Over the past two weeks I’ve had two Electrons constantly connecting, checking for firmware updates, and sleeping for 10 minutes (same test as before), with some more calls to Particle.process()
added. Across 4000 connection attempts, there were only 170 times when the Electron disconnected before getting the firmware update queued event (4.2% failure rate), and these seemed like isolated incidents, not multi-hour outages like before.
Some things that @rickkas7 pointed out that aren’t documented:
You need to call Particle.process()
after Particle.disconnect()
for the cloud to detect the Electron has disconnected. Otherwise, if you connect back up within some nearby timeframe - probably the keepalive timeout of 23 minutes - the cloud thinks it’s the same session and doesn’t go through sending events like it would with a new session. I added this code after Particle.disconnect()
:
// wait for disconnect to complete
while(!Particle.disconnected()) {
Serial.println("...");
for(i=0; i<100; i++) {
Particle.process();
delay(10);
}
}
BTW, Particle.disconnected()
is a real function and seems to work though it’s not documented.
The Particle.process()
documentation doesn’t cover all the cases where you need to call Particle.process()
, so I just added in very frequent calls to Particle.process()
starting from Cellular.connect()
and ending with Particle.disconnected()
returning true.
I noticed another improvement with the firmware in this test: I was getting occasional duplicate webhook events from a single publish, and these went away after calling Particle.process()
more often throughout my code.
Hope this helps anyone else using SYSTEM_MODE_MANUAL
and trying to optimize battery life by using deep sleep as much as possible.