Browse Source

Merge pull request #2286 from IoTThinks/MCdev-PowerSaving-for-nrf52-companion-202604

Added Power Saving for NRF52 companions to have extra 30% battery life
pull/2510/merge
ripplebiz 6 days ago
committed by GitHub
parent
commit
54c111609a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      examples/companion_radio/MyMesh.cpp
  2. 3
      examples/companion_radio/MyMesh.h
  3. 14
      examples/companion_radio/main.cpp

5
examples/companion_radio/MyMesh.cpp

@ -2222,3 +2222,8 @@ bool MyMesh::advert() {
return false;
}
}
// To check if there is pending work
bool MyMesh::hasPendingWork() const {
return _mgr->getOutboundTotal() > 0;
}

3
examples/companion_radio/MyMesh.h

@ -177,6 +177,9 @@ public:
}
#endif
// To check if there is pending work
bool hasPendingWork() const;
private:
void writeOKFrame();
void writeErrFrame(uint8_t err_code);

14
examples/companion_radio/main.cpp

@ -250,13 +250,19 @@ void loop() {
#endif
rtc_clock.tick();
if (!the_mesh.hasPendingWork()) {
#if defined(NRF52_PLATFORM)
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
#endif
}
#if defined(ESP32) && defined(WIFI_SSID)
// Safely attempt to reconnect every 10 seconds if flagged
if (wifi_needs_reconnect && (millis() - last_wifi_reconnect_attempt > 10000)) {
WIFI_DEBUG_PRINTLN("Attempting manual WiFi reconnect...");
WiFi.disconnect();
WiFi.reconnect();
last_wifi_reconnect_attempt = millis();
WIFI_DEBUG_PRINTLN("Attempting manual WiFi reconnect...");
WiFi.disconnect();
WiFi.reconnect();
last_wifi_reconnect_attempt = millis();
}
#endif
}

Loading…
Cancel
Save