Esp8266 WebServer using STM32 HAL
I already covered How to manage multiple UARTs using ring buffer in STM32. You must have a knowledge of that, if you want to understand this one. Better take a look at that tutorial first.
Today, in this tutorial, we will use the ring buffer to manage a Esp8266 Webserver using STM32 HAL library. Basically, we will blink a LED using WiFi, by creating a webserver.
Below is the CubeMX setup. Two UARTs are being used. One is connected to the ESP8266, and another is connected to the computer.
Below is the connection between the ESP8266 and the STM32.
Let’s see some of the functions, that we are going to use
ESP_Init (“SSID”, “PASSWD”) Initialises the ESP8266. Its parameter are the SSID and PASSWD of the Access point that you want to connect to. This function sends some AT commands in a sequence, and than waits for the expected response after every command. These commands are given below
- AT –> to check if the ESP is responding
- AT+CWMODE=1 –> to set the ESP into the station mode
- AT+CWJAP=”SSID”, “PASSWD” –> Join the access point with the SSID, and PASSWD
- AT+CIFSR –> Queries for the IP address of the ESP
- AT+CIPMUX=1 –> Set the multiple connection as TRUE
- AT+CIPSERVER=1,80 –> Starts a server at port 80
All the above information can be seen on the Serial console. Once the ESP gets the IP address, it will also be printed on the console as shown below
Next, we will connect to this IP address, but make sure the device and the ESP should be connected to the same network.
Server_Start() checks the incoming connection, and look for the request made by the browser. If the request is about ledon, or ledoff, or the root. Once identified, it will call the Server_Handle to handle that request
If the request is made for the root, or ledoff the following will be displayed on the browser
Note that the LED on board is OFF right now. There is a option displayed on the web browser to turn this LED ON.
If we tap this ON button, a ledon request will be sent to the ESP, and the Server_Start will call Server_Hnadle to handle this ledon request.
Now the LED is ON, and there is a OFF button to turn it OFF.
The web page source code is divided into 3 categories
- Initial part, where the basic stuff will load
- Button and Status part, which will depend on what request is being processed
- Ending part, which will close the tags
To make this entire thing work, all you have to do is as shown below
In case you are using a microcontroller, which gave you error on Uart_isr function. Errors like DR and SR are not present, replace the Uart_isr code with the following file Uart_isr.c
- STM32 Ethernet #10 HTTP Server (Basic) using LWIP NETCONN (RTOS) May 18, 2022
- STM32 Ethernet #9 TCP Server and Client using LWIP NETCONN (RTOS) April 26, 2022
- STM32 Ethernet #8 UDP Client using LWIP NETCONN (RTOS) April 16, 2022
- STM32 Ethernet #7 UDP Server using LWIP NETCONN (RTOS) April 9, 2022
- GPS (Neo 6M) with STM32 March 9, 2022
- BME280 with STM32 January 8, 2022