Skip to content

Commit

Permalink
esp32/network_wlan: Fix network.WLAN.status().
Browse files Browse the repository at this point in the history
It can return STAT_NO_AP_FOUND and STAT_WRONG_PASSWORD.
This allows users to set the correct credentials.

Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
  • Loading branch information
IhorNehrutsa committed Nov 9, 2023
1 parent a00c9d5 commit 41d8e9b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ports/esp32/network_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@ static void network_wlan_wifi_event_handler(void *event_handler_arg, esp_event_b
switch (disconn->reason) {
case WIFI_REASON_BEACON_TIMEOUT:
// AP has dropped out; try to reconnect.
message = "\nbeacon timeout";
message = "beacon timeout";
break;
case WIFI_REASON_NO_AP_FOUND:
// AP may not exist, or it may have momentarily dropped out; try to reconnect.
message = "\nno AP found";
message = "no AP found";
break;
case WIFI_REASON_AUTH_FAIL:
// Password may be wrong, or it just failed to connect; try to reconnect.
message = "\nauthentication failed";
message = "authentication failed";
break;
default:
// Let other errors through and try to reconnect.
break;
}
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d%s", disconn->reason, message);
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d:%s", disconn->reason, message);

wifi_sta_connected = false;
if (wifi_sta_connect_requested) {
Expand Down Expand Up @@ -333,6 +333,8 @@ STATIC mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) {
if (wifi_sta_connected) {
// Happy path, connected with IP
return MP_OBJ_NEW_SMALL_INT(STAT_GOT_IP);
} else if ((wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND) || (wifi_sta_disconn_reason == WIFI_REASON_AUTH_FAIL)) {
return MP_OBJ_NEW_SMALL_INT(wifi_sta_disconn_reason);
} else if (wifi_sta_connect_requested
&& (conf_wifi_sta_reconnects == 0
|| wifi_sta_reconnects < conf_wifi_sta_reconnects)) {
Expand Down

0 comments on commit 41d8e9b

Please sign in to comment.