Skip to content

Commit

Permalink
Update to new sleep calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rickkas7 committed Jan 6, 2022
1 parent d4fc727 commit c7ae108
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ void loop() {
lastDiagnosticsPublish = Time.now();
}
}

System.sleep(WKP, RISING, sleepTime, SLEEP_NETWORK_STANDBY);
{
SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
.duration(sleepTime)
.network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
SystemSleepResult result = System.sleep(config);
}

Log.info("woke from sleep");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const std::chrono::milliseconds connectMaxTime = 6min;
const std::chrono::milliseconds cloudMinTime = 10s;

// How long to sleep
const std::chrono::seconds sleepTime = 1min;
const std::chrono::milliseconds sleepTime = 15min;

// Maximum time to wait for publish to complete. It normally takes 20 seconds for Particle.publish
// to succeed or time out, but if cellular needs to reconnect, it could take longer, typically
Expand Down Expand Up @@ -108,7 +108,7 @@ void loop() {
readSensorAndPublish();

if (millis() - stateTime < cloudMinTime.count()) {
Log.info("waiting %lu ms before sleeping", cloudMinTime.count() - (millis() - stateTime));
Log.info("waiting %lu ms before sleeping", (unsigned long)(cloudMinTime.count() - (millis() - stateTime)));
state = STATE_PRE_SLEEP;
}
else {
Expand All @@ -135,16 +135,26 @@ void loop() {

Log.info("going to sleep for %ld seconds", (long) sleepTime.count());

{
SystemSleepConfiguration config;
#if HAL_PLATFORM_NRF52840
// Gen 3 (nRF52840) does not suppport SLEEP_MODE_DEEP with a time in seconds
// to wake up. This code uses stop mode sleep instead.
System.sleep(WKP, RISING, sleepTime);
System.reset();
// Gen 3 (nRF52840) does not suppport HIBERNATE with a time duration
// to wake up. This code uses ULP sleep instead.
config.mode(SystemSleepMode::ULTRA_LOW_POWER)
.duration(sleepTime);
System.sleep(config);

// One difference is that ULP continues execution. For simplicity,
// we just match the HIBERNATE behavior by resetting here.
System.reset();
#else
System.sleep(SLEEP_MODE_DEEP, sleepTime);
// This is never reached; when the device wakes from sleep it will start over
// with setup()
config.mode(SystemSleepMode::HIBERNATE)
.duration(sleepTime);
System.sleep(config);
// This is never reached; when the device wakes from sleep it will start over
// with setup()
#endif
}
break;

case STATE_FIRMWARE_UPDATE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,11 @@ The `diagnosticPublishTime` specifies how often to send device diagnostics. Beca
This code does the sleep, which will block until wake-up occurs.

```
System.sleep(WKP, RISING, sleepTime, SLEEP_NETWORK_STANDBY);
SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
.duration(sleepTime)
.network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
SystemSleepResult result = System.sleep(config);
```

Since this uses stop mode sleep, upon wake execution continues with the next line of code with local and global variables still set, and the cloud still connected (since network standby mode is used). In this mode the device goes immediately into breathing cyan mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const std::chrono::milliseconds connectMaxTime = 6min;
const std::chrono::milliseconds cloudMinTime = 10s;
// How long to sleep.
const std::chrono::seconds sleepTime = 1min;
const std::chrono::seconds sleepTime = 15min;
// Maximum time to wait for publish to complete. It normally takes 20 seconds for Particle.publish
// to succeed or time out, but if cellular needs to reconnect, it could take longer, typically
Expand Down Expand Up @@ -264,16 +264,27 @@ If not, then it goes into sleep. This state is never exited; upon wake, the devi
Log.info("going to sleep for %ld seconds", (long) sleepTime.count());
{
SystemSleepConfiguration config;
#if HAL_PLATFORM_NRF52840
// Gen 3 (nRF52840) does not suppport SLEEP_MODE_DEEP with a time in seconds
// to wake up. This code uses stop mode sleep instead.
System.sleep(WKP, RISING, sleepTime);
System.reset();
// Gen 3 (nRF52840) does not suppport HIBERNATE with a time duration
// to wake up. This code uses ULP sleep instead.
config.mode(SystemSleepMode::ULTRA_LOW_POWER)
.duration(sleepTime);
System.sleep(config);
// One difference is that ULP continues execution. For simplicity,
// we just match the HIBERNATE behavior by resetting here.
System.reset();
#else
System.sleep(SLEEP_MODE_DEEP, sleepTime);
// This is never reached; when the device wakes from sleep it will start over
// with setup()
config.mode(SystemSleepMode::HIBERNATE)
.duration(sleepTime);
System.sleep(config);
// This is never reached; when the device wakes from sleep it will start over
// with setup()
#endif
}
break;
```

Expand Down

0 comments on commit c7ae108

Please sign in to comment.