File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,8 +20,12 @@ void halt() {
2020static char command[160 ];
2121
2222// For power saving
23+ constexpr unsigned long ACTIVE_TIME_SEC_INUSE = 2 * 60 ; // 2 minutes
24+ constexpr unsigned long ACTIVE_TIME_SEC_IDLE = 5 ; // 5 seconds
25+ constexpr unsigned long IDLE_PERIOD_SEC = 30 * 60 ; // 30 minutes
26+
2327unsigned 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 = ACTIVE_TIME_SEC_INUSE ; // next sleep in seconds
2529
2630void 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
134+ if (the_mesh.getNodePrefs ()->powersaving_enabled &&
131135 the_mesh.millisHasNowPassed (lastActive + nextSleepinSecs * 1000 )) { // To 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 (IDLE_PERIOD_SEC ); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
134138 lastActive = millis ();
135- nextSleepinSecs = 5 ; // Default: To work for 5s and sleep again
139+ nextSleepinSecs = ACTIVE_TIME_SEC_IDLE ; // Default: To work for 5s and sleep again
136140 } else {
137- nextSleepinSecs += 5 ; // When there is pending work, to work another 5s
141+ nextSleepinSecs += ACTIVE_TIME_SEC_IDLE ; // When there is pending work, to work another 5s
138142 }
139143 }
140144}
You can’t perform that action at this time.
0 commit comments