fix: skip NTP sync and mDNS in deep sleep wake path to reduce battery drain
The syncNTP() call blocks up to 5 seconds waiting for NTP response on every deep sleep wake cycle (every 10 minutes). Combined with mDNS startup, this added significant active WiFi time per cycle. Fix: Add 'minimal' flag to WiFiManager::begin()/startStation(). In the deep sleep wake path, skip NTP sync and mDNS entirely. The system clock is already seeded from the hardware RTC at boot, which is accurate enough for 30-day date window calculations. Normal interactive boot still does full NTP sync + mDNS as before. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -429,8 +429,8 @@ void timerWakeCycle() {
|
||||
|
||||
Settings s = settingsManager.get();
|
||||
|
||||
// Connect WiFi (blocking)
|
||||
wifiManager.begin(settingsManager);
|
||||
// Connect WiFi (minimal — skip NTP/mDNS to save battery)
|
||||
wifiManager.begin(settingsManager, true);
|
||||
if (!wifiManager.isConnected()) {
|
||||
Serial.println("[timer_wake] WiFi failed — going back to sleep");
|
||||
powerManager.enterDeepSleep(s.interval_min);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <sys/time.h>
|
||||
#include "config.h"
|
||||
|
||||
void WiFiManager::begin(SettingsManager& settings) {
|
||||
void WiFiManager::begin(SettingsManager& settings, bool minimal) {
|
||||
_settings = &settings;
|
||||
|
||||
if (!_settings->isProvisioned()) {
|
||||
@@ -15,7 +15,7 @@ void WiFiManager::begin(SettingsManager& settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
startStation();
|
||||
startStation(minimal);
|
||||
}
|
||||
|
||||
bool WiFiManager::isConnected() {
|
||||
@@ -47,18 +47,26 @@ void WiFiManager::startAP() {
|
||||
WiFi.softAPIP().toString().c_str());
|
||||
}
|
||||
|
||||
void WiFiManager::startStation() {
|
||||
void WiFiManager::startStation(bool minimal) {
|
||||
Settings s = _settings->get();
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
_apMode = false;
|
||||
|
||||
Serial.printf("[wifi] Connecting to: %s\n", s.wifi_ssid.c_str());
|
||||
Serial.printf("[wifi] Connecting to: %s%s\n", s.wifi_ssid.c_str(),
|
||||
minimal ? " (minimal)" : "");
|
||||
|
||||
for (_retryCount = 0; _retryCount < WIFI_MAX_RETRIES; _retryCount++) {
|
||||
if (attemptConnection(s.wifi_ssid, s.wifi_pass)) {
|
||||
Serial.printf("[wifi] Connected! IP: %s, RSSI: %d\n",
|
||||
WiFi.localIP().toString().c_str(), WiFi.RSSI());
|
||||
|
||||
if (minimal) {
|
||||
// Deep sleep wake path: skip NTP/mDNS to minimize active time.
|
||||
// System clock was already seeded from hardware RTC at boot.
|
||||
return;
|
||||
}
|
||||
|
||||
WiFi.setSleep(WIFI_PS_MIN_MODEM);
|
||||
syncNTP();
|
||||
setupMDNS("papercolor");
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
class WiFiManager {
|
||||
public:
|
||||
void begin(SettingsManager& settings);
|
||||
void begin(SettingsManager& settings, bool minimal = false);
|
||||
bool isConnected();
|
||||
bool isAPMode();
|
||||
String getIP();
|
||||
int getRSSI();
|
||||
void startAP();
|
||||
void startStation();
|
||||
void startStation(bool minimal = false);
|
||||
void setupMDNS(const char* hostname);
|
||||
void syncNTP();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user