Skip to content

Commit 1f6cd49

Browse files
committed
1. check enabled before scan; 2. make start-station() the single control point for esp_wifi_set_mode()
1 parent 672d0e2 commit 1f6cd49

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,6 @@ msgstr ""
564564
msgid "Can only alarm on two low pins from deep sleep."
565565
msgstr ""
566566

567-
#: ports/esp32s2/common-hal/wifi/Radio.c
568-
msgid "Can't connect when wifi is not enabled"
569-
msgstr ""
570-
571567
#: ports/nrf/common-hal/_bleio/Characteristic.c
572568
msgid "Can't set CCCD on local Characteristic"
573569
msgstr ""
@@ -3910,6 +3906,10 @@ msgstr ""
39103906
msgid "width must be greater than zero"
39113907
msgstr ""
39123908

3909+
#: ports/esp32s2/common-hal/wifi/Radio.c
3910+
msgid "wifi is not enabled"
3911+
msgstr ""
3912+
39133913
#: shared-bindings/_bleio/Adapter.c
39143914
msgid "window must be <= interval"
39153915
msgstr ""

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
7272
}
7373
if (!self->started && enabled) {
7474
// esp_wifi_start() would default to soft-AP, thus setting it to station
75-
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
75+
start_station(self);
7676
ESP_ERROR_CHECK(esp_wifi_start());
7777
self->started = true;
7878
return;
@@ -89,7 +89,9 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
8989
if (self->current_scan != NULL) {
9090
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
9191
}
92-
// check enabled
92+
if (!common_hal_wifi_radio_get_enabled(self)) {
93+
mp_raise_RuntimeError(translate("wifi is not enabled"));
94+
}
9395
start_station(self);
9496

9597
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
@@ -127,7 +129,7 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host
127129

128130
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) {
129131
if (!common_hal_wifi_radio_get_enabled(self)) {
130-
mp_raise_RuntimeError(translate("Can't connect when wifi is not enabled"));
132+
mp_raise_RuntimeError(translate("wifi is not enabled"));
131133
}
132134

133135
EventBits_t bits;

0 commit comments

Comments
 (0)