mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-03 02:36:11 +00:00
Let ESP32-based repeaters to sleep immediately receiving and process a LoRa packet
This commit is contained in:
@@ -20,8 +20,7 @@ void halt() {
|
|||||||
static char command[160];
|
static char command[160];
|
||||||
|
|
||||||
// For power saving
|
// For power saving
|
||||||
unsigned long lastActive = 0; // mark last active time
|
unsigned long POWERSAVING_FIRSTSLEEP_SECS = 120; // The first sleep (if enabled) from boot
|
||||||
unsigned long nextSleepinSecs = 120; // next sleep in seconds. The first sleep (if enabled) is after 2 minutes from boot
|
|
||||||
|
|
||||||
#if defined(PIN_USER_BTN) && defined(_SEEED_SENSECAP_SOLAR_H_)
|
#if defined(PIN_USER_BTN) && defined(_SEEED_SENSECAP_SOLAR_H_)
|
||||||
static unsigned long userBtnDownAt = 0;
|
static unsigned long userBtnDownAt = 0;
|
||||||
@@ -40,9 +39,6 @@ void setup() {
|
|||||||
delay(5000);
|
delay(5000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For power saving
|
|
||||||
lastActive = millis(); // mark last active time since boot
|
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
if (display.begin()) {
|
if (display.begin()) {
|
||||||
display.startFrame();
|
display.startFrame();
|
||||||
@@ -157,16 +153,12 @@ void loop() {
|
|||||||
rtc_clock.tick();
|
rtc_clock.tick();
|
||||||
|
|
||||||
if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) {
|
if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) {
|
||||||
#if defined(NRF52_PLATFORM)
|
#if defined(NRF52_PLATFORM)
|
||||||
board.sleep(1800); // nrf ignores seconds param, sleeps whenever possible
|
board.sleep(1800); // nrf ignores seconds param, sleeps whenever possible
|
||||||
#else
|
#else
|
||||||
if (the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // To check if it is time to sleep
|
if (the_mesh.millisHasNowPassed(POWERSAVING_FIRSTSLEEP_SECS * 1000)) { // To check if it is time to sleep
|
||||||
board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
board.sleep(1800); // Sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
||||||
lastActive = millis();
|
|
||||||
nextSleepinSecs = 5; // Default: To work for 5s and sleep again
|
|
||||||
} else {
|
|
||||||
nextSleepinSecs += 5; // When there is pending work, to work another 5s
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user