#include #include #include #include MDNSResponder mdns; const char* ssid = "xxx"; const char* password = "xxx"; ESP8266WebServer server(80); int ledState = 0; void setup(){ delay(1000); Serial.begin(9600); pinMode(D0, OUTPUT); digitalWrite(D0, LOW); Serial.println(); Serial.print("Pripojuji k "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.println("WiFi pripojena!"); Serial.print("Pouzij k pripojeni tuto adresu: "); Serial.print("http://"); Serial.println(WiFi.localIP()); if (mdns.begin("esp8266", WiFi.localIP())) { Serial.println("MDNS responder started"); } server.on("/", [](){ server.send(200, "text/html", returnWebPage(ledStateInfo(ledState))); }); server.on("/ZapnoutSvetlo", [](){ ledState = 1; server.send(200, "text/html", returnWebPage(ledStateInfo(ledState))); digitalWrite(D0, HIGH); }); server.on("/VypnoutSvetlo", [](){ ledState = 0; server.send(200, "text/html", returnWebPage(ledStateInfo(ledState))); digitalWrite(D0, LOW); }); server.begin(); Serial.println("HTTP server spusten"); } void loop() { server.handleClient(); } String returnWebPage(String message) { String webPage; webPage += ""; webPage += ""; webPage += ""; webPage += "ESP8266 WebServer"; webPage += ""; webPage += ""; webPage += ""; webPage += ""; webPage += ""; webPage += "
"; webPage += "

Wi-Fi LED

"; webPage += "
"; webPage += "
"; webPage += "
"; webPage += "
"; webPage += "

Stav

"; webPage += "
"; webPage += "
"; webPage += message; webPage += "
"; webPage += "
"; webPage += "
"; webPage += "
"; webPage += "ZAPNOUT"; webPage += "
"; webPage += "
"; webPage += "VYPNOUT"; webPage += "
"; webPage += "
"; webPage += "
"; webPage += "
"; webPage += "
"; webPage += ""; webPage += ""; return webPage; } String ledStateInfo(int state) { if (state == 0) { return "VYPNUTO"; } else { return "ZAPNUTO"; } }