-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_garage_door_notifier.ino
52 lines (39 loc) · 1.18 KB
/
open_garage_door_notifier.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
#include <ESP8266WiFi.h>
#include <SmsGlobal.h>
const char *ssid = "<wifi_ssid>";
const char *password = "<wifi_password>";
const char *sms_global_user = "<user>";
const char *sms_global_password = "<password>";
const char *sms_to = "<mobile_number>";
const int REED_PIN = D6;
SmsGlobal smsGlobal(sms_global_user, sms_global_password);
void setup() {
pinMode(REED_PIN, INPUT_PULLUP);
Serial.begin(115200);
delay(100);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (digitalRead(REED_PIN) == LOW) {
Serial.println("Garage door is open");
delay(600000); // 10 minutes
if (digitalRead(REED_PIN) == LOW) {
Serial.println("Garage door is still open - sending message");
smsGlobal.send("Garage Door", sms_to, "You left me open!");
}
} else {
Serial.println("Garage door closed");
}
Serial.println("ESP8266 in sleep mode");
ESP.deepSleep(3e8); // 5 minutes
}
void loop() { }