[solved] IP_EVENT_STA_GOT_IP never triggered

steeveone
Posts: 10
Joined: Fri Jan 10, 2020 10:17 pm

[solved] IP_EVENT_STA_GOT_IP never triggered

Postby steeveone » Tue Jan 10, 2023 1:57 pm

Hello,
i have registered the following wifi event handler:

Code: Select all

static void wifi_event_handler(void* arg, esp_event_base_t event_base,
                                    int32_t event_id, void* event_data)
{
    if (event_id == WIFI_EVENT_AP_STACONNECTED) {
        wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
        ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
                 MAC2STR(event->mac), event->aid);
    } else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
        wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
        ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d",
                 MAC2STR(event->mac), event->aid);
    } else if ( event_id == IP_EVENT_STA_GOT_IP) {
		ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
		//xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
	}else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
    {
        ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
        xEventGroupSetBits(wifi_event_group, WIFI_FAIL_BIT);
    }
    else if (event_id == WIFI_EVENT_STA_CONNECTED )
    {
        ESP_LOGI(TAG, "WIFI_EVENT_STA_CONNECTED");
		xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_BIT);
    }
}
but despite i get an ip the event IP_EVENT_STA_GOT_IP is never triggered:

Code: Select all

I (99078) example: WIFI_MODE_STA connected
I (99788) esp_netif_handlers: sta ip: 192.168.1.111, mask: 255.255.255.0, gw: 192.168.1.254
I don't know how to debug this problem, any help is appriciated.
Last edited by steeveone on Tue Jan 10, 2023 8:30 pm, edited 1 time in total.

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: IP_EVENT_STA_GOT_IP never triggered

Postby mbratch » Tue Jan 10, 2023 3:19 pm

Hi steeveone

Just to confirm, can you show what your call to `esp_event_handler_instance_register` looks like?
Are you getting any other events?

steeveone
Posts: 10
Joined: Fri Jan 10, 2020 10:17 pm

Re: IP_EVENT_STA_GOT_IP never triggered

Postby steeveone » Tue Jan 10, 2023 8:10 pm

hello! follows the esp_event_handler_instance_register call:

Code: Select all

ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                                                        ESP_EVENT_ANY_ID,
                                                        &wifi_event_handler,
                                                        NULL,
                                                        NULL));

yes I am actually getting other events like WIFI_EVENT_STA_CONNECTED and WIFI_EVENT_STA_DISCONNECTED

--- edit ---
found the problem, added

Code: Select all

ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
                                                        IP_EVENT_STA_GOT_IP,
                                                        &wifi_event_handler,
                                                        NULL,
                                                        NULL));
and now the event is triggered

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: IP_EVENT_STA_GOT_IP never triggered

Postby mbratch » Wed Jan 11, 2023 12:39 pm

steeveone wrote:
Tue Jan 10, 2023 8:10 pm
found the problem, added

Code: Select all

ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
                                                        IP_EVENT_STA_GOT_IP,
                                                        &wifi_event_handler,
                                                        NULL,
                                                        NULL));
and now the event is triggered
Yes after seeing your initial register call I was going to suggest that. There are actually different "event bases" to register and your original call only registered one of them.

xiaoxiao
Posts: 1
Joined: Mon Jul 29, 2024 7:17 am

Re: [solved] IP_EVENT_STA_GOT_IP never triggered

Postby xiaoxiao » Fri Sep 27, 2024 9:13 am

I encountered the same issue. I have correctly registered two examples. The first time I call the wifi_init_sta() function, it correctly triggers the IP_EVENT_STA_GOT_IP event. However, if I switch networks in between and call the wifi_init_sta() function again, the IP_EVENT_STA_GOT_IP event is not triggered. Can anyone provide an answer to this problem?

Who is online

Users browsing this forum: No registered users and 239 guests