#include <ESP8266WiFi.h> const char* ssid="Bad Boys " const char* password="876543210" int LOCK=4;//GPI04 d2 WiFiServer server(80); void setup(){ Serial.begin(115200); delay(10); pinMOode(LOCK,OUTPUT); digitalWrite(LOCK, LOW); //connect to WiFi network Serial.println(); 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"); //start the server server.begin(); Serial.println("Server started"); Serial.println(""); Serial.println("************WiFi doorlock********************"); // print the IP address Serial.print("Use this URL to connect"); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/"); } 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 request = client.readstringUntil('\r'); Serial.println(request); //Match the request int value=LOW; if (request.indexOf("/LOCK=ON") != -1) { digitalwrite(LOCK, HIGH); value = LOW; } if (request.indexOf("/LOCK=OFF") != -1) { digitalWrite(LOCK, LOW); value = LOW; } //set LOCK according to the request //digitalWrite(LOCK, value); // Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("802.11b/g/n");//do not forget this one Client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.print("Door is now: "); if(value == HIGH){ client.print("Open"); } else client.print("Closed"); } client.println("<br><br>"); client.println("<a href=\"/LOCK=ON\"\"><button><h1>Turn on</h1> </button></a>"); client.println("<a href=\"/LOCK=OFF\"\"><button><h1>Turn off </h1></button></a><br />"); client.println("</html>"); delay(1); Serial.println("client disconnected"); Serial.println(""); }
Standard input is empty
#include <ESP8266WiFi.h> const char* ssid="Bad Boys " const char* password="876543210" int LOCK=4;//GPI04 d2 WiFiServer server(80); void setup(){ Serial.begin(115200); delay(10); pinMOode(LOCK,OUTPUT); digitalWrite(LOCK, LOW); //connect to WiFi network Serial.println(); 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"); //start the server server.begin(); Serial.println("Server started"); Serial.println(""); Serial.println("************WiFi doorlock********************"); // print the IP address Serial.print("Use this URL to connect"); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/"); } 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 request = client.readstringUntil('\r'); Serial.println(request); client.flush(); //Match the request int value=LOW; if (request.indexOf("/LOCK=ON") != -1) { digitalwrite(LOCK, HIGH); value = LOW; } if (request.indexOf("/LOCK=OFF") != -1) { digitalWrite(LOCK, LOW); value = LOW; } //set LOCK according to the request //digitalWrite(LOCK, value); // Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("802.11b/g/n");//do not forget this one Client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.print("Door is now: "); if(value == HIGH){ client.print("Open"); } else client.print("Closed"); } client.println("<br><br>"); client.println("<a href=\"/LOCK=ON\"\"><button><h1>Turn on</h1> </button></a>"); client.println("<a href=\"/LOCK=OFF\"\"><button><h1>Turn off </h1></button></a><br />"); client.println("</html>"); delay(1); Serial.println("client disconnected"); Serial.println(""); }