Skip to content

feat: add Stop() to power down Wi-Fi driver - #63

Open
hnw wants to merge 1 commit into
tinygo-org:mainfrom
hnw:wifi-stop-powersave
Open

feat: add Stop() to power down Wi-Fi driver#63
hnw wants to merge 1 commit into
tinygo-org:mainfrom
hnw:wifi-stop-powersave

Conversation

@hnw

@hnw hnw commented Aug 17, 2026

Copy link
Copy Markdown

Summary

Adds espradio.Stop() to stop the Wi-Fi interface (calls esp_wifi_stop()).

  • Note: It does not undo Enable(). Init-time state (ISR registration, scheduler ticker, etc.) remains. The caller must re-establish association and DHCP after a subsequent Start().

Motivation

To save power for applications that only need the network occasionally.
On an M5Stack Fire (ESP32), adding Stop() between sync cycles dropped system current by ~50 mA (0.21 A -> 0.16 A).

Implementation details

  • No new C glue needed; esp_wifi_stop is already in the vendored headers.
  • Stop() blocks until the WIFI_EVENT_STA_STOP event is received (with a 15-second timeout), mirroring the synchronization pattern used in Connect().

Testing & Notes

  • Tested on: M5Stack Fire (ESP32). Passed 14 consecutive cycles of Connect -> DHCP -> DNS -> NTP -> Stop -> Start.
  • Known log: wifi: nan is null is emitted by ESP-IDF during stop. This is harmless.
  • Hardware untested: ESP32-C3 / ESP32-S3 (verified symbol presence via nm only).

@hnw
hnw force-pushed the wifi-stop-powersave branch from ae1ead9 to 87b9929 Compare August 17, 2026 12:48
@hnw hnw changed the title feat: add Stop to power down the Wi-Fi driver between uses feat: add Stop() to power down Wi-Fi driver Aug 17, 2026
Expose esp_wifi_stop() as espradio.Stop() to save power when the
network is occasionally used. On an M5Stack Fire, stopping the
radio drops system current by ~50 mA.

API Note:
Stop() does not undo Enable(). Init-time state (ISR registration,
scheduler ticker) remains. The caller must re-establish association
and DHCP after a subsequent Start().

Implementation details:
- Stop() blocks until the blob posts the WIFI_EVENT_STA_STOP event
  or a 15-second timeout expires, mirroring the Connect() behavior.
@hnw
hnw force-pushed the wifi-stop-powersave branch from 87b9929 to ca75f53 Compare August 17, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant