My application is that I need to publish a temperature once every 5 minutes. Simply using delay(300000) works fine with the cell modem on all the time, but of course that drains my batteries.
Is there any known good sample code that utilizes the System.sleep() function and/or Manual system mode to turn the cell radio on and off so as to preserve batttery life?
The documentation is simply terrible and just doesn’t give good, practical examples of using many of the functions. I’ve tried setting to manual mode, putting Cellular.off() in the setup routine, then using millis() for elapsed time, and after 5 minutes use this basic paradigm: Cellular.on() > if(Cellular.ready()) > Particle.connect() > if(Particle.connected()) > Particle.publish(). I’ve tried various permutations and combinations, and adding delays throughout to give reasonable amounts of time to wait for things to connect. Someone mentioned to check RSSI instead of Cellular.ready() as I guess there’s a bug where ready() returns true sometimes before there’s a solid cell connection.
Anyway, this is maddening. I would have thought turning the radio/internet on and off every 5 minutes wouldn’t be a big deal, but I just can’t find any solid examples or straightforward explanations on how to properly use these APIs. Someone elsewhere suggested System.sleep() which supposedly turns the radio off and on automatically, but that only seems to work halfway because it never seems to connect to the cloud after wakeup.