← index #8994PR #9004
Duplicate · high · value 4.277
QUERY · ISSUE

ESP32: Wifi peripheral configuration is not reset before/after a soft reset or light/deep sleep.

openby glenn20opened 2022-07-31updated 2025-09-22
bugport-esp32

After a soft reset, micropython restarts with the wifi peripheral configuration continuing as set prior to the reset.

This may be regarded as a feature by some (eg. continued connection to wifi Access Point) after reset, however, it

  • requires additional unexpected and undocumented protection code in startup scripts
    • eg. sta.connect(ssid, pwd) will raise an exception after a soft reset if already connected().
  • difficult to diagnose errors can arise in circumstances where the peripheral is left in a bad state or a state unexpected by the users or the micropython software after reset.

I have made the mistake of chasing apparent bugs in my apps (or while developing PR #6515) only for them to resolve after a hard reset. I have also dealt with a number of users reporting issues which have turned out to be due to the wifi peripheral being in a bad state and not being re-initialised after a soft reset. I suspect this may also be contributing to user frustration with apparent lack of reproducibility or reliability.

I propose to prepare a PR which:

  • calls esp_wifi_stop() and esp_wifi_deinit() before soft reset

An alternative may be to call esp_wifi_deinit() on bootup before esp_wifi_init().

I am aware that some may rely on the current (undocumented) behaviour, though I believe that for predictability and reproducibility it is much more desirable to allways start micropython with the peripheral in a known state.

CANDIDATE · PULL REQUEST

ports/esp32: Deinit wifi peripheral on soft_reset and stop wifi before light/deep sleep.

closedby glenn20opened 2022-08-01updated 2023-06-26
port-esp32

This PR adds support for deinitialising the wifi peripheral prior to performing a soft reset. Besides calling esp_wifi_deinit(), it also resets the static state variables in network_wlan.c to their default values.

In this way, the wifi peripheral is always in a known state after a soft reset.

Adds:

  • network_wlan_deinit_wifi(), network_wlan_stop_wifi(), and network_wlan_init_wifi() to network_wlan.c;
  • WLAN.deinit() method;
    • so users can invoke a reset of the wifi peripheral and module state
    • (as well as freeing wifi and mdns resources).
  • call to network_wlan_deinit_wifi() before soft_reset in main.c; and
  • calls to network_wlan_stop_wifi() before light or deep sleep in machine.c;

Resolves #8994.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied