Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created March 19, 2017 14:19
Show Gist options
  • Save maxpromer/6b2e840fb543eb3d81633af1a31bfdbb to your computer and use it in GitHub Desktop.
Save maxpromer/6b2e840fb543eb3d81633af1a31bfdbb to your computer and use it in GitHub Desktop.
// 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