Websockets: Async send within an interrupt

tomfrance
Posts: 12
Joined: Wed Mar 17, 2021 3:50 pm

Websockets: Async send within an interrupt

Postby tomfrance » Mon Apr 05, 2021 4:39 pm

Hello team!

I am working on a project where the client should be informed about a data update via a push from the server. The server is an ESP32 running esp_http_server and the data push is triggered by e.g., an SPI triggered event running in a seperate task.

What's the best way to accomplish this? All websocket examples (e.g., https://github.com/espressif/esp-idf/bl ... o_server.c) assume that the relevant code to trigger an update is called from within the request handler that is associated with the websocket (in particular regarding the access to the *req pointer).

To be able do something like [1], [2], it seems like I need access to the socket fds, that are associated with a previous websocket request as well as the httpd_handle_t that was initialized when the server was started. While I can pass the latter to other freertos task, I have no idea how to obtain the FDs in a nice manner and especially how to track whether they are related to a WS socket.

[1] https://github.com/espressif/esp-idf/bl ... rver.c#L40
[2] https://github.com/espressif/esp-idf/bl ... rver.c#L56

I have found the API function httpd_get_client_list() - is this the best way to accomplish this with manual tracking in the WS request handler which of those is related to a WS?

Thank you,
Tom

tomfrance
Posts: 12
Joined: Wed Mar 17, 2021 3:50 pm

Re: Websockets: Async send within an interrupt

Postby tomfrance » Mon Apr 05, 2021 11:08 pm

I just found out that a lot of useful stuff (e.g. sock_db and its members ws_handshake_detect) can be retrieved from the struct

struct httpd_data

defined in esp_httpd_priv.h However it seems like this data is not meant to be accessed.

Any other way?

tomfrance
Posts: 12
Joined: Wed Mar 17, 2021 3:50 pm

Re: Websockets: Async send within an interrupt

Postby tomfrance » Thu Apr 08, 2021 7:17 am

Hi guys!

Any ideas on this matter?

Best,
Tom

Who is online

Users browsing this forum: Womboo and 40 guests