I cannot get my Electron to sleep in SINGLE_THREADED_BLOCK() {}
. I imagine it has something to do with some calls not making it to the other parts of the RTOS when in single threaded mode.
It seems like in order to avoid communication with the Particle cloud when waking in this loop, I am going to have to disconnect from the Particle cloud before going to sleep. New code looks like:
// System.sleep(SLEEP_MODE_DEEP, seconds, SLEEP_NETWORK_STANDBY);
// 46 = LOW_BAT_UC = INT pin on bq24195
sleepTimer = Time.now();
uint32_t timeToSleep = seconds;
if(Particle.connected()) {
Particle.disconnect();
waitFor(Particle.disconnected, 60000);
}
do {
System.sleep(46, FALLING, SLEEP_NETWORK_STANDBY, timeToSleep);
if(!pmic.isPowerGood()) { break; }
timeToSleep = seconds - (Time.now() - sleepTimer);
if(timeToSleep > seconds || timeToSleep <= 0) { break; }
} while(Time.now() - sleepTimer < seconds);
System.reset();
This seems to fix my issue, but comes with two new questions:
- I’m using the undocumented function
Particle.disconnected
. This is a little worrying, but it seems to work. - What penalty do I incur by issuing a Particle.disconnect() when later reconnecting after waking up? It seems, per the logs below, the device is restoring its status without going through the full 5k handshake. Is that correct?
0000014083 [comm.protocol.handshake] INFO: Establish secure connection
0000014113 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=0
0000014115 [comm.dtls] INFO: out_ctr 0,1,0,0,0,0,0,135, next_coap_id=73
0000014115 [comm.dtls] INFO: app state crc: 96efa765, expected: e17ef99
0000014117 [comm.dtls] INFO: restored session from persisted session data. next_msg_id=115
0000014117 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 2