Correctly turning off the Cellular?

If you are OK with this 1-shot approach (wake up, try to connect, go to sleep, repeat), this works great for me. It’s Manual mode, un-related code removed. Give it a spin.

#include <Particle.h>
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
int sleepTime = 4 * 3600       ;    // (# HOURS * 3600 seconds) 14,400 = 4 hours, 28800 = 8 hr, 21600 = 6hr ,
int connectionFail = 5 * 60000 ;    // (# of Minutes * 60,000 ms) Electron will Give-Up after this amount of time.

void setup()  {
}

void loop()   {
  // Wakes up Here

  Cellular.on();
  for (uint32_t ms = millis(); millis() - ms < 1000; Particle.process());
  
  Particle.connect();
  for (uint32_t ms = millis(); millis() - ms < 10000; Particle.process());

  if (waitFor(Particle.connected, connectionFail)) {  // Limit the Connection attempt      
      // do your sensor reading stuff here
      Particle.process();
      
      // Perform the Publish here, use NO_ACK flag or you may want to wait longer afterwards
        for (uint32_t ms = millis(); millis() - ms < 5000; Particle.process());
    }
 
  
  // Either the Cloud Connection was successful, or it wasn't.  It's time to go to sleep either way. 
  
  Particle.disconnect();
  for (uint32_t ms = millis(); millis() - ms < 1000; Particle.process());

  Cellular.off();
  for (uint32_t ms = millis(); millis() - ms < 1000; Particle.process());
  
  System.sleep(SLEEP_MODE_DEEP, sleepTime);  // Go to Sleep

} // End LOOP

1 Like