Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[esp32] Fix mgos_wifi_scan never completing if wifi in connecting state #24

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions esp32/src/esp32_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

static bool s_inited = false;
static bool s_started = false;
static bool s_connecting = false;

typedef esp_err_t (*wifi_func_t)(void *arg);

esp_err_t esp32_wifi_ev(system_event_t *ev) {
Expand All @@ -62,10 +64,12 @@ esp_err_t esp32_wifi_ev(system_event_t *ev) {
mg_ev = MGOS_WIFI_EV_STA_DISCONNECTED;
mg_ev_arg = &sta_disconnected;
send_mg_ev = true;
s_connecting = false;
break;
case SYSTEM_EVENT_STA_CONNECTED:
mg_ev = MGOS_WIFI_EV_STA_CONNECTED;
send_mg_ev = true;
s_connecting = false;
tripflex marked this conversation as resolved.
Show resolved Hide resolved
break;
case SYSTEM_EVENT_STA_GOT_IP:
mg_ev = MGOS_WIFI_EV_STA_IP_ACQUIRED;
Expand Down Expand Up @@ -501,6 +505,9 @@ bool mgos_wifi_dev_sta_connect(void) {
esp_err_t r = esp_wifi_connect();
if (r != ESP_OK) {
LOG(LL_ERROR, ("WiFi STA: Connect failed: %d", r));
s_connecting = false;
} else {
s_connecting = true;
}
return (r == ESP_OK);
}
Expand All @@ -509,6 +516,7 @@ bool mgos_wifi_dev_sta_disconnect(void) {
wifi_mode_t cur_mode = esp32_wifi_get_mode();
if (cur_mode == WIFI_MODE_NULL || cur_mode == WIFI_MODE_AP) return false;
esp_wifi_disconnect();
s_connecting = false;
/* If we are in station-only mode, stop WiFi task as well. */
if (cur_mode == WIFI_MODE_STA) {
esp_err_t r = esp_wifi_stop();
Expand Down Expand Up @@ -584,6 +592,10 @@ bool mgos_wifi_dev_start_scan(void) {
.active = {
.min = 10, .max = 50,
}, }};
if( s_connecting ){
esp_wifi_disconnect();
s_connecting = false;
}
r = esp_wifi_scan_start(&scan_cfg, false /* block */);
}
return (r == ESP_OK);
Expand Down