#include <WiFi.h>
#include <WebServer.h>
// Replace with your network credentials
const char* ssid = "Fien";
const char* password = "fienneke";
// Set web server port number to 80
WebServer server(80);
// Variable to store the HTTP request
String header;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Start the server
server.begin();
// Route for root / web page
server.on("/", handleRoot);
Serial.println("HTTP server started");
}
void loop() {
// Listen for client connections
server.handleClient();
}
void handleRoot() {
String html = "<!DOCTYPE html><html><head><title>ESP32 Web Server</title></head><body><h1>Hello from ESP32!</h1></body></html>";
server.send(200, "text/html", html);
}