Can you keep the cellular module turned off after reset?

As the title says. I want to keep the cellular module turned off after my electron wakes up from deep sleep.
I want to do this to keep the power consumption as low as possible. Ideally the electron should be in deep sleep for the most time, in between the micro-controller should wake up to check if it has to send data to the cloud and only if that is the case the cellular module should ever get turned on. Is there any way to do this? Thanks in advance! :slight_smile:

@FlorianRebernig,

Yes, in fact that is how I manage mine. Here are the steps:

  1. You need to change to semi-automatic mode. That will let you control the connection. I put these two lines up front in my sketches:
SYSTEM_MODE(SEMI_AUTOMATIC);          // This will enable user code to start executing automatically.
SYSTEM_THREAD(ENABLED);               // Means my code will not be held up by Particle processes.

  1. In startup, you need to use a conditional statement to decide if you want to connect or not. Mine looks like this:
if (!lowPowerMode && (stateOfCharge >= lowBattLimit) && !(Time.hour() >= closeTime || Time.hour() < openTime)) connectToParticle();  // If not lowpower or sleeping, we can connect

The logic of your statement will vary.

  1. Then you need to create functions to control the connection. Here are what mine look like:
bool connectToParticle()
{
  if (!Cellular.ready())
  {
    Cellular.on();                                           // turn on the Modem
    Cellular.connect();                                      // Connect to the cellular network
    if(!waitFor(Cellular.ready,90000)) return false;         // Connect to cellular - give it 90 seconds
  }
  Particle.process();
  Particle.connect();                                      // Connect to Particle
  if(!waitFor(Particle.connected,30000)) return false;     // Connect to Particle - give it 30 seconds
  Particle.process();
  return true;
}

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;
}

bool notConnected() {
  return !Particle.connected();                             // This is a requirement to use waitFor
}

  1. Then, in your sketch, you can manage connections to ensure you are only connecting when you want to. I use statements like this:

When I might be connected but want to disconnect:

      if (Particle.connected())
      {
        Particle.publish("State","Disconnecting from Particle");
        disconnectFromParticle();                                       // If connected, we need to disconned and power down the modem
      }

Or, when I might not be connected but want to be:

      if (!Particle.connected()) {
        if (!connectToParticle()) {
          resetTimeStamp = millis();
          state = ERROR_STATE;
          break;
        }
      }

I hope this helps and - for all you out there watching - suggestions as to how to do this better are welcome.

One last thing, I think you want to be on 0.7.0 or better firmware for all this to work as advertised.

Thanks,

Chip