-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp8266_gate_press.ino
56 lines (44 loc) · 1.11 KB
/
esp8266_gate_press.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#ifndef STASSID
#define STASSID "SSID_Name"
#define STAPSK "SSID_Password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const int relayPin = D1;
ESP8266WebServer server(80);
void handleGatePress() {
Serial.println("Pressing Gate");
digitalWrite(relayPin, HIGH);
delay(750);
digitalWrite(relayPin, LOW);
server.send(200, "text/plain", "Gate Pressed");
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(relayPin, LOW);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
digitalWrite(LED_BUILTIN, LOW);
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/gate/press", handleGatePress);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}