ESP32 WebSockets

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

ESP32 WebSockets

Post by rdagger » Mon Sep 04, 2017 3:02 pm

Has anyone implemented WebSockets on an ESP32?

Capstan
Posts: 117
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: ESP32 WebSockets

Post by Capstan » Thu Sep 07, 2017 1:05 am

I've got a websocket client implementation that works on both ESP32 and ESP8266. It can connect up to a websocket server running the standard protocol. Right now it is kind of wound up with the application I'm writing but I could peel it out and opensource with some work.

But, it is based on this; https://github.com/danni/uwebsockets

There are two websocket clients there, the 'vanilla' kind and one that is purportedly compatible with socket.io. I couldn't get the socket.io version to connect with a known good server, but the vanilla one does. If you want to collaborate on this let me know.

User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Re: ESP32 WebSockets

Post by rdagger » Thu Sep 07, 2017 1:27 am

Capstan wrote:I've got a websocket client implementation that works on both ESP32 and ESP8266. It can connect up to a websocket server running the standard protocol. Right now it is kind of wound up with the application I'm writing but I could peel it out and opensource with some work.
But, it is based on this; https://github.com/danni/uwebsockets
There are two websocket clients there, the 'vanilla' kind and one that is purportedly compatible with socket.io. I couldn't get the socket.io version to connect with a known good server, but the vanilla one does. If you want to collaborate on this let me know.
I'll take a look at Danni's. I'd be interested to check out your code and help if I can.

Capstan
Posts: 117
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: ESP32 WebSockets

Post by Capstan » Thu Sep 07, 2017 5:05 pm

Let me know how it goes with the Danni code, what I have is just an extension of it.

The client operates in a read loop listening on the socket. Seems like it would be better to have an event be generated somehow when data is available to read rather than looping (and apparently hanging?) on a read attempt. Not sure if that behavior is implemented in Micropython. If you come up with a scheme for that please share.

Also I found that the call stack on the esp8266 is very shallow, you can't move incoming data through a couple of handler functions and then respond all on the same thread without getting stack overflow exceptions. I had to put incoming data on a queue and handle it some milliseconds later on a timer in order to fit under the call stack limit.

Post Reply