#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "Wokwi-GUEST"; // Wokwi provides this simulated Wi-Fi
const char* password = "";
const int ledPin = 26;
WebServer server(80);
void handleRoot() {
String html = R"rawliteral(
<html>
<head><title>LED Control</title></head>
<body>
<h1>LED Control</h1>
<p><a href="/on"><button>Turn ON</button></a></p>
<p><a href="/off"><button>Turn OFF</button></a></p>
</body>
</html>
)rawliteral";
server.send(200, "text/html", html);
}
void handleOn() {
digitalWrite(ledPin, HIGH);
server.send(200, "text/html", "<p>LED is ON</p><a href='/'>Go Back</a>");
}
void handleOff() {
digitalWrite(ledPin, LOW);
server.send(200, "text/html", "<p>LED is OFF</p><a href='/'>Go Back</a>");
}
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected. IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/on", handleOn);
server.on("/off", handleOff);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}