From 66864ba2bf53f700ceeb8546374d2bae54c41073 Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Thu, 16 Jun 2022 20:14:15 -0500 Subject: [PATCH] add remote messages via deadswitch --- src/main.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e812290..bb458db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -113,7 +114,7 @@ void setup(void) { pinMode(ledPin, OUTPUT); // if we stat up we need to see what the status is... - previousState= digitalRead(buttonPin); + digitalWrite(ledPin, previousState= digitalRead(buttonPin)); Serial.printf("Initial State: %d",previousState); // Connect to WiFi network WiFi.begin(ssid, password); @@ -175,6 +176,31 @@ void setup(void) { server.begin(); } +void send_notification(String subject){ + return; + Serial.println("Sending Notification."); + WiFiClientSecure client; + client.setInsecure(); // NOT RECOMMENDED + const char* host="deadswitch.kawomi.com"; + const int port=443; + if (!client.connect(host,port)) { + Serial.println("connection failed"); + return; + } + + String url = "/api/v1?topic=" + subject + "&secs=0&email=joerg.tretter@gmail.com"; + Serial.print("Requesting URL: "); + Serial.println(url); + client.print(String("POST ") + url + " HTTP/1.1\r\n" + + "Host: " + host + "\r\n" + + "Content-Type: application/x-www-form-urlencoded\r\n" + + "Content-Length: 14\r\n\r\n" + + "platform=esp32\r\n"); + +} + + + void loop(void) { server.handleClient(); delay(1000); @@ -185,9 +211,11 @@ void loop(void) { if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); Serial.println("Garage Opened"); + send_notification("garagedooropen.livorno.address"); } else { digitalWrite(ledPin, LOW); Serial.println("Garage Closed"); + send_notification("garagedoorclosed.livorno.address"); } previousState=buttonState; }