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.
Very cool, but C++ bites buffalo butts.
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).
Can you develop?
Websocket is a neat and clean remedy that addresses one of the limitations of HTTP !
[citation needed]
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?
Yes please!
ADS.
Too bad that the ESP8266 async websockets support is problematic on Android :(
https://github.com/me-no-dev/ESPAsyncWebServer/issues/259
How about server-sent events? The ESPAsyncWebServer supports this, I use it in my projects – doesn’t work on MS browsers though but Chrome works fine.
Hi, do you have any experience with using ESP8266 with Arduino Nano and parsing API response after the HTTP request?
@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.
No need to be rude. The code is already open source, and available on Github, I was trying to see if there was interest in a written tutorial of some kind.
For what it’s worth, WebSockets on an ESP8266 is how last year I hacked together a pumpkin with LED eyes that I could control from my phone https://blog.lmorchard.com/2018/02/08/pumpkin/
The Arduino MCU`s like ATiny ATMega are quite weak and slow (only 4Kb RAM and 16MHz clock).Especially for the HTTP protocol