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;
}
I have my first WiFi thing (a D1 Mini) enroute from the Far East, and I plan to make a mailbox notifier using IFTTT. Looks like it would be very similar to what you are doing. I usually try to find a Youtube video that explains how to do everything, with code on Github. The closest I've found so far is Ralph Bacon's video:
It uses Thingspeak instead of IFTTT, and uses a secure connection. But he goes on at length explaining the code, so it might be useful to check your code against what he did. And if anyone knows of a better video on this subject, please post the link.
I don't know enough about this to help you. Based on the comments to the video, it looks like he dropped the ball on providing the code. Well have you tried using the Google Drive code he provides? It looks like yours is significantly different from that. I really don't know what else to suggest, except maybe find a better tutorial.