Page 1 of 1

[solved] IP_EVENT_STA_GOT_IP never triggered

Posted: Tue Jan 10, 2023 1:57 pm
by steeveone
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.

Re: IP_EVENT_STA_GOT_IP never triggered

Posted: Tue Jan 10, 2023 3:19 pm
by mbratch
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?

Re: IP_EVENT_STA_GOT_IP never triggered

Posted: Tue Jan 10, 2023 8:10 pm
by steeveone
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

Re: IP_EVENT_STA_GOT_IP never triggered

Posted: Wed Jan 11, 2023 12:39 pm
by mbratch
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.