Why is my ESP32 task not logging when Wi-Fi is disconnected, but Wi-Fi retry logs are showing up?

Vaibhav02
Posts: 11
Joined: Wed Sep 04, 2024 8:09 am

Why is my ESP32 task not logging when Wi-Fi is disconnected, but Wi-Fi retry logs are showing up?

Postby Vaibhav02 » Sat Jan 04, 2025 10:47 am

I'm working with an ESP32, and I have a task that publishes data to the cloud. When the Wi-Fi is disconnected, the wifi_event_handler keeps retrying to connect, and I can see the retry logs on the monitor. However, the task publish_data_to_cloud does not log anything to the monitor when the Wi-Fi is disconnected.

Here is the relevant code for the Wi-Fi event handler:

Code: Select all

void wifi_event_handler(void *arg, esp_event_base_t event_base,
                               int32_t event_id, void *event_data)
{
    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
    {
        if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
        {
            esp_wifi_connect();
            s_retry_num++;
            ESP_LOGI("sta....", "retry to connect to the AP");
        }
        else
        {
            esp_wifi_disconnect(); 
            esp_wifi_connect();
            s_retry_num = 0;
        }
        is_wifi = false;
        ESP_LOGI(TAG, "is_wifi: %d", is_wifi);
    }
    // Other event cases...
}
And I'm creating the task as follows:

Code: Select all

xTaskCreate(publish_data_to_cloud, "publish_data_to_cloud", 8192, &ucParameterToPass, 1, NULL);
The issue is:

The Wi-Fi retry logs are printing as expected.
The publish_data_to_cloud task doesn't log anything when Wi-Fi is disconnected.
I believe the task should run regardless of the Wi-Fi connection status, but it's not logging when the Wi-Fi is down. Is there something I'm missing? What could cause this issue, and how can I fix it so that the task logs even when Wi-Fi is disconnected?

Any help would be appreciated!

MicroController
Posts: 1994
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Why is my ESP32 task not logging when Wi-Fi is disconnected, but Wi-Fi retry logs are showing up?

Postby MicroController » Sat Jan 04, 2025 1:16 pm

Obviously not a problem with the code you showed but with the task you didn't show.
Might be blocking waiting for the network or something.

Vaibhav02
Posts: 11
Joined: Wed Sep 04, 2024 8:09 am

Re: Why is my ESP32 task not logging when Wi-Fi is disconnected, but Wi-Fi retry logs are showing up?

Postby Vaibhav02 » Mon Jan 06, 2025 6:35 am

How can I solve this issue can you please guide me?

Who is online

Users browsing this forum: No registered users and 70 guests