Trying to stream data from ESP device over a web socket

#1

I’m trying to allow one or more client devices (like tablets and phones) to connect to an ESP32 via a websocket, via wifi or BT, and then have the ESP32 stream data to the client in JSON.

From searching it seems that I do this using the RPC libraries, including one called rpc-ws which I can not find in the API documentation. Regardless, it seems that I have to create a callback and then use mg_rpc_send_responsef() from within the callback.

But this only seems to work if the client takes some action to poll the server. How can I cause the server to stream data to the clients? Would I just use a timer with a callback that calls mg_rpc_send_responsef() even if there is nothing from the client?

Is there an example? After searching I have not found much.

Thank you…

1 Like
#2

Are you trying to make something like https://vcon.io ?

#3

You don’t need rpc-ws.

You need your client to open a websocket connection and your application to send data over it.

#4

No, I’m trying to have an uC stream data to an iPad for display, so the UI is on the iPad (or other device).

#5

Right, that’s what I’m trying to figure out how to do. More searching found some more hints so I’m still at it.

#6

The mgos_register_http_endpoint() should do the job:

As for the event handler function, see example: