[SOLVED] Deep Sleep Electron

Hey all,

This might be a repetitive query but I wasn’t able to find a satisfactory answer online, so here it is my question:

I understand that the keepalive signal from the Electron needs to be sent out every 23 minutes (while using the particle sim) and it is done so automatically in the AUTOMATIC mode and using Particle.process() in MANUAL/ SEMI-AUTO mode.

  1. In AUTOMATIC mode, if I put the Electron to SLEEP_MODE_DEEP for more than 12 hours at a time (just DEEP SLEEP, not SLEEP_NETWORK_STANDBY , not SLEEP_MODE_SOFTPOWEROFF), will it automatically send the periodic keepalive pings whilst sleeping?

                             **OR**
    
  2. Would I need to manually wake-up every 23 minutes, allow enough time for the Electron to get online and then go back to sleep???

  3. How would I achieve a deepsleep or minimum power consuming sleep mode for such long periods of time (12+hours) …?

Thanks for the help… :slight_smile:

When the device sleeps no “premature” wake nor a keep alive ping will happen.
You either need to wake every 23 min or just accept the extra data consumption incurred by the full handshake.

If power is your prime concern, the latter is probably the way to go. You can always prevent a cellular connect on wake if you won’t need it on every wake to further save power and data.

Okay. So no Keepalives are sent while a device is sleeping. That would mean I HAVE to wake up every 23 minutes.

If I used retained variable to calculate the time elapsed such as:

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
retained unsigned long time_before_sleeping = 0; //will retain the clock value just before the device goes to sleep

void setup(){

  unsigned long now = Time.now();
  if(abs(time_before_sleeping - now) < 1000 * 60 * 60 * 12){ //If device hasn't slept for at least 12 hours, go to sleep for 20 min
     time_before_sleeping = Time.now();
     System.sleep(SLEEP_MODE_DEEP, 60*20); //sleep for 20 minutes
   
  }
}
void loop(){

//do stuff

   time_before_sleeping = Time.now(); //record time just before sleeping
   System.sleep(SLEEP_MODE_DEEP, 60*20); //sleep for 20 minutes
   
   //upon wakeup, program restarted (software reset) - setup re-executed
}

Would this code work in forcing the device to sleep for at least 12 hours whilst periodically waking up every 20 minutes to send a keep alive ping to the cellular towers??

Thanks, again :slight_smile:

What do you mean by:

Does this mean that I can actually deep sleep for 12 hours but when I wake up I'd have to do the (6kB) handshake again ?

A keepalive ping every 20 minutes in a 12 hour period would cost me : 122 (bytes of keepalive ping) * 3 (pings/hour) * 12 (total hours) = 4.39kB/12 hours

                            **vs**

12 hours continuous deep sleep: 6kB/12 hours

Hmm.. Might resort to the later despite the excessive 2kB cost as it might turn out to be more Power Efficient!

Does that (my calculations and assumption on improved power efficiency) seem right?

Thank you

Probably even less than that. I have 50 Electrons wake up twice a day (and even send 128-bytes of data). Their daily consumption for this right now is 2.26kB. I’m not sure why this number doesn’t match up with your calculation though. I don’t think the handshake is really that big? 6kB seems like an excessive amount for that.

Also, theoretically even if you did save on a little bit of data, the trade-off of waking up your Electron that often and establishing a connection again, is probably not worth it if it’s supposed to be power-efficient.

1 Like

Perfect! Thank you :smiley:

I agree. I have Electrons that wake up every 8 hours and they don't use anywhere near the 6 kB per handshake. I believe the 6kB is considered a max, or "Up To".....

2 Likes

Yes, that is the max for a full/cold handshake.
To reduce data consuption Particle has put in some extra intelligence to tell whether a full/cold handshake is needed. If the cloud already knows everything about your cloud interface (variables, functions, subscriptions) and nothing has changed since, these infos won’t be needed to be refreshed and hence can be taken as they were.
Saving on data-cost.

2 Likes