common_hal_wifi_radio_start_scanning_networks() sets self->current_scan (Radio.c:245) and only two paths ever clear it:
common_hal_wifi_radio_stop_scanning_networks() (Radio.c:278)
- the
!started && enabled branch of set_enabled() (Radio.c:112)
If iteration over the results is abandoned, for example an exception in the loop body or a break, neither runs. current_scan stays set and every later scan raises:
RuntimeError: Already scanning for wifi networks
from the guard at Radio.c:238.
Observed
A code.py that scanned and hit an exception mid-iteration left the radio in this state. Because code.py runs again on every boot, the state was recreated immediately after each reset, so it looked like the condition survived a commander device reset. It did not survive the reset itself, it was simply re-established. Recovery needed a code.py that does not scan.
Once in this state the board is not usable for scanning at all, and wifi.radio.connect() is unaffected, so it is easy to mistake for a scan-only hardware fault.
Suggested
Clear current_scan when the iterator is exhausted or collected, or make wifi_reset() clear it unconditionally rather than only via the set_enabled() path. A break out of for n in wifi.radio.start_scanning_networks(): is ordinary user code and should not brick scanning until the next power cycle.
Related: #59 (calling stop_scanning_networks() to recover hangs the board).
common_hal_wifi_radio_start_scanning_networks()setsself->current_scan(Radio.c:245) and only two paths ever clear it:common_hal_wifi_radio_stop_scanning_networks()(Radio.c:278)!started && enabledbranch ofset_enabled()(Radio.c:112)If iteration over the results is abandoned, for example an exception in the loop body or a
break, neither runs.current_scanstays set and every later scan raises:from the guard at
Radio.c:238.Observed
A
code.pythat scanned and hit an exception mid-iteration left the radio in this state. Becausecode.pyruns again on every boot, the state was recreated immediately after each reset, so it looked like the condition survived acommander device reset. It did not survive the reset itself, it was simply re-established. Recovery needed acode.pythat does not scan.Once in this state the board is not usable for scanning at all, and
wifi.radio.connect()is unaffected, so it is easy to mistake for a scan-only hardware fault.Suggested
Clear
current_scanwhen the iterator is exhausted or collected, or makewifi_reset()clear it unconditionally rather than only via theset_enabled()path. Abreakout offor n in wifi.radio.start_scanning_networks():is ordinary user code and should not brick scanning until the next power cycle.Related: #59 (calling
stop_scanning_networks()to recover hangs the board).