Skip to content

Commit c8c3564

Browse files
committed
Some more fixes when disabling wifi
1 parent 0cefc23 commit c8c3564

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/esp32/esp32_wifi.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ static esp_err_t esp32_wifi_set_mode(wifi_mode_t mode) {
222222
}
223223

224224
if (mode == WIFI_MODE_NULL) {
225-
if (s_started) {
226-
esp_wifi_set_mode(WIFI_MODE_NULL);
227-
}
225+
esp_wifi_set_mode(mode);
228226
r = esp_wifi_stop();
229227
if (r == ESP_ERR_WIFI_NOT_INIT) r = ESP_OK; /* Nothing to stop. */
230228
if (r == ESP_OK) {
@@ -547,10 +545,13 @@ bool mgos_wifi_dev_ap_setup(const struct mgos_config_wifi_ap *cfg) {
547545

548546
bool mgos_wifi_dev_sta_connect(void) {
549547
if ((esp32_wifi_ensure_init() != ESP_OK) ||
550-
(esp32_wifi_ensure_start() != ESP_OK))
548+
(esp32_wifi_ensure_start() != ESP_OK)) {
551549
return false;
550+
}
552551
wifi_mode_t cur_mode = esp32_wifi_get_mode();
553-
if (cur_mode == WIFI_MODE_NULL || cur_mode == WIFI_MODE_AP) return false;
552+
if (cur_mode == WIFI_MODE_NULL || cur_mode == WIFI_MODE_AP) {
553+
return false;
554+
}
554555
esp_err_t r = esp_wifi_connect();
555556
if (r != ESP_OK) {
556557
LOG(LL_ERROR, ("WiFi STA: Connect failed: %d", r));
@@ -563,11 +564,14 @@ bool mgos_wifi_dev_sta_connect(void) {
563564

564565
bool mgos_wifi_dev_sta_disconnect(void) {
565566
wifi_mode_t cur_mode = esp32_wifi_get_mode();
566-
if (cur_mode == WIFI_MODE_NULL || cur_mode == WIFI_MODE_AP) return false;
567+
if (cur_mode == WIFI_MODE_NULL || cur_mode == WIFI_MODE_AP) {
568+
return false;
569+
}
567570
esp_wifi_disconnect();
568571
s_connecting = false;
569572
/* If we are in station-only mode, stop WiFi task as well. */
570573
if (cur_mode == WIFI_MODE_STA) {
574+
esp_wifi_set_mode(WIFI_MODE_NULL);
571575
esp_err_t r = esp_wifi_stop();
572576
if (r == ESP_ERR_WIFI_NOT_INIT) r = ESP_OK; /* Nothing to stop. */
573577
if (r == ESP_OK) {

src/mgos_wifi.c

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ bool mgos_wifi_setup_sta(const struct mgos_config_wifi_sta *cfg) {
199199
ret = mgos_wifi_connect();
200200
}
201201
} else {
202+
// May turn off STA mode, depending on the hardware.
203+
mgos_wifi_dev_sta_setup(cfg);
202204
ret = true;
203205
}
204206
return ret;

0 commit comments

Comments
 (0)