Skip to content

Commit c524900

Browse files
committed
check connected before connecting
1 parent 6a76b60 commit c524900

File tree

1 file changed

+9
-2
lines changed
  • ports/esp32s2/common-hal/wifi

1 file changed

+9
-2
lines changed

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host
126126
}
127127

128128
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) {
129-
// check enabled
129+
EventBits_t bits;
130+
bits = xEventGroupWaitBits(self->event_group_handle,
131+
WIFI_CONNECTED_BIT | WIFI_DISCONNECTED_BIT,
132+
pdTRUE,
133+
pdTRUE,
134+
0);
135+
if ((bits & WIFI_CONNECTED_BIT) != 0) {
136+
return WIFI_RADIO_ERROR_NONE;
137+
}
130138
start_station(self);
131139

132140
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
157165
self->retries_left = 5;
158166
esp_wifi_connect();
159167

160-
EventBits_t bits;
161168
do {
162169
RUN_BACKGROUND_TASKS;
163170
bits = xEventGroupWaitBits(self->event_group_handle,

0 commit comments

Comments
 (0)