Created
October 5, 2025 12:27
-
-
Save michidk/c2b2370fb95021361d1d4d03a31b72a4 to your computer and use it in GitHub Desktop.
Revisions
-
michidk created this gist
Oct 5, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #include <WiFi.h> #include <WebServer.h> #define LED_PIN 2 // Abhaenig vom Board WebServer server(80); const char* SSID = "WiFi Name"; const char* PASSWORD = "passwort123"; void handleRoot() { String html = "<html><body>" "<h1>LED Steuerung</h1>" "<p><a href=\"/on\"><button>LED AN</button></a></p>" "<p><a href=\"/off\"><button>LED AUS</button></a></p>" "</body></html>"; server.send(200, "text/html", html); } void handleOn() { digitalWrite(LED_PIN, HIGH); server.sendHeader("Location", "/"); server.send(303); // Redirect zurück auf die Startseite } void handleOff() { digitalWrite(LED_PIN, LOW); server.sendHeader("Location", "/"); server.send(303); // Redirect zurück auf die Startseite } void setup() { pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(SSID, PASSWORD); // Warten bis verbunden while (WiFi.status() != WL_CONNECTED) { delay(250); } // Routen registrieren server.on("/", handleRoot); server.on("/on", handleOn); server.on("/off", handleOff); server.begin(); // Optional: IP loggen Serial.print("IP: "); Serial.println(WiFi.localIP()); } void loop() { server.handleClient(); }