Advertisement
nedfire

NEW_espmotor4 old

Jul 3rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <ESP8266WiFi.h>
  3.  
  4.  
  5.  
  6. //const char* ssid = "....";
  7. //const char* password = "trashbin";
  8. //const char* ssid = "TP-Link_DB6F";
  9. // const char* password = "akupunya";
  10. const char* ssid = "maidiee1234@unifi";// change to your wifi name between double quote
  11. const char* password = "napsiah1";// change to your wifi password between double quote
  12. Servo myservo; // create servo object to control a servo
  13. int pos = 0; // variable to store the servo position
  14.  
  15.  
  16. WiFiServer server(80);
  17.  
  18. void setup() {
  19. Serial.begin(115200);
  20. // Connect to WiFi network
  21. Serial.println();
  22. Serial.println();
  23. Serial.print("Connecting to ");
  24. Serial.println(ssid);
  25.  
  26. WiFi.begin(ssid, password);
  27.  
  28. while (WiFi.status() != WL_CONNECTED) {
  29. delay(500);
  30. Serial.print(".");
  31. }
  32. Serial.println("");
  33. Serial.println("WiFi connected");
  34.  
  35. // Start the server
  36. server.begin();
  37. Serial.println("Server started");
  38.  
  39. // Print the IP address
  40. Serial.print("Use this URL to connect: ");
  41. Serial.print("http://");
  42. Serial.print(WiFi.localIP());
  43. Serial.println("/");
  44. myservo.attach(D8); // attaches the servo on pin D8 to the servo object
  45. }
  46.  
  47. void loop() {
  48. // Check if a client has connected
  49. WiFiClient client = server.available();
  50. if (!client) {
  51. return;
  52. }
  53.  
  54. // Wait until the client sends some data
  55. //Serial.println("new client");
  56. while(!client.available()){
  57. delay(1);
  58. }
  59.  
  60. // Read the first line of the request
  61. String request = client.readStringUntil('\r');
  62. Serial.println(request);
  63. client.flush();
  64.  
  65. // Match the request
  66.  
  67. int value = LOW;
  68. // if you press open from the screen
  69. if (request.indexOf("gpio12_pin=ON")>0) {
  70. openDoor();
  71. delay(3000);
  72. }
  73. else{
  74. closeDoor();
  75. value = HIGH;
  76. delay(3000);
  77. }
  78.  
  79. // Return the response
  80. client.println("HTTP/1.1 200 OK");
  81. client.println("Content-Type: text/html");
  82. client.println(""); // do not forget this one
  83. client.println("<!DOCTYPE HTML>");
  84. client.println("<html>");
  85. String content = "<body style='background: #80c6f7'><h1 align ='center'><b><u><i><strong>REMOTE DOOR AUTHENTICATION </strong></i></u></b></h1><br><p align ='center'>DOOR<a href=\"/gpio12_pin=ON\"\"><button>OPEN</button></a></p>";
  86. content += "<br><p><marquee direction='right'>Developed by Eng. maximilien www.maxtek.dx.am </marquee></p>";
  87.  
  88. client.print(content);
  89.  
  90. client.println("</html>");
  91.  
  92. delay(1);
  93. Serial.println("Client disonnected");
  94. Serial.println("");
  95.  
  96. }
  97. //function to initialize the lcd and display waiting for initialization and command
  98. void openDoor() {
  99. for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
  100. // in steps of 1 degree
  101. myservo.write(pos); // tell servo to go to position in variable 'pos'
  102. delay(15); // waits 15ms for the servo to reach the position
  103. }
  104.  
  105. }
  106.  
  107. void closeDoor() {
  108. for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
  109. myservo.write(pos); // tell servo to go to position in variable 'pos'
  110. delay(15); // waits 15ms for the servo to reach the position
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement