diff options
| author | anecdata <16617689+anecdata@users.noreply.github.com> | 2021-01-17 20:21:31 -0600 |
|---|---|---|
| committer | anecdata <16617689+anecdata@users.noreply.github.com> | 2021-01-17 20:21:31 -0600 |
| commit | c524900a1b5c1a68cd3faec74e47e0fbc6dd0d5c (patch) | |
| tree | beb9848a6b04e35cc9beee8eaaab1556b8ea295f | |
| parent | 6a76b60027aa163756aace389a5c9203594759ce (diff) | |
check connected before connecting
| -rw-r--r-- | ports/esp32s2/common-hal/wifi/Radio.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 930230088..696af28f8 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -126,7 +126,15 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host } wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t* bssid, size_t bssid_len) { - // check enabled + EventBits_t bits; + bits = xEventGroupWaitBits(self->event_group_handle, + WIFI_CONNECTED_BIT | WIFI_DISCONNECTED_BIT, + pdTRUE, + pdTRUE, + 0); + if ((bits & WIFI_CONNECTED_BIT) != 0) { + return WIFI_RADIO_ERROR_NONE; + } start_station(self); wifi_config_t* config = &self->sta_config; @@ -157,7 +165,6 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t self->retries_left = 5; esp_wifi_connect(); - EventBits_t bits; do { RUN_BACKGROUND_TASKS; bits = xEventGroupWaitBits(self->event_group_handle, |
