diff options
| author | Damien George <damien@micropython.org> | 2023-06-21 17:08:08 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-06-23 15:34:37 +1000 |
| commit | bccbaa92b1fc6237f0f49a7f07cc194835fbf4e3 (patch) | |
| tree | 7bf5c1645dd80db67c2e3965606d51a2e824ff36 | |
| parent | 2cc3711e5e00c13d43771ee8a78778e7ef3c2930 (diff) | |
esp32/network_wlan: Wait for WIFI_EVENT_STA_START after activating.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/esp32/network_wlan.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index 63f01dfc2..cfedd898c 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -72,7 +72,7 @@ static bool mdns_initialised = false; #endif static uint8_t conf_wifi_sta_reconnects = 0; -static uint8_t wifi_sta_reconnects; +static volatile uint8_t wifi_sta_reconnects; // This function is called by the system-event task and so runs in a different // thread to the main MicroPython task. It must not raise any Python exceptions. @@ -233,16 +233,16 @@ STATIC mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) { } else { esp_exceptions(esp_wifi_set_mode(mode)); if (!wifi_started) { + // WIFI_EVENT_STA_START must be received before esp_wifi_connect() can be called. + // Use the `wifi_sta_reconnects` variable to detect that event. + wifi_sta_reconnects = 1; esp_exceptions(esp_wifi_start()); wifi_started = true; + while (wifi_sta_reconnects != 0) { + MICROPY_EVENT_POLL_HOOK; + } } } - // This delay is a band-aid patch for issues #8289, #8792 and #9236, - // allowing the esp data structures to settle. It looks like some - // kind of race condition, which is not yet found. But at least - // this small delay seems not hurt much, since wlan.active() is - // usually not called in a time critical part of the code. - mp_hal_delay_ms(1); } return (mode & bit) ? mp_const_true : mp_const_false; |
