Skip to content

Commit 26c09c4

Browse files
committed
Used setting constants for Power Saving
1 parent 3e79842 commit 26c09c4

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

examples/simple_repeater/main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ void halt() {
2020
static char command[160];
2121

2222
// For power saving
23+
const uint32_t POWERSAVING_FIRSTSLEEP_SINCEBOOT_SECS = 120; // PowerSaving will be active some time after boot
24+
const uint32_t POWERSAVING_MAXSLEEP_PERIOD_SECS = 1800; // Wakeup periodically to do scheduled jobs
25+
const uint32_t POWERSAVING_WAKEUP_PERIOD_SECS = 5; // Awake period after wakeup
26+
2327
unsigned long lastActive = 0; // mark last active time
24-
unsigned long nextSleepinSecs = 120; // next sleep in seconds. The first sleep (if enabled) is after 2 minutes from boot
28+
unsigned long nextSleepinSecs = POWERSAVING_FIRSTSLEEP_SINCEBOOT_SECS; // next sleep in seconds. The first sleep (if enabled) is after some time since boot
2529

2630
void setup() {
2731
Serial.begin(115200);
@@ -127,14 +131,14 @@ void loop() {
127131
#endif
128132
rtc_clock.tick();
129133

130-
if (the_mesh.getNodePrefs()->powersaving_enabled && // To check if power saving is enabled
131-
the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // To check if it is time to sleep
134+
if (the_mesh.getNodePrefs()->powersaving_enabled && // Check if power saving is enabled
135+
the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // Check if it is time to sleep
132136
if (!the_mesh.hasPendingWork()) { // No pending work. Safe to sleep
133-
board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
137+
board.sleep(POWERSAVING_MAXSLEEP_PERIOD_SECS); // Sleep. Wake up periodically or when receiving a LoRa packet
134138
lastActive = millis();
135-
nextSleepinSecs = 5; // Default: To work for 5s and sleep again
139+
nextSleepinSecs = POWERSAVING_WAKEUP_PERIOD_SECS; // Default: Work for 1 wakeup period and sleep again
136140
} else {
137-
nextSleepinSecs += 5; // When there is pending work, to work another 5s
141+
nextSleepinSecs += POWERSAVING_WAKEUP_PERIOD_SECS; // When there is pending work, work another wakeup period
138142
}
139143
}
140144
}

0 commit comments

Comments
 (0)