Closed jmattsson closed 2 years ago
Does the espressif server support websockets? I actually use a LUA based httpserver with support for websockets as it enabled some highly interactive use cases....
There is some websocket support, yes. I haven't tried wiring it up yet as I haven't had a use-case for it. When I looked at it it wasn't entirely straight forward how one would best surface it into Lua.
It appears that the Espressif web server just calls the handler function for each websocket message received and then allows you to transmit a response later. In this way it is very similar to the standard processing except that (I think) the callback can send multiple messages back through the websocket.
The differences are that you have to use httpd_ws_recv_frame
and httpd_ws_send_frame
when interacting with the websocket.
I think that the LUA api should look like:
The handler function is called with two arguments:
send
method on it that can be used for sending response frames. The user program can also attach state variable to this object. The received frame will be nil if this is the start of a session.
The context object can be saved until later.
The frame (in each direction) is represented by a table with two keys: type
and data
. The type
is either text
or binary
. The data
is a string. Three additional types are used for control frames -- close
, ping
, pong
.
Receiving a close
message means that this is the last message that will be received.
Sending a close
message will close the connection.
@pjsg That sounds pretty reasonable. Did you find any actual API documentation for the Espressif WebSocket API, or just the example?
Did you want to work on that, or did you want me to? I could possibly fit it in, but I couldn't give you a definite time frame. And are you okay with me merging in this PR in the meantime, and treating websocket support as a future enhancement?
Yes. Merge it and file a ticket for the enhancement.
On Thu, Mar 3, 2022, 20:15 Johny Mattsson @.***> wrote:
@pjsg https://github.com/pjsg That sounds pretty reasonable. Did you find any actual API documentation for the Espressif WebSocket API, or just the example?
Did you want to work on that, or did you want me to? I could possibly fit it in, but I couldn't give you a definite time frame. And are you okay with me merging in this PR in the meantime, and treating websocket support as a future enhancement?
— Reply to this email directly, view it on GitHub https://github.com/nodemcu/nodemcu-firmware/pull/3502#issuecomment-1058728703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALQLTLCQ57VZ42X44DNDL3U6FP4DANCNFSM5NUZJXBA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
dev
branch rather than for therelease
branch.docs/*
.This PR adds two new modules:
httpd
which provides an interface to Espressif's web server that is included in the IDF.eromfs
(Embedded ReadOnly Mountable File Sets) which makes it easy to include files within the firmware itself, allowing for easy OTA upgrades. This is predominantly aimed at including the static web contents when using thehttpd
module, though other uses are of course also possible.The
httpd
module is able to offload all static file serving to the IDF's web server task, for minimum impact to the LVM. Dynamic route handlers are bounced into the LVM task. Chunked body receiving and sending is supported. For details, refer to the documentation.