(solved) esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(solved) esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

Postby mzimmers » Fri Oct 29, 2021 4:20 am

Hi all -

Trying to write an initialization routine...starts like this:

Code: Select all

esp_err_t wifiInit(wifi_mode_t mode) {
    esp_err_t err = ESP_OK;
    do {
        // step 1 in https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/wifi.html:
        // Wifi/LwIP Init.
        // step 1.1: call esp_netif_init()
        err = esp_netif_init();
        if (err != ESP_OK) {
            ESP_LOGE(TAG, "wifiInit(): esp_netif_init() returned \"%s\".", esp_err_to_name(err));
            continue;
        }

        // step 1.2 
        // identify the event handler.
        err = esp_event_loop_create_default();
        if (err != ESP_OK) {
            ESP_LOGE(TAG, "wifiInit(): esp_event_loop_create_default() returned \"%s\".", esp_err_to_name(err));
            continue;
        }
And the call to esp_event_loop_create_default() returns ESP_ERR_INVALID_STATE.

What state is the error message referring to? And, what could be causing this so early in the routine?

Thanks...
Last edited by mzimmers on Sat Oct 30, 2021 3:31 am, edited 1 time in total.

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

Postby boarchuz » Fri Oct 29, 2021 4:59 am

Probably because it's already initialised. Many components depend on the event loop being initialised, so you should do it once early in your main initialisation. Repeated calls will return ESP_ERR_INVALID_STATE.

Is there another esp_event_loop_create_default() somewhere before this wifiInit()?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

Postby mzimmers » Sat Oct 30, 2021 3:31 am

Hi boarchuz - that was the problem. I had one call, but it was in a routine that was repeated. Thanks for the help.

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Re: (solved) esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

Postby leschge » Thu Jun 09, 2022 2:49 pm

This behavior is not documented in the reference, and it should be declared what cause this error raises. (Probably because it's already initialised. )
https://docs.espressif.com/projects/esp ... e_defaultv

HPekiM
Posts: 4
Joined: Mon Oct 10, 2022 5:54 pm

Re: (solved) esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

Postby HPekiM » Wed Oct 26, 2022 5:24 pm

Is there any means to detect if "esp_event_loop_create_default()" was already called before? Or do I have to keep track of that call on my own?

Thanks in advance
Mike

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: (solved) esp_event_loop_create_default() returned ESP_ERR_INVALID_STATE

Postby mzimmers » Wed Oct 26, 2022 5:28 pm

Well, you could use the return from the call.

Who is online

Users browsing this forum: No registered users and 135 guests