|
#include <ESP8266WiFi.h> |
|
#include <ESP8266HTTPClient.h> |
|
|
|
HTTPClient http; //Declare an object of class HTTPClient |
|
WiFiClientSecure client; |
|
|
|
const char* ssid = "xxx"; //insert your SSID here |
|
const char* password = "xxx"; //insert your WIFI-Password here |
|
const char* host = "https://api.pushcut.io/xxx/notifications/Doorbell"; |
|
|
|
void setup() { |
|
Serial.begin(115200); |
|
Serial.println("Booting"); |
|
WiFi.mode(WIFI_STA); |
|
WiFi.begin(ssid, password); |
|
while (WiFi.status() != WL_CONNECTED) { |
|
Serial.print("."); |
|
delay(500); |
|
Serial.print("Connected"); |
|
} |
|
} |
|
|
|
void loop() { |
|
sonos(); |
|
iphone(); |
|
Serial.print("Good Night ..."); |
|
ESP.deepSleep(0); |
|
delay(3000); |
|
} |
|
|
|
void iphone() { |
|
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status |
|
client.setInsecure(); //the magic line, use with caution |
|
client.connect(host, 443); |
|
http.begin(client, host); // Push notification to my phone. |
|
int httpCode = http.GET(); //Send the request |
|
if (httpCode > 0) { //Check the returning code |
|
String payload = http.getString(); //Get the request response payload |
|
Serial.println(httpCode); |
|
Serial.println(payload); //Print the response payload |
|
} |
|
http.end(); //Close connection |
|
} |
|
} |
|
|
|
void sonos() { |
|
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status |
|
http.begin("http://172.20.20.130:8888/doorbell_press?ringtone=dingdong1&volume=60"); //Push to sonos speakers |
|
int httpCode = http.GET(); |
|
if (httpCode > 0) { //Check the returning code |
|
String payload = http.getString(); //Get the request response payload |
|
Serial.println(httpCode); |
|
Serial.println(payload); //Print the response payload |
|
} |
|
http.end(); //Close connection |
|
} |
|
} |