-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
60 lines (52 loc) · 1.46 KB
/
main.cpp
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
57
58
59
60
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char *ssid = "Your Wifi SSID";
const char *password = "Your Wifi Password";
String serverPath = "https://example.com/door-status"; // <-- replace with your server or server ip
const int relayPin = D5; // does not fire up on startup, other than no specific reason to use d5
const int ledBuiltIn = LED_BUILTIN;
HTTPClient http;
WiFiClientSecure client;
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
pinMode(relayPin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
while (WiFi.status() != WL_CONNECTED)
{
digitalWrite(ledBuiltIn, LOW);
delay(1000);
digitalWrite(ledBuiltIn, HIGH);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
digitalWrite(ledBuiltIn, LOW);
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
client.setInsecure();
client.connect(serverPath.c_str(), 443);
http.begin(client, serverPath.c_str());
int httpResponseCode = http.GET();
Serial.println(httpResponseCode);
if (httpResponseCode > 0)
{
if (http.getString() == "CLOSED")
{
// NOOP
}
else
{
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW);
}
}
http.end();
}
delay(3000);
}