Check whether Cellular is on/off

I was wondering if there is an efficient way to check if the cellular modem on the U260 Electron is turned on/off. I am switching it on/off regularly, and as I want a low-power device I don’t want to delay code any longer than I need to. Below is my code:

    if (!initialized) {
         initialized = true;
    if (millis() - stateTime >= 90000) {;
         System.sleep(SLEEP_MODE_DEEP, 5);

ideally I’d remove the 8 and 5-second delay and run my code (or enter deep sleep) as soon as the modem has been switched. in this case would ONLY be called if the device is unable to connect either to the network, or the Particle cloud.

Also - I couldn’t find a whole lot of info about this - is it okay to call while Cellular.connecting() is true? Or is Cellular.disconnect() needed for this?

Let me ping someone that might be able to help, @rickkas7 or @ParticleD are you able to assist?

There is no way to find the cellular on/off state. Though the system never spontaneously changes it, so you can keep your own variable to know if it’s set or not.

You can use


instead of Cellular.on(). The one with the underscore is blocking, so you don’t need to delay afterwards.

There is a cellular_off(), however I don’t recommend using that in place of because it doesn’t do exactly the same things as and I’ve managed to get the modem into a bad state using it.

Also, if you don’t connect to the cloud on every wake, you don’t need to turn the cellular modem on and off when you’ve previously turned off the cellular modem and gone into deep sleep. You really only need to turn the modem on then off on cold boot.


Thanks. I will use cellular_on(NULL) then to shave off some time for my sensor :slight_smile:

This part of the code is only run when I do need to connect to the Cloud - like you said, I don’t enable/disable it if it doesn’t need to connect.

Also, if Cellular.connecting() is true (i.e. it’s blinking green), but I want to abort it is it necessary to call Particle.disconnect() first? Or can I go straight to without it having any consequences?

I just go for I found it to work more reliably than trying to bring down each layer one at a time.