feat(power): automatic WiFi disable when running on battery#9428
feat(power): automatic WiFi disable when running on battery#9428lexfrei wants to merge 8 commits intomeshtastic:developfrom
Conversation
Add wifi_on_external_power_only and wifi_power_loss_timeout_secs fields to NetworkConfig structure. Updated init macros, field tags, and size. Note: Full regeneration with nanopb required before merge. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
Add deinitWebServer() to properly stop and clean up web servers (HTTPS and HTTP) when WiFi is disabled at runtime. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
Add stop() method to properly close UDP multicast listener when WiFi is disabled at runtime. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
Add deinitWifiServices() to properly stop all WiFi-dependent services before disabling WiFi: - Syslog client - API server - Web server - mDNS - NTP client Reset APStartupComplete flag to allow services to reinitialize on reconnect. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
Add handleWifiPowerManagement() to automatically manage WiFi based on external power state: - When external power is lost: start timer, disable WiFi after timeout - When external power is restored: cancel timer, re-enable WiFi - Timeout prevents accidental WiFi toggle on brief power interruptions Configuration: - wifi_on_external_power_only: enable feature (default: false) - wifi_power_loss_timeout_secs: delay before WiFi disable (default: 30s) Closes: meshtastic#9427 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
Points to feat/wifi-power-management branch with new NetworkConfig fields. Will be updated to upstream master after protobufs PR is merged. See: meshtastic/protobufs#851 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
@lexfrei, Welcome to Meshtastic!Thanks for opening your first pull request. We really appreciate it. We discuss work as a team in discord, please join us in the #firmware channel. Welcome to the team 😄 |
The close() method is only available in ESP32's AsyncUDP implementation. Other platforms (nrf52, portduino/native) don't have this method, causing build failures in native simulator tests. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
Portduino has HAS_WIFI=1 but excludes mesh/wifi/ from build, causing undefined reference errors for isWifiAvailable(), initWifi(), deinitWifi(). Added !defined(ARCH_PORTDUINO) guard to all WiFi power management code. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
| syslog.disable(); | ||
|
|
||
| // Stop API server | ||
| deInitApiServer(); |
There was a problem hiding this comment.
Hi,
Before stopping these services, should the code check if ethernet is currently enabled? Since initEthernet() also initializes several of these services, we might want to ensure they aren't killed if a valid ethernet connection is still active, even if WiFi is being deinitialized.
Should a check for config.network.eth_enabled be added here and also for timeClient.end();?
A separate pull request for "automatic disable ethernet when running on battery" can take care of stopping these services if both config.network.eth_enabled and config.network.wifi_on_external_power_only are set.
Summary
Implement automatic WiFi management based on power source. When enabled, WiFi is automatically disabled when running on battery and re-enabled when external power is connected.
wifi_on_external_power_onlyconfig option to enable featurewifi_power_loss_timeout_secsconfig option for delay before disabling WiFi (default: 30s)Use Case
Docked mode (at home, charging):
Portable mode (on the go):
Implementation
WiFi Service Cleanup (hot toggle support)
deinitWebServer()to stop HTTPS/HTTP serversstop()method toUdpMulticastHandlerdeinitWifiServices()to properly shutdown all WiFi-dependent services (mDNS, NTP, Syslog, WebServer, API Server)APStartupCompleteflag to allow service reinitialization on reconnectPower-Based WiFi Control
handleWifiPowerManagement()inPower.cppmonitors USB power stateDependencies
Test Plan
Platforms
Closes: #9427