serveur-web.ino
The connected classic: the board serves an HTML page on the local network, two links toggle the LED, and an ADC shows live. No external infrastructure — the server runs inside the board.
Hardware required
A classic ESP32 board (ESP32-WROOM-32 module, dual-core Xtensa 240 MHz, Wi-Fi + Bluetooth) such as a DevKitC / DOIT V1, powered over micro-USB. 2.4 GHz Wi-Fi access (not enterprise WPA3); optional potentiometer on an ADC.
Wiring
LED on GPIO2 through 330 Ω; potentiometer wiper on GPIO34 (input-only, 3.3 V max) between 3.3 V and GND.
How it works
WiFi.begin joins the access point, WebServer registers routes /, /on, /off and handleClient() serves requests as they come. The refresh tag keeps the page live every 5 s. In the Arduino IDE, install the « esp32 » board package, pick « Dev Module », the port, then Upload (hold BOOT if detection fails). GPIO34-39 are input-only; avoid GPIO6-11 and GPIO12.
Going further
Add a password (server.authenticate), or publish the same values to an MQTT broker instead of displaying them.
serveur-web.ino
// Serveur web embarque : page de controle LED GPIO2 + etat analogique.
#include <WiFi.h>
#include <WebServer.h>
const char *SSID = "votre-wifi";
const char *CLE = "votre-cle";
const int LED = 2;
WebServer serveur(80);
void page() {
String h = "<h1>ESP32 locale</h1>"
"<p><a href=on>LED ON</a> | <a href=off>LED OFF</a></p>"
"<p>GPIO34 : " + String(analogRead(34)) + "</p>"
"<meta http-equiv=refresh content=5>";
serveur.send(200, "text/html", h);
}
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, CLE);
while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); }
Serial.printf("\nhttp://%s/\n", WiFi.localIP().toString().c_str());
serveur.on("/", page);
serveur.on("/on", []() { digitalWrite(LED, HIGH); page(); });
serveur.on("/off", []() { digitalWrite(LED, LOW); page(); });
serveur.begin();
}
void loop() { serveur.handleClient(); }