Still having no end of sleep issues with electron, despite being on 0.7.0 i still have many many occurrences of SLEEP_MODE_DEEP and SLEEP_MODE_SOFTPOWEROFF not shutting the modem down properly, making devices unusable for long life battery operations, due to inconsistent sleep current.
So when cellular_off fails, what is left to do?
Can I manually turn the module off using PWR_UC pin?
Before I call the SLEEP commands, I call this function to ensure I am disconnected and the cellular modem is off. Perhaps you could give this a try:
bool disconnectFromParticle()
{
Particle.disconnect(); // Disconnect from Particle in prep for sleep
waitFor(notConnected,10000);
Cellular.disconnect(); // Disconnect from the cellular network
delay(3000);
Cellular.off(); // Turn off the cellular modem
return true;
}
Also, I would not use celluar_off(). It does not do the same thing that Cellular.off() does, and I found that it can leave the modem in a bad state. I’ve found Cellular.off() (possibly with a 2000 ms delay before sleep) to be the most reliable way of having the modem shut down all the time.
And I don’t step down, disconnecting each layer. I go directly from Particle.connected() to Cellular.off(). I’ve found that to work the best for me, but your mileage may vary.
@rickkas7 Thanks, The reason for using cellular_off was that I thought it was blocking, whereas Cellular.off was not? and I'm running SYSTEM THREAD enabled.
Oh and by bad state, do you mean anything like this?
Occasionally the modem turns off goes into a limbo state with complete system pulling 40ma with slow pulsing green led and code lockup. I have to rely on external watchdog timer to reset it, at which point it enters proper sleep.
Yes, that would be the bad state. And yes, cellular_off is blocking, which is handy for SYSTEM_THREAD(ENABLED) but the bad state problem makes it not worth it.
I use cellular_on(NULL) as that works great, but still use Cellular.off().
I had the delay with 0.6.x but I’m not sure it’s necessary anymore. I haven’t done enough tests with 0.7.0 to be absolutely sure it’s not necessary, but I don’t think it is. But 2 seconds at 40 mA isn’t a lot of power either, so I haven’t removed it.
Pulling PWR_UC low might work, but I’m worried it will go into the state it’s in during cold boot with cellular off (1 mA) instead of SLEEP_MODE_DEEP state (130 uA). I haven’t actually tested it, though, so maybe it’s fine.
Ok thanks again, all I want is a bullet proof way of going into 130ua sleep, 4 months of trying and still not there! I have around 200 prototype devices out in the wild and the number of them not going into sleep properly is killing my product.
So, sorry to go over one more time, but… aside from the possible PWR_UC option, do you think this in your experience is the most robust method to go into 130ua deep sleep. …?
//Do whatever, connect to gsm, send sms, cloud connection etc.
cellular_result_t result = -1;
result = cellular_on(NULL);
if (result) {
if (serialdebug) Serial.println("ERROR: Failure powering on the modem!");
} else {
if (serialdebug) Serial.println("Modem ON!");
}
Cellular.off();
delay(2000);
System.sleep(SLEEP_MODE_SOFTPOWEROFF,1440);
Yes, I believe that will go into 130 uA sleep always.
Though the jury is still out on whether the delay(2000) is necessary with 0.7.0 or later, it certainly doesn’t hurt anything (except for a little battery life).
Also, you only need to turn on and off the modem on cold boot. I use a retained variable to know that I’ve already powered on and off the modem and don’t go through that again if I already know the modem is off. It’s 0 on cold boot, and I put a magic value in it after waking up the modem.
Is that video just after you run the cellular.off() code?
I remember seeing this also for like 30 seconds or so after calling cellular.off() before the modem actually turned OFF and the 130uA sleep current kicked in.