I've written a couple intro tutorials in french (Les Bases d'un Serveur Web sur ESP-01 en commande AT and Techniques "avancées" de serveur web sur ESP8266). May be google translate can help you read those.
I think there are important things to understand before diving into a web code though:
If I want to be simplistic, the way it works could be described as follow:
-
The client (basically a web browser) opens a connexion to the server and sends a request using the HTTP protocol (basically you type a URL to get things started)
-
the server analyzes the request and sends an answer in the form of a document using a normalized description language (basically HTML, CSS, Javascript).
-
the client interprets the document description and paints the screen / acts accordingly
At that stage the connexion is usually closed. The request has been handled. There is no more link between the client and the server.
Going back to the server means you do that cycle again: the client contacts the server over HTTP and requests a new document.
Where the magic happens is that:
-
In the page description language you have specific capabilities (basically forms with textfield, checkbox, buttons, ...) to describe an interactive User Interface and what happens if the user on the client triggers an action (basically this is a request for a new document from the server and some data from the web browser will be sent to the server).
-
the HTTP protocol describes various Request Methods and the two most common are GET and POST. In particular they describe how the data (status of your check box, content of a textfield, ...) is encoded within the Request Method.
-
The server recognizes the Request Method being used, decodes the parameters and takes action to build a new document that is sent back to the client
-
the connexion is closed and the cycle can start over again.
There is one more thing:
- In the page description language You also have the capability to provide some code written using a programming language (Javascript) that is interpreted by the client.
- The programming language can affect how things are painted over the screen
- One specific possibility is also to trigger an HTTP request and get an answer: a frequently used technic is called AJAX. With AJAX you can read data from a web server after the page has loaded, you can update a web page without reloading the page and you can send data to a web server - in the background.
Libraries such as ESPAsyncWebServer makes it easy to set up a server ready to handle any form of Request Methods. The library will help you unpack the parameters and provide various ways of sending the document answer back to the client (dealing with the necessary protocol information so that you can only focus on the description).
Once you've said this, it becomes evident that you won't do anything relevant if you don't invest a bit of time in understanding the underlying document object model for a web page and HTML, CSS and Javascript because that's fundamentally what drives the interaction. If you can't write the document then you can't prime that pump.
➜ It depends on the learner how they want to achieve this.
I started looking at this a long time ago when HTTP was being developed and I followed along all those years, out of curiosity mainly, to stay aware of the new capabilities. So I learnt about the HTTP protocol, then HTML, CSS and about Javascript but at the time I was exploring this, there was no ESP so I did not test anything along the way.
If I had to learn now, that's how I would do it, it suits my learning style (may be not suited for everyone) as
I learn better by understanding all the building blocks and concepts, independently of of each others and then putting things together.
You have tons of training material available on line and you can go as deep as you want on each.
1/ Read a bit about HTTP and play with your ESP to set up a basic server listening on port 80 and see what you get when you type an URL in your favorite web browser
2/ Read a bit about HTML and generate a simple page that you send back to the client. As everything is text, you can play around in your ESP code to dynamically generate HTML (eg send the value you read on A0 for example).
3/ Then read about Javascript and add some auto update capability to your page. Every second you request an update to that page, so you get the page re-painted with the value of A0 every second.
4/ Then keep exploring HTML and forms. Build a page with a form and a submit button and see what you get on your ESP when you click submit.
5/ Then read about the DOM (Document Object Model) and how Javascript can be used to dynamically access/read/write the elements on your web page.
6/ Then Explore AJAX and start playing with it still with your ultra simple ESP listening on port 80.
At that stage you start understanding that extracting information from the request is really about text parsing. Having a good grasp on cStrings functions helps or you can use the String class.
If you got that far, you have accumulated enough experience and understanding on the pieces of the puzzle and that's where Libraries such as ESPAsyncWebServer can come into play to avoid re-inventing the wheel.
Libraries are specific and then you can read tutorials and examples from those libraries. But as you are now equipped with the concepts, you know what's going on in the background and there is no black magic.
My strong belief is that if you lack the foundations, you are building on sand and moving grounds and can't really do something great, you'll be trying all sorts of things and workaround because you don't get what's happening behind the scene. (you can always try to work your way up from sample code but I don't find this satisfying).