Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/simple_room_server/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,11 @@ void MyMesh::loop() {
uptime_millis += now - last_millis;
last_millis = now;
}

// To check if there is pending work
bool MyMesh::hasPendingWork() const {
#if defined(WITH_BRIDGE)
if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep
#endif
return _mgr->getOutboundTotal() > 0;
}
3 changes: 3 additions & 0 deletions examples/simple_room_server/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
void clearStats() override;
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
void loop();

// To check if there is pending work
bool hasPendingWork() const;
};
15 changes: 14 additions & 1 deletion examples/simple_room_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ void halt() {

static char command[MAX_POST_TEXT_LEN+1];

// For power saving
unsigned long POWERSAVING_FIRSTSLEEP_SECS = 120; // The first sleep (if enabled) from boot

void setup() {
Serial.begin(115200);
delay(1000);
Expand Down Expand Up @@ -113,4 +116,14 @@ void loop() {
ui_task.loop();
#endif
rtc_clock.tick();
}

if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) {
#if defined(NRF52_PLATFORM)
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
#else
if (the_mesh.millisHasNowPassed(POWERSAVING_FIRSTSLEEP_SECS * 1000)) { // To check if it is time to sleep
board.sleep(30); // Sleep. Wake up after a while or when receiving a LoRa packet
}
#endif
}
}