#include <WiFi.h>
#include <WebServer.h>
// WiFi credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Create web server on port 80
WebServer server(80);
// HTML webpage
String webpage = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<title>ESP32 Web Server</title>
</head>
<body>
<h1>Welcome to ESP32 Web Server</h1>
<p>IoT Practical using ESP32</p>
<p>Server Running Successfully</p>
</body>
</html>
)rawliteral";
// Function for homepage
void handleRoot() {
server.send(200, "text/html", webpage);
}
void setup() {
Serial.begin(115200);
// Connect WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected");
// Print IP address
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Homepage route
server.on("/", handleRoot);
// Start server
server.begin();
Serial.println("Web Server Started");
}
void loop() {
// Handle browser requests
server.handleClient();
}