Search code examples
pythonarduinoesp8266ifttt

How to do a POST request with ESP8266 to the IFTTT Webhook service properly?


I am completely new to Python and ESP8266 (Arduino like) modules. I'm trying to make an IFTTT webhook POST Request when the module is turned on and it has successfully connected to the wifi. But it seems that I did something wrong, it didn't work at all and I am probably completely unaware, is there anything I could do and maybe learn something new?

The following code is made from constant copy and pasting since I am not experienced with Python (just yet?). Pardon if it does look utterly terrible and impractical, but that's just what I have for now.

#include <IFTTTWebhook.h>
#include <ESP8266WiFi.h>

#define led LED_BUILTIN
#define ssid "ssid name"
#define password "pass"
#define IFTTT_API_KEY "key"
#define IFTTT_EVENT_NAME "your event"
//these were filled with the required data, I changed it for privacy reasons.

void setup() {
  Serial.begin(74880);

  connectToWifi();

  //just connected to Wi-Fi
  IFTTTWebhook hook(IFTTT_API_KEY, IFTTT_EVENT_NAME);
  hook.trigger();
  Serial.print("hook triggered");

  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);   
  delay(200);              
  digitalWrite(led, LOW); 
  //now sending board to sleep

  ESP.deepSleep(wakePin); 
}
void loop(){
  //if deep sleep is working, this code will never run.
  Serial.println("This shouldn't get printed");
}

void connectToWifi() {
  Serial.print("Connecting to: "); //uncomment next line to show SSID name
  Serial.print(ssid); 
  WiFi.begin(ssid, password);  
  Serial.println(" ");// print an empty line
  Serial.print("Attempting to connect: ");

  //try to connect for 10 seconds
  int i = 10;
  while(WiFi.status() != WL_CONNECTED && i >=0) {
    delay(1000);
    Serial.print(i);
    Serial.print(", ");
    i--;
  }
  Serial.println(" ");// print an empty line

  //print connection result
  if(WiFi.status() == WL_CONNECTED){
    Serial.print("Connected."); 
    Serial.println(" ");// print an empty line
    Serial.print("NodeMCU ip address: "); 
    Serial.println(WiFi.localIP());
  }
  else {
    Serial.println("Connection failed - check your credentials or connection");
  }
}

if the module has successfully connected to the wifi, it will automatically send a webhook POST request and I will receive a notification on my mobile phone, but in the end, there's nothing coming out of it.

Thank you for your time.


Solution

  • If this is my IFTTTWebhook library, I'm withdrawing the library. Don't use it. I don't have time to maintain it. I don't want to publish a library that communicates with IFTTT insecurely. Handling HTTPS has been a moving target (for good reasons), so I'm withdrawing the library. Sorry for your time being wasted on it. I'd recommend reading up on the IFTTT API and communicating with it directly with ESP8266HTTPClient; it's a fairly trivial exercise.