// Wemos d1 mini : LED control from Web  

#include 
#define LED 16  // LED at D0

const char* ssid = "your ssid";
const char* password = "your password";


WiFiServer server(80);

void setup() {
 Serial.begin(115200);
 pinMode(LED, OUTPUT);
 digitalWrite(LED, LOW);

 Serial.println();
 Serial.println();
 Serial.print("Connecting to "); // Wi-Fi network
 Serial.println(ssid);

 WiFi.begin(ssid, password);

 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println("");
 Serial.println("WiFi connected");

 // Start the server
 server.begin();
 Serial.println("Server started at...");
 Serial.println(WiFi.localIP()); 

}  // == end of setup() ==

void loop() {

 // Check if a client has connected
 WiFiClient client = server.available();
 if (!client) {
   return;
 }

 // Wait until the client sends some data
 Serial.println("new client");
 while (! client.available()) {
   delay (1);
 }
  
 // Read the first line of the request
 String req = client.readStringUntil('\r');
 Serial.println(req);  


 // Match the request 
  if (req.indexOf("/ledoff") >0)  {   
       
   digitalWrite(LED, LOW);
   Serial.println("LED OFF");
 }
 else if(req.indexOf("/ledon") >0) {  

   digitalWrite(LED,HIGH);
   Serial.println("LED ON");
 }

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println(""); 

client.println("<!DOCTYPE HTML>");
client.println("<HTML>");
client.println("<H1> LED CONTROL </H1>");
client.println("<br />");

client.println("<a href=\"/ledon\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px;WIDTH: 300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED ON </button> </a>");
client.println("<a href=\"/ledoff\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px; WIDTH: 300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED OFF </button> </a>");
client.println("</html>");

 delay(1);
 Serial.println("Client disonnected");
 Serial.println("");

} //==== end of loop() =======