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.
Some Insight into the CODE
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
YOU CAN DOWNLOAD FULL CODE AT THE END OF THIS POST
. . . . . DOWNLOAD . . . . .
You can buy me acontrollerstech
coffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020
- STM32 ADC MULTI CHANNEL WITHOUT DMA December 24, 2020
- Send and Receive data to PC without UART (STM32 USB COM) December 10, 2020
- STM32 GPIO INPUT Configuration December 4, 2020
- STM32 GPIO OUTPUT Config using REGISTERS November 24, 2020