Network.isoff() with Cellular modem

Using Network.isOff() to check if the cellular modem is turned off, does not seem to work here. Am I using it correctly?

Function Sleep2_state always takes 60 seconds matching the timeout set. Power consumption show the modem is in fact off [while sleeping].

...
void SLEEPstate() { // Go to sleep, 0. Disconnect Particle Cloud
    if (mainState != lastState) {
        stateTime = millis();     
        if (firmwareUpdateBegin) {mainState = SWUPDT; return;} 
        Particle.disconnect(CloudDisconnectOptions().graceful(true).timeout(5000));
        lastState = mainState;
    }
    
    if (Particle.disconnected() || ((millis() - stateTime) >= 5000)) mainState = SLEEP1;
}

void SLEEP1state() { // Go to sleep, 1. Disconnect network
    if (mainState != lastState) {
        stateTime = millis();     
        Network.disconnect();
        lastState = mainState;
    }
    if (!Network.ready() || ((millis() - stateTime) >= 5000))     mainState = SLEEP2;    
}

void SLEEP2state() { // Go to sleep, 2. Turn network off (cellular or wifi), then sleep.
    if (mainState != lastState) {
        stateTime = millis();     
        Network.off();
        lastState = mainState;
    }
    if (Network.isOff() || ((millis() - stateTime) >= 60000)){
        devLog("ZZZzzz");
        SystemSleepConfiguration config;
        config.mode(SystemSleepMode::ULTRA_LOW_POWER)
            .duration(14min);
        System.sleep(config);
        // Sleeping then continue from here
        mainState = CONNCT;
    }
}
...

OS 4.0.2 and modem is B523

@thrmttnw ,

I use a very heavy handed Cellular command:

  // Then we need to disconnect from Cellular and power down the cellular modem
  startTime = Time.now();
  Cellular.disconnect();                                               // Disconnect from the cellular network
  Cellular.off();                                                      // Turn off the cellular modem
  waitFor(Cellular.isOff, 30000);                                      // As per TAN004: https://support.particle.io/hc/en-us/articles/1260802113569-TAN004-Power-off-Recommendations-for-SARA-R410M-Equipped-Devices
  Particle.process();
  if (Cellular.isOn()) {                                               // At this point, if cellular is not off, we have a problem
    Log.info("Failed to turn off the Cellular modem");
    return(false);                                                     // Let the calling function know that we were not able to turn off the cellular modem
  }
  else {
    Log.info("Turned off the cellular modem in %i seconds", (int)(Time.now() - startTime));
    return true;
  }

Hope this helps,

Chip

1 Like

Thank you @chipmc, doing it your way also works well in the original code example when using Cellular.disconnect() with !Cellular.ready() and also Cellular.off() with Cellular.isOff().

Turns out Network.off() and Network.isOff() is just not working here. Curiously neither did Cellular.off() after Network.disconnect() that itself worked well.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.