WebSockets Embedded With The ESP8266

It used to be that Web browsing was simple. You asked a server for some text, which was duly sent, and then formatted by your browser. Now a web page is as likely to be a full-blown application that is reading mail, editing text, or lots of other things and may use WebSockets to create a back channel to the server. Thanks to affordable hardware like the ESP8266 one of those things a modern web browser can do is sense and control the real world. [Acrobotic] has an interesting video about using WebSockets to allow a browser to talk to an ESP8266 web server in real time. You can see his simple demo in the video below.

Of course, you’ll use the usual language you use on the ESP8266 — [Acrobotic] uses C++ in the Arduino IDE. On the browser side you’ll use JavaScript, although that will be embedded in your C++ program which acts as a web server.

It’s as well to remember that there are several other ways you could do this. You could, for example ask for a different URL, or pass data in a query string. The problem here is that the performance would suffer as you have to establish a new connection every time. you want to transact with the server. You could also use AJAX methods but they are not as efficient either since they are primarily aimed at updating a portion of a web page dynamically. The web socket is simple enough and as you can see in the video, the performance is quite good. It also facilitates non-browser based clients that use the same service.

We’ve seen this technique used to fly a quadcopter. WebSockets have been around for a while, so your browser should support them. If it doesn’t, though, you can always use this hack — at least in one direction.

14 thoughts on “WebSockets Embedded With The ESP8266

  1. I wondered how people like cnlohr could display real-time status from their ESP8266 project, but their final code was way too complex for me to understand and use quickly. Then I stumbled on a very simple simple project on the (by the way excellent) AMG8833 IR grid sensor (https://gist.github.com/NeoCat/a57f73b8db0605e1763d3ca1a1f75941) which included the easy to use WebSocketsServer library for arduino. It’s simpler, lighter and faster than trying to use AJAX (and doesn’t need any aditionnal JS library in modern browser).

  2. I’ve been working on developing a variety of ESP8266 hardware nodes which, instead of hosting their own websocket servers, connect to a central websocket server in order to receive commands. Would folk be interested in a write-up?

  3. @jpoles1 The best way to find out if developers like your ideas, is to open source it and get some feedback.
    If you want an invitation, OK I would like to see your code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.