first final version.
This commit is contained in:
54
src/main.cpp
54
src/main.cpp
@@ -102,6 +102,30 @@ const char* serverIndex =
|
||||
"});"
|
||||
"</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
|
||||
*/
|
||||
@@ -139,6 +163,9 @@ void setup(void) {
|
||||
}
|
||||
}
|
||||
Serial.println("mDNS responder started");
|
||||
|
||||
send_notification("garagedoor.rebooted.livorno.address");
|
||||
|
||||
/*return index page which is stored in serverIndex */
|
||||
server.on("/", HTTP_GET, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
@@ -176,29 +203,6 @@ 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) {
|
||||
@@ -211,11 +215,11 @@ void loop(void) {
|
||||
if (buttonState == HIGH) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
Serial.println("Garage Opened");
|
||||
send_notification("garagedooropen.livorno.address");
|
||||
send_notification("garagedoor.open.livorno.address");
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW);
|
||||
Serial.println("Garage Closed");
|
||||
send_notification("garagedoorclosed.livorno.address");
|
||||
send_notification("garagedoor.closed.livorno.address");
|
||||
}
|
||||
previousState=buttonState;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user