Adding timeouts to the wifi event loop (adding user defined system events)
Posted: Thu Nov 09, 2017 3:20 am
Hello.
As the ESP32 has a softAP, the AP channel has to follow the radio channel. This means that in APSTA mode when scanning to join a STA the connections to the AP are lost.
To handle this I'm adding a higher level state machine to the wifi event loop and switching between AP, STA, and APSTA mode depending on events and timeouts. The net effect is that the user experience is optimized. We won't scan for STA, changing channels and dropping AP connections, if something is connected to the AP. We'll try to connect on startup to a STA and periodically retry etc. Yes its complicated but it also addresses pretty cleanly all of the use cases I've come up with so far.
I have added logic to the wifi event handler loop but some of this is timeout based.
So I'm using a FreeRTOS timer that does:
To inject timeouts events into the wifi event handler loop and let the state machine run again. The problem is that event iDs out of the normal range result in error prints on the console:
I'd prefer to keep my timeout logic combined with the wifi event loop to avoid race conditions between state changes and timeouts but these error prints kind of stink.
Am I missing some way to add new system events without having to modify esp_event.h and rebuild? I really dislike carrying around esp-idf changes. I could overload and use an event that doesn't mean anything to me, such as the ethernet events, or maybe SYSTEM_EVENT_WIFI_READY but that's also not the greatest looking solution.
As the ESP32 has a softAP, the AP channel has to follow the radio channel. This means that in APSTA mode when scanning to join a STA the connections to the AP are lost.
To handle this I'm adding a higher level state machine to the wifi event loop and switching between AP, STA, and APSTA mode depending on events and timeouts. The net effect is that the user experience is optimized. We won't scan for STA, changing channels and dropping AP connections, if something is connected to the AP. We'll try to connect on startup to a STA and periodically retry etc. Yes its complicated but it also addresses pretty cleanly all of the use cases I've come up with so far.
I have added logic to the wifi event handler loop but some of this is timeout based.
So I'm using a FreeRTOS timer that does:
Code: Select all
system_event_t timerEvent;
timerEvent.event_id = (system_event_id_t)(SYSTEM_EVENT_MAX);
esp_event_send(&timerEvent);
Code: Select all
W (13182) event: unexpected system event 24!
E (13182) event: mismatch or invalid event, id=24
E (13182) event: default event handler failed!
Am I missing some way to add new system events without having to modify esp_event.h and rebuild? I really dislike carrying around esp-idf changes. I could overload and use an event that doesn't mean anything to me, such as the ethernet events, or maybe SYSTEM_EVENT_WIFI_READY but that's also not the greatest looking solution.