/* Project: ESP8266 ESP-01 module, LEDs webserver Function: Webserver to control two LEDs */ //************************************************************ #include //include library code #include #include //include library code #include //include library code //************************************************************ MDNSResponder mdns; // Replace with your network credentials const char* ssid = "TR-2"; const char* password = "AQW112"; //************************************************************ ESP8266WebServer server(80); String webPage = ""; int gpio0_pin = 0; int gpio2_pin = 2; void setup(void){ webPage += "

ESP8266 ESP-01 Web Server

GPIO 0  

"; webPage += "

GPIO 2  

"; // preparing GPIOs pinMode(gpio0_pin, OUTPUT); digitalWrite(gpio0_pin, LOW); pinMode(gpio2_pin, OUTPUT); digitalWrite(gpio2_pin, LOW); delay(1000);//sets delay for 1 second Serial.begin(115200);//initialize serial communication at 115200 bps WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if (mdns.begin("esp8266", WiFi.localIP())) { Serial.println("MDNS responder started"); } server.on("/", [](){ server.send(200, "text/html", webPage); }); server.on("/socket1On", [](){ server.send(200, "text/html", webPage); digitalWrite(gpio0_pin, HIGH); delay(1000); }); server.on("/socket1Off", [](){ server.send(200, "text/html", webPage); digitalWrite(gpio0_pin, LOW); delay(1000); }); server.on("/socket2On", [](){ server.send(200, "text/html", webPage); digitalWrite(gpio2_pin, HIGH); delay(1000); }); server.on("/socket2Off", [](){ server.send(200, "text/html", webPage); digitalWrite(gpio2_pin, LOW); delay(1000); }); server.begin(); Serial.println("HTTP server started"); } //************************************************************************ void loop(void){ server.handleClient(); }