#include #include // Connect to ESP32 via browser after connecting to the same WiFi // Try: http:///status const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; WebServer server(80); // Start webserver on port 80 const int ledPin = 2; void flashLED() { // to signal ESP32 is receiving a request digitalWrite(ledPin, HIGH); // Turn LED on delay(100); // Wait 100ms digitalWrite(ledPin, LOW); // Turn LED off } void handleStatus() { // sample call to check it's working flashLED(); String response = "ESP32 is alive and connected. "; server.send(200, "text/plain", response); } void handleHTTP() { // handles invalid requests flashLED(); String path = server.uri(); String message = "Not a valid call for " + path; server.send(404, "text/plain", message); } void setup() { Serial.begin(115200); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { flashLED(); // flash while connecting delay(500); Serial.print("."); } Serial.println("\nConnected to WiFi."); Serial.print("ESP32 IP address: "); Serial.println(WiFi.localIP()); // processes must be defined first - case sensitive parameters server.on("/status", handleStatus); // Restful api call - http://192.168.1.123/status server.onNotFound(handleHTTP); // Catch all others server.begin(); } void loop() { server.handleClient(); // Must be called regularly }