Skip to content

Commit c7ae108

Browse files
committed
Update to new sleep calls
1 parent d4fc727 commit c7ae108

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

src/assets/files/app-notes/AN028/firmware/src/Stop-Sleep-Cellular.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ void loop() {
190190
lastDiagnosticsPublish = Time.now();
191191
}
192192
}
193-
194-
System.sleep(WKP, RISING, sleepTime, SLEEP_NETWORK_STANDBY);
193+
{
194+
SystemSleepConfiguration config;
195+
config.mode(SystemSleepMode::STOP)
196+
.duration(sleepTime)
197+
.network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
198+
SystemSleepResult result = System.sleep(config);
199+
}
195200

196201
Log.info("woke from sleep");
197202

src/assets/files/app-notes/AN029/firmware/src/Wake-Publish-Sleep-Cellular.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const std::chrono::milliseconds connectMaxTime = 6min;
3838
const std::chrono::milliseconds cloudMinTime = 10s;
3939

4040
// How long to sleep
41-
const std::chrono::seconds sleepTime = 1min;
41+
const std::chrono::milliseconds sleepTime = 15min;
4242

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

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

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

138+
{
139+
SystemSleepConfiguration config;
138140
#if HAL_PLATFORM_NRF52840
139-
// Gen 3 (nRF52840) does not suppport SLEEP_MODE_DEEP with a time in seconds
140-
// to wake up. This code uses stop mode sleep instead.
141-
System.sleep(WKP, RISING, sleepTime);
142-
System.reset();
141+
// Gen 3 (nRF52840) does not suppport HIBERNATE with a time duration
142+
// to wake up. This code uses ULP sleep instead.
143+
config.mode(SystemSleepMode::ULTRA_LOW_POWER)
144+
.duration(sleepTime);
145+
System.sleep(config);
146+
147+
// One difference is that ULP continues execution. For simplicity,
148+
// we just match the HIBERNATE behavior by resetting here.
149+
System.reset();
143150
#else
144-
System.sleep(SLEEP_MODE_DEEP, sleepTime);
145-
// This is never reached; when the device wakes from sleep it will start over
146-
// with setup()
151+
config.mode(SystemSleepMode::HIBERNATE)
152+
.duration(sleepTime);
153+
System.sleep(config);
154+
// This is never reached; when the device wakes from sleep it will start over
155+
// with setup()
147156
#endif
157+
}
148158
break;
149159

150160
case STATE_FIRMWARE_UPDATE:

src/content/datasheets/app-notes/an028-stop-sleep-cellular.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ The `diagnosticPublishTime` specifies how often to send device diagnostics. Beca
361361
This code does the sleep, which will block until wake-up occurs.
362362

363363
```
364-
System.sleep(WKP, RISING, sleepTime, SLEEP_NETWORK_STANDBY);
364+
SystemSleepConfiguration config;
365+
config.mode(SystemSleepMode::STOP)
366+
.duration(sleepTime)
367+
.network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
368+
SystemSleepResult result = System.sleep(config);
365369
```
366370

367371
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.

src/content/datasheets/app-notes/an029-wake-publish-sleep-cellular.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const std::chrono::milliseconds connectMaxTime = 6min;
129129
const std::chrono::milliseconds cloudMinTime = 10s;
130130
131131
// How long to sleep.
132-
const std::chrono::seconds sleepTime = 1min;
132+
const std::chrono::seconds sleepTime = 15min;
133133
134134
// Maximum time to wait for publish to complete. It normally takes 20 seconds for Particle.publish
135135
// to succeed or time out, but if cellular needs to reconnect, it could take longer, typically
@@ -264,16 +264,27 @@ If not, then it goes into sleep. This state is never exited; upon wake, the devi
264264
265265
Log.info("going to sleep for %ld seconds", (long) sleepTime.count());
266266
267+
{
268+
SystemSleepConfiguration config;
267269
#if HAL_PLATFORM_NRF52840
268-
// Gen 3 (nRF52840) does not suppport SLEEP_MODE_DEEP with a time in seconds
269-
// to wake up. This code uses stop mode sleep instead.
270-
System.sleep(WKP, RISING, sleepTime);
271-
System.reset();
270+
// Gen 3 (nRF52840) does not suppport HIBERNATE with a time duration
271+
// to wake up. This code uses ULP sleep instead.
272+
config.mode(SystemSleepMode::ULTRA_LOW_POWER)
273+
.duration(sleepTime);
274+
System.sleep(config);
275+
276+
// One difference is that ULP continues execution. For simplicity,
277+
// we just match the HIBERNATE behavior by resetting here.
278+
System.reset();
272279
#else
273-
System.sleep(SLEEP_MODE_DEEP, sleepTime);
274-
// This is never reached; when the device wakes from sleep it will start over
275-
// with setup()
280+
config.mode(SystemSleepMode::HIBERNATE)
281+
.duration(sleepTime);
282+
System.sleep(config);
283+
// This is never reached; when the device wakes from sleep it will start over
284+
// with setup()
276285
#endif
286+
}
287+
277288
break;
278289
```
279290

0 commit comments

Comments
 (0)