Unit A · On the network
What we are making: a web page, served by your board, showing a live sensor reading. You open it on your phone. Nothing is plugged into your phone.
A web server sounds enormous. It is not. It is a program that waits for somebody to ask for a page, and sends back some text. The text happens to be HTML, which the phone knows how to draw.
Your board has enough memory to do this comfortably. Every WiFi router, every printer, every smart plug in the building does exactly this and nothing more.
What you are building today. Yes, really — that is served by the board.
Any analogue sensor. We will use the ultrasonic from Level 2, but a light sensor or a potentiometer works just as well for today.
Two resistors and nothing else. They split the 5V coming back from Echo so the ESP32 sees about 3.3V — exactly what it can handle, and not a volt more.
Longer than anything in Level 2. Read it in three parts: the sensor, the page, the server.
pulseIn with a timeout. Without that third number, a sensor that never answers freezes your whole program forever. This is the first piece of surviving-in-the-field code you have written.-1 for 'no reading' instead of a wrong number. You will thank yourself in Session 6.refresh content='2' tells the phone to reload every 2 seconds. It is a cheap trick and it is how your page appears live./, run handleRoot”. That is the entire routing system.String with + is how you glue text and numbers together. It is convenient and slightly wasteful. On a board this size, convenient wins.| What you see | Why | What to do |
|---|---|---|
| Phone leaves the network by itself | It hunts for internet. | Turn off 'auto-switch to mobile data' for that network. |
| Page loads once then stops | loop() is blocked. | Look for a delay() you added. |
| Shows -1 constantly | Sensor not answering. | Check Trig/Echo not swapped, and the divider. |
| Browser searches instead of loading | You typed it into the search box. | Use the address bar. Add http:// if it helps. |
Unplug the sensor while the page is open. The number becomes −1 and stays on the page. Your page is now confidently displaying a fake value. Remember that feeling — Session 6 is about it.
In this session