#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "Wokwi-GUEST"; // Wokwi default Wi-Fi
const char* password = "";
WebServer server(80);
void handleRoot() {
server.send(200, "text/html", "<h1>Hello from ESP32 Smart Home!</h1><p>/onTurn ON</a> | <a hrefn OFF</a></p>");
}
void handleOn() {
digitalWrite(23, HIGH);
server.send(200, "text/html", "<p>Device ON</p>/Back</a>");
}
void handleOff() {
digitalWrite(23, LOW);
server.send(200, "text/html", "<p>Device OFF</p>/Back</a>");
}
void setup() {
Serial.begin(115200);
pinMode(23, OUTPUT);
WiFi.begin(ssid, password);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/on", handleOn);
server.on("/off", handleOff);
server.begin();
}
void loop() {
server.handleClient();
}