shell$ git clone https://github.com/nodemcu/nodemcu-flasher.git
Vyplnit e-mail, kam přijdou odkazy ke stažení buildu NodeMCU. Dále vybrat moduly, které chceme mít ve zkompilovaném balíčku a potvrdit.
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> 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 += "<!DOCTYPE html>"; webPage += "<html>"; webPage += "<head>"; webPage += "<title>ESP8266 WebServer</title>"; webPage += "<meta charset=\"UTF-8\">"; webPage += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"; webPage += "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\">"; webPage += "</head>"; webPage += "<body>"; webPage += "<div class=\"container\">"; webPage += "<h1 class=\"h3 text-center\">Wi-Fi LED</h1>"; webPage += "<div class=\"row\">"; webPage += "<div class=\"col-md-offset-4 col-md-4\">"; webPage += "<div class=\"panel panel-default\">"; webPage += "<div class=\"panel-heading\">"; webPage += "<h3 class=\"panel-title\">Stav</h3>"; webPage += "</div>"; webPage += "<div class=\"panel-body text-center\">"; webPage += message; webPage += "</div>"; webPage += "</div>"; webPage += "<div class=\"row\">"; webPage += "<div class=\"col-xs-6\">"; webPage += "<a class=\"btn btn-success btn-block\" href=\"/ZapnoutSvetlo\">ZAPNOUT</a>"; webPage += "</div>"; webPage += "<div class=\"col-xs-6\">"; webPage += "<a class=\"btn btn-danger btn-block\" href=\"/VypnoutSvetlo\">VYPNOUT</a>"; webPage += "</div>"; webPage += "</div>"; webPage += "</div>"; webPage += "</div>"; webPage += "</div>"; webPage += "</body>"; webPage += "</html>"; return webPage; } String ledStateInfo(int state) { if (state == 0) { return "VYPNUTO"; } else { return "ZAPNUTO"; } }