first final version.

This commit is contained in:
Joe Tretter
2022-06-17 16:43:55 -05:00
parent 66864ba2bf
commit 2ce6c5d012

View File

@@ -102,6 +102,30 @@ const char* serverIndex =
"});" "});"
"</script>"; "</script>";
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=none";
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");
}
/* /*
* setup function * setup function
*/ */
@@ -139,6 +163,9 @@ void setup(void) {
} }
} }
Serial.println("mDNS responder started"); Serial.println("mDNS responder started");
send_notification("garagedoor.rebooted.livorno.address");
/*return index page which is stored in serverIndex */ /*return index page which is stored in serverIndex */
server.on("/", HTTP_GET, []() { server.on("/", HTTP_GET, []() {
server.sendHeader("Connection", "close"); server.sendHeader("Connection", "close");
@@ -176,29 +203,6 @@ void setup(void) {
server.begin(); 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) { void loop(void) {
@@ -211,11 +215,11 @@ void loop(void) {
if (buttonState == HIGH) { if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
Serial.println("Garage Opened"); Serial.println("Garage Opened");
send_notification("garagedooropen.livorno.address"); send_notification("garagedoor.open.livorno.address");
} else { } else {
digitalWrite(ledPin, LOW); digitalWrite(ledPin, LOW);
Serial.println("Garage Closed"); Serial.println("Garage Closed");
send_notification("garagedoorclosed.livorno.address"); send_notification("garagedoor.closed.livorno.address");
} }
previousState=buttonState; previousState=buttonState;
} }