Dear friends welcome to another ESP32 video tutorial! In this video, we are going to build a simple ESP32 Web Server! We are also going to learn how to make some requests to it using a web browser. There is a lot to cover, so let’s get started!
Intro to the ESP32 Web Server Tutorial
Hello, guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics projects. In this channel, I share everything about the projects I build to help you develop similar projects or inspire you to start making things because it is easy, fun and creative. Subscribe to the channel now if you do not want to miss any future video.
Today’s project is this. An easy to build ESP32 Web Server. If we open a Web Browser and make a request to the IP address of the ESP32, an HTML page will be loaded with the readings we get from the BME280 sensor. The values are updated once every minute. The BME280 sensor can measure the temperature, the humidity, and the barometric pressure and it communicates with the ESP32 using the I2C interface. Check the ESP32 Weather Station project for more information. The HTML page also enables us to control the state of an LED which is connected to the ESP32 board. We can set the state of the LED here and when we press the Submit button the state of the LED changes. How cool is that! In my opinion, this is a very useful functionality that it will enable us to build some very interesting projects in the future! Let’s now see how to build this project.
——————–
WHERE TO BUY
——————–
ESP32: https://educ8s.tv/part/ESP32
BME280: https://educ8s.tv/part/BME280
100Ω Resistor: https://educ8s.tv/part/Resistors
LED: https://educ8s.tv/part/LEDs
Small Breadboard: https://educ8s.tv/part/SmallBreadboard
Wires: https://educ8s.tv/part/Wires
Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!
[adsense]
The total cost of the project is around 10$. You can find links to all the parts I use in the description of the video below. You can also use an ESP8266 if you wish but you will have to make some changes to the code of the project.
If you are not familiar with it, the ESP32 is a new WiFi-enabled chip that just hit the market. It offers everything a maker wants, like WiFi, Bluetooth, two processing cores and a large amount of memory with a cost of around 7$.
Schematic Diagram of the ESP32 Web Server Project
I have connected the BME280 sensor to pins 26 and 27 of the ESP32 board, and the LED to digital pin 32 according to this schematic diagram. You can find a link to the schematic diagram in the description of the video below. As you can see the connection is extremely easy. Now, all we have to do is to load the code. If you have a problem uploading the code to the board try pressing the Boot button after pressing the upload button on the Arduino IDE. After the uploading procedure is complete, open the serial monitor and write down the local IP address of the ESP32 server. Now, if we open up any web browser and type in this IP address of the server, the server will create an HTML page with the values from the sensor and two radio buttons that control the state of the LED. We can turn the LED ON or OFF by selecting a state and pressing the Submit button! Our ESP32 web server works fine! Let’s now see the software side of the project.
——————–
LIBRARIES
——————–
? ESP32 BME280: https://github.com/Takatsuki0204/BME280-I2C-ESP32
? Web Server: https://github.com/bbx10/WebServer_tng
In order the code to compile we need to download two libraries. We need a library for the sensor and the WebServer library. The WebServer library for the ESP32 is not ready yet, so I am going to use a port of the ESP8266 WebServer library for the ESP32 which works fine. This library provides some very useful methods that will help us set up the server and handle incoming HTTP requests without needing to worry about low-level implementation details. You can find links to all the libraries in the description of the video below.
At first, we create a WebServer object, and we will pass the port where the server will be listening to. Since 80 is the default port for HTTP, we will use this value. Next, we initialize the sensor, we connect to the wifi network, and after this, we start the server.
In the beginServer function, we define a handling function for a request to the server. So, if we receive a request to the root path, it will trigger the execution of the handleRoot function. If the request does not contain any arguments, the server will reply with an OK message, and it will load the HTML page with values from the sensor. If the request to the server contains the LED argument, it will trigger the handleSubmit function.
This function retrieves the value of the LED variable and sets the state of the LED which is connected to the ESP32 board. Finally, it updates the HTML page.
Finally, to handle the actual incoming requests, we need to call the handleClient method on the server object in the main loop function. Please study the code and experiment with it to better understand it. Only by building this project and by experimenting with it you are going to understand exactly how it works. You can easily modify this code if you wish to satisfy your needs and handle many more requests. As always you can find the code of the project in a link in the video description.
——————–
CODE & SCHEMATICS
——————–
——————–
SUBSCRIBE ON YOUTUBE
——————–
Never miss a video: Subscribe to educ8s.tv
Hello, I tried loading the “WebServer_tng-master” library, but the Arduino IDE returns this error: Arduino \ libraries \ WebServer_tng-master \ src / WebServer.h: 27: 22: fatal error: functional: No such file or directory.
I tried in all the ways but nothing, is there anyone who can help me?
Thanks and compliments for the great channel.
Rename the folder to “WebServer_tng”
Hi Sir, my name is Roy Tan ?. Many thanks for the hard work of this esp8266 wifi project?, i have do a modification in your circuit hardward and programming?. I have change the temperature sensor to DS18B20, and the output LED i have change it to a 5Vdc relay. It work too? haha…thanks you Sir
Im from Singapore? and im a Singaporean Chinese, i also a electronic engineer (R&D). I love electronics and programming???
Hi Nic
Downloaded your code for the ‘simple data logger’ using Arduino 1.6.7. it refuses to load on this line:- DS3231_set_creg (DS3231_INTCH | DS3231_A21E);
saying ‘DS3231_INTCH ‘ was not declared in this scope@ any ideas what is wrong??
alan
I’m using a ESP32 board, Heltec esp32 lora, and changed the IIC SDA, and SCK pin to 4 and 15,
Adafruit_BME280 bme(4,15); //I2C for heltec esp32 lora
the code complied with error:
no matching function for call to ‘Adafruit_BME280::Adafruit_BME280(int, int)’
any idea about the error?
Sorry, My bad, I did not notice that the adafruit BME280 in this code, is a modified version….it works…!!
Cool! I am glad that it now works! Cheers!
j’utilise l’esp32 aussi mais la température n’apparaisse sur la page web elle s’affiche sur le moniteur série avec l’adresse ip .pouvez vous m’aider svp
Really nice tutorial! Thank you! I started off learning esp32 with this example. I am curious whether theres a way to send javascript or css as well, along with the html page. Could this be implemented in code with arduino IDE?
You mention code modifications to allow it to function on esp8266, what changes are needed?
compiles ok. but does not print the IP address, I guess its not connecting to my router.
No errors and uploads ok. any help please
John
In the text it says, we are going to build a simple ESP32 Web Server!
When I compiled the code it took over 50% of the code space, a whopping 705 kilobytes!!!!
And this was a simple demo! If the code is so space hogging, there will not be any space or some real code, not just a demo! And this code is not even a connection to internet, just to a wifi router.
Hello Jerry, the implementation of the Wifi libraries take a lot of space. If you need more program space, change the partition of your ESP32 program space to gain more available space. Cheers!
Hi thanks for the sketch.
Can you please provide more info on the arduino ide config?
because I don’t get any output from the serial monitor:
Sketch uses 605486 bytes (17%) of program storage space. Maximum is 3407872 bytes.
Global variables use 40496 bytes (13%) of dynamic memory, leaving 254416 bytes for local variables. Maximum is 294912 bytes.
esptool.py v2.1
Connecting….
Chip is ESP32D0WDQ6 (revision (unknown 0xa))
Uploading stub…
Running stub…
Stub running…
Configuring flash size…
Auto-detected Flash size: 4MB
Compressed 8192 bytes to 47…
Writing at 0x0000e000… (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 5041.2 kbit/s)…
Hash of data verified.
Compressed 14128 bytes to 9196…
Writing at 0x00001000… (100 %)
Wrote 14128 bytes (9196 compressed) at 0x00001000 in 0.8 seconds (effective 137.8 kbit/s)…
Hash of data verified.
Compressed 606640 bytes to 344757…
Writing at 0x00010000… (4 %)
Writing at 0x00014000… (9 %)
Writing at 0x00018000… (13 %)
Writing at 0x0001c000… (18 %)
Writing at 0x00020000… (22 %)
Writing at 0x00024000… (27 %)
Writing at 0x00028000… (31 %)
Writing at 0x0002c000… (36 %)
Writing at 0x00030000… (40 %)
Writing at 0x00034000… (45 %)
Writing at 0x00038000… (50 %)
Writing at 0x0003c000… (54 %)
Writing at 0x00040000… (59 %)
Writing at 0x00044000… (63 %)
Writing at 0x00048000… (68 %)
Writing at 0x0004c000… (72 %)
Writing at 0x00050000… (77 %)
Writing at 0x00054000… (81 %)
Writing at 0x00058000… (86 %)
Writing at 0x0005c000… (90 %)
Writing at 0x00060000… (95 %)
Writing at 0x00064000… (100 %)
Wrote 606640 bytes (344757 compressed) at 0x00010000 in 30.5 seconds (effective 159.0 kbit/s)…
Hash of data verified.
Compressed 3072 bytes to 112…
Writing at 0x00008000… (100 %)
Wrote 3072 bytes (112 compressed) at 0x00008000 in 0.0 seconds (effective 1293.5 kbit/s)…
Hash of data verified.
Leaving…
Hard resetting…
Hello, thank you for sharing the sketch.
I’ve gott following errors:
ESP32_Web_Server:30:37: error: invalid conversion from ‘int’ to ‘SPIClass*’ [-fpermissive]
Adafruit_BME280 bme(I2C_SDA, I2C_SCL);
^
In file included from C:\Users\_\AppData\Local\Temp\Temp1_ESP32-Web-Server.zip\ESP32_Web_Server\ESP32_Web_Server.ino:11:0:
C:\Users\_\Documents\Arduino\libraries\Adafruit_BME280_Library/Adafruit_BME280.h:192:3: error: initializing argument 2 of ‘Adafruit_BME280::Adafruit_BME280(int8_t, SPIClass*)’ [-fpermissive]
Adafruit_BME280(int8_t cspin, SPIClass *theSPI = &SPI);
^
C:\Users\_\AppData\Local\Temp\Temp1_ESP32-Web-Server.zip\ESP32_Web_Server\ESP32_Web_Server.ino: In function ‘void connectToWifi()’:
ESP32_Web_Server:58:6: error: ‘class WiFiClass’ has no member named ‘enableSTA’
WiFi.enableSTA(true);
^
ESP32_Web_Server:62:28: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
WiFi.begin(ssid, password);
^
In file included from C:\Users\_\AppData\Local\Temp\Temp1_ESP32-Web-Server.zip\ESP32_Web_Server\ESP32_Web_Server.ino:8:0:
C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:79:9: error: initializing argument 1 of ‘int WiFiClass::begin(char*, const char*)’ [-fpermissive]
int begin(char* ssid, const char *passphrase);
^
Multiple libraries were found for “WiFi.h”
Used: C:\Program
Not used: C:\Users\_\Documents\Arduino\libraries\WiFiNINA
Not used: C:\Users\_\Documents\Arduino\libraries\WiFiEspAT
Multiple libraries were found for “WebServer.h”
Used: C:\Users\_\Documents\Arduino\libraries\WebServer_tng-master
Multiple libraries were found for “ESP8266WiFi.h”
Used: C:\Users\_\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi
Multiple libraries were found for “Adafruit_BME280.h”
Used: C:\Users\_\Documents\Arduino\libraries\Adafruit_BME280_Library
Not used: C:\Users\_\Documents\Arduino\libraries\BME280-I2C-ESP32-master
Multiple libraries were found for “Adafruit_Sensor.h”
Used: C:\Users\_\Documents\Arduino\libraries\Adafruit_Unified_Sensor
Multiple libraries were found for “SPI.h”
Used: C:\Users\_\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SPI
Multiple libraries were found for “Wire.h”
Used: C:\Users\_\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire
Using library WiFi at version 1.2.7 in folder: C:\Program Files
Using library WebServer_tng-master at version 1.0 in folder: C:\Users\_\Documents\Arduino\libraries\WebServer_tng-master
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\_\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi
Using library Adafruit_BME280_Library at version 1.0.10 in folder: C:\Users\_\Documents\Arduino\libraries\Adafruit_BME280_Library
Using library Adafruit_Unified_Sensor at version 1.0.3 in folder: C:\Users\_\Documents\Arduino\libraries\Adafruit_Unified_Sensor
Using library SPI at version 1.0 in folder: C:\Users\_\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SPI
Using library Wire at version 1.0 in folder: C:\Users\_\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire
exit status 1
invalid conversion from ‘int’ to ‘SPIClass*’ [-fpermissive]
What should i do?
Kind regards
Jan
This piece of writing will assist the internet visitors for creating new web site or even a weblog from start to end.
can this be done on a esp32 cam ai thinker?
PLEASE
I stay continously in:
while(WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(“.”);
}
Ans¡d I don’t know why.
HELP!