Created
March 19, 2017 14:19
-
-
Save maxpromer/6b2e840fb543eb3d81633af1a31bfdbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Coding By IOXhop : www.ioxhop.com | |
#include <Servo.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266mDNS.h> | |
#define UNLOCK_POS 5 | |
#define LOCK_POS 100 | |
const char* ssid = "<YOU WIFI NAME>"; | |
const char* password = "<YOU WIFI PASSWORD>"; | |
Servo myservo; | |
ESP8266WebServer server(80); | |
void setup(void){ | |
myservo.attach(4); | |
myservo.write(UNLOCK_POS); | |
WiFi.mode(WIFI_STA); | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
Serial.println(""); | |
// Wait for connection | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.print("Connected to "); | |
Serial.println(ssid); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
server.on("/", []() { | |
server.send(200, "text/html", "<h1>Hello, world !</h1>"); | |
}); | |
server.on("/lock", []() { | |
myservo.write(LOCK_POS); | |
server.send(200, "text/html", "OK"); | |
}); | |
server.on("/unlock", []() { | |
myservo.write(UNLOCK_POS); | |
server.send(200, "text/html", "OK"); | |
}); | |
server.begin(); | |
} | |
void loop() { | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment