Adding timeouts to the wifi event loop (adding user defined system events)

cmorgan
Posts: 89
Joined: Thu Aug 24, 2017 12:52 am

Adding timeouts to the wifi event loop (adding user defined system events)

Postby cmorgan » 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:

Code: Select all

    system_event_t timerEvent;
    timerEvent.event_id = (system_event_id_t)(SYSTEM_EVENT_MAX);
    esp_event_send(&timerEvent);
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:

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!
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.

cmorgan
Posts: 89
Joined: Thu Aug 24, 2017 12:52 am

Re: Adding timeouts to the wifi event loop (adding user defined system events)

Postby cmorgan » Mon Nov 13, 2017 6:11 pm

In case anyone is interested I ended up marshalling the events over to another task and processing them there. I could have kept the processing in the other task but the errors on the console were making it difficult to see when real errors occurred.

The event code could have been modified to add an element to system_event_t but I'd prefer not to carry around esp-idf changes.

The implementation is basically a copy of the approach from the esp event loop using xQueueSend and xQueueReceive so it was quite easy. The downside is that extra stack space is used by this other thread and that's a bit of a waste given that the event task is perfectly fine for my use.

If you'd like other info please let me know!

Who is online

Users browsing this forum: No registered users and 92 guests