forked from krdarrah/trigBoard_MCP9808
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifttt.ino
52 lines (40 loc) · 1.46 KB
/
ifttt.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
/*
* Found example code here: https://iotdesignpro.com/projects/how-trigger-led-using-ifttt-and-esp32-email-notification
*
*/
void ifttt() {
if (strcmp(config.iftttEnable, "t") == 0) {//only if enabled
wiFiNeeded = true;
Serial.println("Sending ifttt");
WiFiClientSecure client;
const char* host = "maker.ifttt.com";
const int httpsPort = 443;
if (!client.connect(host, httpsPort)) {
Serial.println("couldn't connect..");
//client.stop();
return;
}
String url = String("/trigger/") + config.trigName + "/with/key/" + config.iftttMakerKey;
// Serial.print("requesting URL: ");
//
// Serial.println(url);
String jsonData = String("{ \"value1\" : \"") + config.trigName + "\", \"value2\" :\"" + pushMessage + "\", \"value3\" : \" \" }";
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: trigBoard\r\n" +
"Connection: close\r\n" + "Content-Type: application/json\r\n" + "Content-Length:" + jsonData.length() + "\r\n\r\n" + jsonData);
//let's wait for something to come back... only a few seconds
unsigned long startTimePush = millis();
while (millis() - startTimePush < 5000) {
if (client.available()){
Serial.println("From Server");
break;
}
}
while (client.available() != 0) {
Serial.print(char(client.read()));
}
client.stop();
Serial.println("");
}
}