Hello ESP-IDF community,
I’m working on an ESP32 project using ESP-IDF, and I’m facing an issue where my code gets stuck in the WiFi event handler when WiFi disconnects. This prevents other tasks, including one with priority 7, from executing. I expected the higher-priority task to run, but it seems the WiFi event handler is blocking the FreeRTOS scheduler. I’d appreciate any insights or suggestions to resolve this.
ESP32 WiFi Event Handler Blocks Other High-Priority Tasks on Disconnect
-
nopnop2002
- Posts: 362
- Joined: Thu Oct 03, 2019 10:52 pm
- Contact:
Re: ESP32 WiFi Event Handler Blocks Other High-Priority Tasks on Disconnect
Unless you reveal the WiFi handler code you're using, no one can know what the problem is.
Re: ESP32 WiFi Event Handler Blocks Other High-Priority Tasks on Disconnect
My wifi handler code:
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_AP_STACONNECTED)
{
wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t *)event_data;
ESP_LOGI(TAG, "Station " MACSTR " joined, AID=%d",
MAC2STR(event->mac), event->aid);
}
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STADISCONNECTED)
{
wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t *)event_data;
ESP_LOGI(TAG, "Station " MACSTR " left, AID=%d, reason:%d",
MAC2STR(event->mac), event->aid, event->reason);
}
else 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");
vTaskDelay(pdMS_TO_TICKS(4000)); // Delay between retries (10 seconds)
}
else
{
esp_wifi_connect(); // Attempt to reconnect
vTaskDelay(pdMS_TO_TICKS(1000)); // Wait 1 second before reconnecting
s_retry_num = 0; // Reset the retry count if needed
}
wifi_connected = false; // Wi-Fi not connected
}
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
{
esp_wifi_connect();
ESP_LOGI("sta connection ...", "Station started");
start_webserver(); // Ensure the server is started in STA mode as well
}
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
ESP_LOGI("Tag _ sta ...", "Got IP:" IPSTR, IP2STR(&event->ip_info.ip));
s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
wifi_connected = true; // Wi-Fi connected successfully
}
}
Who is online
Users browsing this forum: No registered users and 1 guest