#include <ESP8266WiFi.h>#define LED D0 // use D0 connect to LEDconst char* ssid = "Your SSID"; // SSID is setconst char* password = "Your password"; // Password is set unsigned char status_led=0; // keep status LEDWiFiServer server(80); // set TCP Server Port 80void setup() { Serial.begin(115200); pinMode(LED, OUTPUT); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); server.begin(); //TCP Server started Serial.print("Web Server started at IP "); Serial.println(WiFi.localIP()); //display IP of Web Server Serial.println(""); }void loop() { WiFiClient client = server.available(); if (!client) { //if not Client request then loop agian return; } Serial.println("new client"); while(!client.available()) { delay(1); } String req = client.readStringUntil('\r'); // read string from client until ‘\r’ Serial.println(req); // display stringdata from client at Serial monitor client.flush(); if (req.indexOf("/ledoff") != -1) // check data is "/ledoff" { status_led=0; digitalWrite(LED,LOW); Serial.println("LED OFF"); } else if(req.indexOf("/ledon") != -1) // check data is "/ledon" { status_led=1; digitalWrite(LED,HIGH); Serial.println("LED ON"); }//---------------keep Code HTML in variable "web"--------------------- String web = "<!DOCTYPE html\r\n"; web += "<html>\r\n"; web += "<body>\r\n"; web += "<h1>LED Status</h1>\r\n"; web += "<p>\r\n"; if(status_led==1) web += "LED On\r\n"; else web += "LED Off\r\n"; web += "</p>\r\n"; web += "<p>\r\n"; web += "<a href=\"/ledon\"><button>LED On</button></a>\r\n"; web += "<a href=\"/ledoff\"><button>LED Off</button></a>\r\n"; web += "</p>\r\n"; web += "</body>\r\n"; web += "</html>\r\n"; client.print(web);}