04 / 20
Use Wi-Fi
A tiny HTTP server lets a virtual phone switch an LED.
Run this experiment →Why it’s here
Connect the simulated network, then tap the phone toggle.
How it works
A tiny HTTP server lets a virtual phone switch an LED. No. Network controls model connection state and HTTP requests locally. The hardware sketch uses WiFi and WebServer. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.
Try it
- Open this experiment
- Connect the simulated network, then tap the phone toggle.
Connections
- 2.4 GHz — Wi-Fi STA + HTTP /toggle
- GPIO 2 — LED through resistor
Example sketch
#include <WiFi.h>
#include <WebServer.h>
WebServer server(80);
bool lightOn = false;
void setup() {
pinMode(2, OUTPUT);
WiFi.begin("YOUR_SSID", "YOUR_PASSWORD");
while (WiFi.status() != WL_CONNECTED) delay(250);
server.on("/", []() { server.send(200, "text/html", "<a href='/toggle'>Toggle LED</a>"); });
server.on("/toggle", []() {
lightOn = !lightOn; digitalWrite(2, lightOn);
server.send(200, "text/plain", lightOn ? "ON" : "OFF");
});
server.begin();
}
void loop() {
server.handleClient();
}Check your understanding
Does this page connect to my home router?
Show the answer
No. Network controls model connection state and HTTP requests locally. The hardware sketch uses WiFi and WebServer.