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:
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. Cellular.off() 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 Cellular.off while Cellular.connecting() is true? Or is Cellular.disconnect() needed for this?
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
cellular_on(NULL);
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 Cellular.off() because it doesn’t do exactly the same things as Cellular.off() 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.
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 Cellular.off() without it having any consequences?