Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServer.h>
- #include <Servo.h>
- // WiFi network
- Servo servo;
- const char* ssid = "xxxxx";
- const char* password = "xxxxx";
- ESP8266WebServer server ( 80 );
- char htmlResponse[3000];
- String inputString = ""; // a String to hold incoming data
- bool stringComplete = false; // whether the string is complete
- void handleRoot() {
- snprintf ( htmlResponse, 3000,
- "<!DOCTYPE html>\
- <html lang=\"en\">\
- <head>\
- <style>\
- body {background-color: rgb(160, 0, 53);}\
- h3 {color: white;text-align:center;}\
- p {color: white; text-align:center;}\
- div {color: white; text-align:center;}\
- ID {text-align:center;}\
- input {text-align:center;}\
- </style>\
- <meta charset=\"utf-8\">\
- <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
- </head>\
- <body>\
- <h3>\<canter>Electropeak Smart Security Door</canter>\</h3>\
- <p>\<canter>Please type your ID</canter>\</p>\
- <div>ID: <input type='text' name='pass_word' id='pass_word' align='center' size=10 autofocus></div> \
- <div>\
- <br><button id=\"save_button\">Log In</button>\
- </div>\
- <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\
- <script>\
- var pass;\
- $('#save_button').click(function(e){\
- e.preventDefault();\
- pass = $('#pass_word').val();\
- $.get('/save?pass=' + pass, function(data){\
- console.log(data);\
- });\
- });\
- </script>\
- </body>\
- </html>");
- server.send ( 200, "text/html", htmlResponse );
- }
- void handleSave() {
- if (server.arg("pass")!= ""){
- Serial.println(server.arg("pass"));
- }
- }
- void setup() {
- // Start serial
- Serial.begin(115200);
- delay(10);
- servo.attach(15); //D8
- servo.write(0);
- // Connecting to a 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");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- server.on ( "/", handleRoot );
- server.on ("/save", handleSave);
- server.begin();
- Serial.println ( "HTTP server started" );
- // Serial.begin(9600);
- // reserve 200 bytes for the inputString:
- // inputString.reserve(200);
- //servomotormove
- // pinMode(9,OUTPUT);
- }
- void loop() {
- server.handleClient();
- if (stringComplete) {
- if (inputString=="123")
- {
- //digitalWrite(9,HIGH);
- // delay(300);
- // digitalWrite(9,LOW);
- // Serial.println(inputString);
- servo.write(90);
- delay(300);
- servo.write(0);
- // clear the string:
- inputString = "";
- stringComplete = false;
- }
- }
- }
- void serialEvent() {
- while (Serial.available()) {
- // get the new byte:
- char inChar = (char)Serial.read();
- // add it to the inputString:
- inputString += inChar;
- // if the incoming character is a newline, set a flag so the main loop can
- // do something about it:
- if (inChar == '\n') {
- stringComplete = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement