I have a Boron which I’d like to keep asleep to save power and only wake when it receives an event on a subscribed topic over cellular, then show information on an e-ink display. This will be a solar + battery setup.
From the docs, I saw that using SystemSleepMode::STOP in the following manner will keep the device connected to cellular during sleep, and also wake on received events:
sleepConfig
.mode(SystemSleepMode::STOP)
.network(NETWORK_INTERFACE_CELLULAR)
.duration(1min);
What I’m curious about is the best-practice way to have the device stay asleep, wake on a received event and process it, then sleep automatically. I can’t seem to find much about exactly how Particle OS handles received events during this kind of sleep mode, and would like to learn more. Does it wait until the subscription handler returns before running loop and sleeping again?
Below is what I have so far, which seems to work (the LED indicates it’s receiving data from the Cloud) but it’s a bit hard to tell because the serial connection is lost when it sleeps:
SYSTEM_MODE(AUTOMATIC);
SystemSleepConfiguration sleepConfig;
void setup()
{
Particle.subscribe("siri_wait_times", handleWaitTimeSubscription);
waitUntil(Cellular.ready);
waitUntil(Particle.connected);
sleepConfig
.mode(SystemSleepMode::STOP)
.network(NETWORK_INTERFACE_CELLULAR)
.duration(1min);
}
void loop()
{
// sleep immediately
System.sleep(sleepConfig);
}
Thanks in advance.