Reason code

ml8923
Posts: 3
Joined: Tue Jan 14, 2020 3:13 pm

Reason code

Postby ml8923 » Tue Jan 14, 2020 4:00 pm

How do I get the reason code with the non legacy event loop?
ie: static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)

I understand with the legacy eventloop:
esp_err_t event_handler(void *ctx, system_event_t *event)

I can get the info:
system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected;

I haven't seen examples anywhere of getting this information with the esp_event Library Event Loop though.

Thanks

ml8923
Posts: 3
Joined: Tue Jan 14, 2020 3:13 pm

Re: Reason code

Postby ml8923 » Tue Jan 14, 2020 4:20 pm

I've got it figured out. Thanks

wifi_event_sta_disconnected_t* event = (wifi_event_sta_disconnected_t*) event_data;
ESP_LOGI(TAG, "%d", event->reason);

ml8923
Posts: 3
Joined: Tue Jan 14, 2020 3:13 pm

Re: Reason code

Postby ml8923 » Tue Jan 14, 2020 5:35 pm

With the new handler:

wifi_event_sta_disconnected_t* event = (wifi_event_sta_disconnected_t*) event_data;

if(WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT == event->reason || WIFI_REASON_AUTH_FAIL == event->reason)
{
g_fatal_error = true;
ESP_LOGI(TAG,"Incorrect WiFi Credentials");
}

glrtheil
Posts: 61
Joined: Tue Dec 07, 2021 2:48 pm

Re: Reason code

Postby glrtheil » Tue Nov 29, 2022 6:42 pm

ml8923 wrote:
Tue Jan 14, 2020 5:35 pm
if(WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT == event->reason || WIFI_REASON_AUTH_FAIL == event->reason)
{
g_fatal_error = true;
ESP_LOGI(TAG,"Incorrect WiFi Credentials");
}
Just as a note, don't use WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT to determine whether or not the password is correct. I made this mistake in some custom firmware and there are a TON of cases where customers have weak wifi signals and even though wrong password can sometimes return as WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT, it can be a false positive. Even sometimes when reconnecting to wifi it will return WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT but we know the password is correct. Changing to only use WIFI_REASON_AUTH_FAIL is the only way to determine a wrong password.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 287 guests