Chapter 4. Software framework
4.10.20 [Connect] While ESP32 connecting Wi-Fi, how can I determine the reason of
failure by error codes?
For ESP-IDF v4.0 and later versions, please refer to the following codes to get the reason:
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
wifi_event_sta_disconnected_t *sta_disconnect_evt = (wifi_event_sta_
,→disconnected_t*)event_data;
ESP_LOGI(TAG, "wifi disconnect reason:%d", sta_disconnect_evt->reason);
esp_wifi_connect();
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
}
When the callback function received WIFI_EVENT_STA_DISCONNECTED event, you can get the
reason through the reason variable from wi_event_sta_disconnected_t.
• WIFI_REASON_AUTH_EXPIRE: This code is returned during the auth phase when the STA
sends an auth but do not received any auth reply from the AP within the specied time. The
possibility of this code occurrence is low.
• WIFI_REASON_AUTH_LEAVE: This code is sent by AP, normally because the AP is discon-
nected from the STA for some reason.
• WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT or WIFI_REASON_HANDSHAKE_TIMEOUT:
Wrong password.
WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT is the standard generalized error code, while
WIFI_REASON_HANDSHAKE_TIMEOUT is a customized error code. The main dierence is:
WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT occurs when the router tells the device the
password is wrong;
WIFI_REASON_HANDSHAKE_TIMEOUT
occurs when the device itself per-
forms a timeout mechanism without being informed about the wrong password by the router.
• WIFI_REASON_CONNECTION_FAIL: This code is returned during the scan phase when the
STA scanned a matched AP while the AP is in the blacklist. This is probably because that the AP
has actively disconnected from the STA last time or something wrong happened when the STA
connecting the AP.
4.10.21 Does ESP32 perform domain name resolution each time it connects to the server?
The domain name is resolved via DNS within the stack, and the resolved data will be cached within
the specied time. The cache time is based on the TTL data obtained from the DNS server, which is a
parameter lled when conguring the domain name, usually 10 minutes.
4.10.22 [Connect] What does the number after the state machine switch in Wi-Fi log
mean?
eg: run -> init (fc0), fc0 means the STA has received the deauth frame and reason is password error.
• c0 indicates the received frame type (00 indicates a timeout)
• f indicates reason
Frame type: [a0 disassoc], [b0 auth], [c0 deauth].
Espressif Systems 130
Submit Document Feedback
Release master