-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp32-ifttt.ino
71 lines (53 loc) · 1.44 KB
/
esp32-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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <HTTPClient.h>
#include <WiFi.h>
// Wifi
const char* ssid = "WIFI SSID";
const char* pass = "WIFI PASSWORD";
// IFTTT Webwook url
const String WebhookURL = "IFTTT WEBHOOK URL";
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, pass);
Serial.println("Connecting...");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected");
Serial.println(WiFi.localIP());
}
void loop() {
const int pinTouch = touchRead(4);
Serial.print("Value: ");
Serial.println(pinTouch);
if(pinTouch < 40 || pinTouch > 90){
Serial.println("Touch detected: Sending email");
if(SendEmail(pinTouch)){
Serial.println("Email sent");
Serial.println("Wait 10 seconds to detect pin touch again");
delay(10000);
}else{
Serial.println("An error has been ocurred, try again");
}
}
delay(500);
}
bool SendEmail(int value){
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
http.begin(WebhookURL);
http.addHeader("Content-Type", "application/json");
String _value = "";
_value += value;
const String json = "{\"value1\":\""+_value+"\"}";
int httpResponseCode = http.POST(json);
// Serial.println(json);
// Serial.println(value);
// Serial.println(_value);
// Serial.println(httpResponseCode);
if(httpResponseCode >= 200 && httpResponseCode < 300)
return true;
else return false;
}
}