Advertisement
nedfire

HTMLMOTOR

Apr 14th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266WebServer.h>
  3. #include <Servo.h>
  4. // WiFi network
  5. Servo servo;
  6. const char* ssid = "xxxxx";
  7. const char* password = "xxxxx";
  8. ESP8266WebServer server ( 80 );
  9. char htmlResponse[3000];
  10. String inputString = ""; // a String to hold incoming data
  11. bool stringComplete = false; // whether the string is complete
  12. void handleRoot() {
  13. snprintf ( htmlResponse, 3000,
  14. "<!DOCTYPE html>\
  15. <html lang=\"en\">\
  16. <head>\
  17. <style>\
  18. body {background-color: rgb(160, 0, 53);}\
  19. h3 {color: white;text-align:center;}\
  20. p {color: white; text-align:center;}\
  21. div {color: white; text-align:center;}\
  22. ID {text-align:center;}\
  23. input {text-align:center;}\
  24. </style>\
  25. <meta charset=\"utf-8\">\
  26. <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
  27. </head>\
  28. <body>\
  29. <h3>\<canter>Electropeak Smart Security Door</canter>\</h3>\
  30. <p>\<canter>Please type your ID</canter>\</p>\
  31. <div>ID: <input type='text' name='pass_word' id='pass_word' align='center' size=10 autofocus></div> \
  32. <div>\
  33. <br><button id=\"save_button\">Log In</button>\
  34. </div>\
  35. <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\
  36. <script>\
  37. var pass;\
  38. $('#save_button').click(function(e){\
  39. e.preventDefault();\
  40. pass = $('#pass_word').val();\
  41. $.get('/save?pass=' + pass, function(data){\
  42. console.log(data);\
  43. });\
  44. });\
  45. </script>\
  46. </body>\
  47. </html>");
  48. server.send ( 200, "text/html", htmlResponse );
  49. }
  50. void handleSave() {
  51. if (server.arg("pass")!= ""){
  52. Serial.println(server.arg("pass"));
  53. }
  54. }
  55. void setup() {
  56. // Start serial
  57. Serial.begin(115200);
  58. delay(10);
  59.  
  60. servo.attach(15); //D8
  61. servo.write(0);
  62. // Connecting to a WiFi network
  63. Serial.println();
  64. Serial.println();
  65. Serial.print("Connecting to ");
  66. Serial.println(ssid);
  67. WiFi.begin(ssid, password);
  68. while (WiFi.status() != WL_CONNECTED) {
  69. delay(500);
  70. Serial.print(".");
  71. }
  72. Serial.println("");
  73. Serial.println("WiFi connected");
  74. Serial.println("IP address: ");
  75. Serial.println(WiFi.localIP());
  76. server.on ( "/", handleRoot );
  77. server.on ("/save", handleSave);
  78. server.begin();
  79. Serial.println ( "HTTP server started" );
  80.  
  81. // Serial.begin(9600);
  82. // reserve 200 bytes for the inputString:
  83. // inputString.reserve(200);
  84. //servomotormove
  85. // pinMode(9,OUTPUT);
  86. }
  87. void loop() {
  88. server.handleClient();
  89. if (stringComplete) {
  90. if (inputString=="123")
  91. {
  92. //digitalWrite(9,HIGH);
  93. // delay(300);
  94. // digitalWrite(9,LOW);
  95. // Serial.println(inputString);
  96. servo.write(90);
  97. delay(300);
  98. servo.write(0);
  99. // clear the string:
  100. inputString = "";
  101. stringComplete = false;
  102. }
  103. }
  104. }
  105.  
  106.  
  107. void serialEvent() {
  108. while (Serial.available()) {
  109. // get the new byte:
  110. char inChar = (char)Serial.read();
  111. // add it to the inputString:
  112. inputString += inChar;
  113. // if the incoming character is a newline, set a flag so the main loop can
  114. // do something about it:
  115. if (inChar == '\n') {
  116. stringComplete = true;
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement