[SOLVED] HELP with esp8266 AND ifttt

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

When I open the monitor here is what happens

DOOR OPEN!!
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...

and it does not stop

What tutorial are you using?

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.

Hey!

Here is the tutorial I was using

but the code that he shared is not the same one that he uses in the video.

Here is the actuall code I am using right now. But I doesn't work

#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(115200);

   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) yield();
      doorClosed = 0;
      break;
    }

}

 
int get_http()
{
   HTTPClient http;
   int ret = 0;
   Serial.print("[HTTP] begin...\n");

    http.begin("https://maker.ifttt.com/trigger/door_opened/with/key/dPr3nmKyZ6e5_wbC0-xWgh","5B:63:B5:6B:23:ED:0C:41"); //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;
}

And here is what shows up on the monitor

.Connected to wifi
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
DOOR OPEN!!
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...
[HTTP] GET failed, error: connection refused
[HTTP] begin...
[HTTP] begin...

Hopefully you can help me

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.

You might want to look at this one:

There is further info at makeuseof.com, with sketch available from Pastebin.

Heu I just solved the problem.

Here is a link if you want to follow what I went through

Thanks for you help. Hopefully that can help you latter.

https://forum.arduino.cc/index.php?topic=638809.15