Flush messages before going to sleep

I have a workaround for flushing messages before entering Deep Sleep that so far seems to be working. We need a way to call Spark_Sleep() to flush the messages. There’s no way (that I can find) to call the Spark_Sleep() function directly, but you can call it by entering STOP mode sleep with a pin wake. With a short value for seconds (1 second), this should have the effect of flushing the messages, stopping the CPU for a second, then we can enter Deep Sleep. One other thing to save time/battery: keep the network connected during the first sleep call with the SLEEP_NETWORK_STANDBY option, otherwise the sleep call seems to wait for the modem to connect again before returning.

This code should wait to flush the messages, then go to Deep Sleep (for 10 seconds):

System.sleep(D0,RISING,1,SLEEP_NETWORK_STANDBY);
System.sleep(SLEEP_MODE_DEEP, 10);

I’ll try to remember to post back after setting up a more thorough test and getting results.

We are currently working on flushing of messages for TCP communications before sleeping (would affect Core/Photon/P1). Target for release is 0.7.0-rc.1. :smile:

3 Likes