ESP8266 AJAX - WebSocket Dynamic Communication

Esp8266 is a chip that supports the tcp / ip protocol. With this chip for a few dollars you can log into the IOT world and create wonders. There are 2 ways to track or manipulate any data dynamically with the ESP8266. One is AJAX and the other is Websocket technology.

AJAX, in early 2000, made static websites dynamic. Asynchronous JavaScript and XML (AJAX) creates a bridge between the server and client and keeps it open. This structure makes static sites dynamic. This technique is called long probe. At the beginning of 2010, as data traffic increased, the connection between the server and the customer became longer and longer.

The following code is dynamically sending data with AJAX. ESP8266 is the server here. Once you have entered the IP address in the web browser, connect to the client when you are connected. In C ++, writing HTML as a string is really simple and very simple.

But there is something here that should not be forgotten. ESP8266 should send TCP packets in one step. ESP8266 packages not found. If you send a long packet, ESP should send it without looking at its length. If the size of the TCP packets is long, ESP8266 is killed. It can be reset. Instead of using html and css to fix this, design with Javascript as much as possible.

Long polling in communication with Ajax generates traffic for wifi. In this case it is not good for ESP8266. We will solve this problem with WebSocket technology. Websocker is a full duplex protocol and does not send data over long polls, such as ajax. Toggles connection data connection on / off. Thus traffic is reduced. The following code is an example written with WebSocket technology.

Video for the websocket will be added. Here is the thing, do not use pure html and css to desing the website, use javascript which saves more lines that means less traffic. It saves the time for your esp8266. 03/06/2018..