Merge pull request #4017 from anecdata/connect
ESP32-S2 wifi radio: check whether already connected before trying to connect
This commit is contained in:
commit
ec8a42d7c9
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -467,7 +467,7 @@ jobs:
|
|||||||
id: idf-cache
|
id: idf-cache
|
||||||
with:
|
with:
|
||||||
path: ${{ github.workspace }}/.idf_tools
|
path: ${{ github.workspace }}/.idf_tools
|
||||||
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210121
|
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210122
|
||||||
- name: Clone IDF submodules
|
- name: Clone IDF submodules
|
||||||
run: |
|
run: |
|
||||||
(cd $IDF_PATH && git submodule update --init)
|
(cd $IDF_PATH && git submodule update --init)
|
||||||
|
@ -3930,6 +3930,10 @@ msgstr ""
|
|||||||
msgid "width must be greater than zero"
|
msgid "width must be greater than zero"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ports/esp32s2/common-hal/wifi/Radio.c
|
||||||
|
msgid "wifi is not enabled"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/_bleio/Adapter.c
|
#: shared-bindings/_bleio/Adapter.c
|
||||||
msgid "window must be <= interval"
|
msgid "window must be <= interval"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -72,7 +72,7 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
|
|||||||
}
|
}
|
||||||
if (!self->started && enabled) {
|
if (!self->started && enabled) {
|
||||||
// esp_wifi_start() would default to soft-AP, thus setting it to station
|
// esp_wifi_start() would default to soft-AP, thus setting it to station
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
start_station(self);
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
self->started = true;
|
self->started = true;
|
||||||
return;
|
return;
|
||||||
@ -89,7 +89,9 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
|
|||||||
if (self->current_scan != NULL) {
|
if (self->current_scan != NULL) {
|
||||||
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
|
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
|
||||||
}
|
}
|
||||||
// check enabled
|
if (!common_hal_wifi_radio_get_enabled(self)) {
|
||||||
|
mp_raise_RuntimeError(translate("wifi is not enabled"));
|
||||||
|
}
|
||||||
start_station(self);
|
start_station(self);
|
||||||
|
|
||||||
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
|
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
|
||||||
@ -126,7 +128,25 @@ 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) {
|
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
|
if (!common_hal_wifi_radio_get_enabled(self)) {
|
||||||
|
mp_raise_RuntimeError(translate("wifi is not enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
EventBits_t bits;
|
||||||
|
// can't block since both bits are false after wifi_init
|
||||||
|
// both bits are true after an existing connection stops
|
||||||
|
bits = xEventGroupWaitBits(self->event_group_handle,
|
||||||
|
WIFI_CONNECTED_BIT | WIFI_DISCONNECTED_BIT,
|
||||||
|
pdTRUE,
|
||||||
|
pdTRUE,
|
||||||
|
0);
|
||||||
|
if (((bits & WIFI_CONNECTED_BIT) != 0) &&
|
||||||
|
!((bits & WIFI_DISCONNECTED_BIT) != 0)) {
|
||||||
|
return WIFI_RADIO_ERROR_NONE;
|
||||||
|
}
|
||||||
|
// explicitly clear bits since xEventGroupWaitBits may have timed out
|
||||||
|
xEventGroupClearBits(self->event_group_handle, WIFI_CONNECTED_BIT);
|
||||||
|
xEventGroupClearBits(self->event_group_handle, WIFI_DISCONNECTED_BIT);
|
||||||
start_station(self);
|
start_station(self);
|
||||||
|
|
||||||
wifi_config_t* config = &self->sta_config;
|
wifi_config_t* config = &self->sta_config;
|
||||||
@ -157,7 +177,6 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
|
|||||||
self->retries_left = 5;
|
self->retries_left = 5;
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
|
|
||||||
EventBits_t bits;
|
|
||||||
do {
|
do {
|
||||||
RUN_BACKGROUND_TASKS;
|
RUN_BACKGROUND_TASKS;
|
||||||
bits = xEventGroupWaitBits(self->event_group_handle,
|
bits = xEventGroupWaitBits(self->event_group_handle,
|
||||||
|
Loading…
Reference in New Issue
Block a user