Hey guys I am pretty much a noob with Arduino, I just started. I found a Tutorial about making a door sensor that would send me a notification to my phone when my door opens. It uses an ESP8266, a magnetic sensor the IFTTT app and some coding. The probelm is that it is not working. I am able to flash it on my ESP8266 with no problem. But I guess something is rong because when I open the sesnor I don't receive any notification.
Here is the code
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#define REED_SWITCH 5 //D1
int status = WL_IDLE_STATUS;
const char* ssid = "******";
const char* password = "**********";
int doorClosed = 1;
void setup() {
pinMode(REED_SWITCH, INPUT_PULLUP);
Serial.begin(9600);
WiFi.mode(WIFI_STA);
status = WiFi.begin(ssid, password);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to wifi");
get_http();
}
void loop() {
while ((digitalRead(REED_SWITCH) == HIGH) && (doorClosed == 1))
{
Serial.println("DOOR OPEN!!");
while (get_http() != 0);
doorClosed = 0;
break;
}
}
int get_http()
{
HTTPClient http;
int ret = 0;
Serial.print("[HTTP] begin...\n");
http.begin("HERE IS MY IFTTT KEY************"); //HTTP
Serial.print("[HTTP] begin...\n");
int httpCode = http.GET();
if(httpCode > 0) {
Serial.printf("[HTTP] GET code: %d\n", httpCode);
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
ret = -1;
Serial.printf("[HTTP] GET failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
return ret;
}
Thanks in advance