Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <ESP8266WiFi.h>
- //const char* ssid = "....";
- //const char* password = "trashbin";
- //const char* ssid = "TP-Link_DB6F";
- // const char* password = "akupunya";
- const char* ssid = "maidiee1234@unifi";// change to your wifi name between double quote
- const char* password = "napsiah1";// change to your wifi password between double quote
- Servo myservo; // create servo object to control a servo
- int pos = 0; // variable to store the servo position
- WiFiServer server(80);
- void setup() {
- Serial.begin(115200);
- // 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");
- // Print the IP address
- Serial.print("Use this URL to connect: ");
- Serial.print("http://");
- Serial.print(WiFi.localIP());
- Serial.println("/");
- myservo.attach(D8); // attaches the servo on pin D8 to the servo object
- }
- 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 you press open from the screen
- if (request.indexOf("gpio12_pin=ON")>0) {
- openDoor();
- delay(3000);
- }
- else{
- closeDoor();
- value = HIGH;
- delay(3000);
- }
- // Return the response
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println(""); // do not forget this one
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- 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>";
- content += "<br><p><marquee direction='right'>Developed by Eng. maximilien www.maxtek.dx.am </marquee></p>";
- client.print(content);
- client.println("</html>");
- delay(1);
- Serial.println("Client disonnected");
- Serial.println("");
- }
- //function to initialize the lcd and display waiting for initialization and command
- void openDoor() {
- for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
- // in steps of 1 degree
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }
- void closeDoor() {
- for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement