esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
741 stars 207 forks source link

Accessing WifiEvent data #2412

Open Easyoakland opened 4 days ago

Easyoakland commented 4 days ago

Motivations

Getting the data from WifiEvents for application. I'm particularly interested in accessing wifi_event_ap_staconnected_t and wifi_event_ap_stadisconnected_t data to maintain a list of connected and disconnected clients and to do something based on the mac of the connecting or disconnecting client.

From what I can tell, this data is made available to the event_post function here but is discarded.

Solution

A way to access the data from WifiEvents. If not a blocking callback, then the events would have to buffer since losing an event matters.

Alternatives

For my particular problem of maintaining a list of connected macs, I can somewhat use the sta_list functions as here (aside: should I submit a pull request?) but the list appears to sometimes be out of sync and I have to manually compare the list before and after an event to find which entry was added or removed. It would make more sense to use the data of the event if it were available.

Additional context

Easyoakland commented 4 days ago

Also, does esp-hal support setting up event callbacks at all? As best I can tell, the only supported way to do this is using the async WifiController::wait_for_* functions in a super-function which has a unique reference to the controller and dispatches to callback by matching the received event.

bjoernQ commented 2 days ago

Having a way for user code to

a) subscribe to events and/or dequeue events b) get event data (see https://github.com/espressif/esp-idf/blob/9106c43accd9f5e75379f62f12597677213f5023/components/esp_wifi/include/esp_wifi_types_generic.h#L1032-L1146)

Seems like a good idea. (we don't have it yet)

Ideally the user could mask out events they are not interested in