如何使用 ESP8266 正确地向 IFTTT Webhook 服务发出 POST 请求?

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

我对 Python 和 ESP8266(类似 Arduino)模块完全陌生。我正在尝试在模块打开并且已成功连接到 wifi 时发出 IFTTT webhook POST 请求。但是好像我做错了什么,根本没有用,我可能完全不知道,有什么我可以做的,也许可以学到一些新东西吗?

以下代码是通过不断复制和粘贴制作的,因为我对 Python 没有经验(还没有?)。如果它确实看起来非常糟糕和不切实际,请原谅,但这就是我现在所拥有的。

#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");
  }
}

如果模块连接wifi成功,它会自动发送一个webhookPOST请求,我会在我的手机上收到通知phone,但最后没有任何消息出来了。

感谢您的宝贵时间。

如果这是我的 IFTTTWebhook 库,我将撤回该库。不要使用它。我没有时间维护它。我不想发布与 IFTTT 不安全通信的库。处理 HTTPS 一直是一个移动的目标(有充分的理由),所以我要撤回该库。很抱歉浪费您的时间。我建议阅读 IFTTT API 并直接与 ESP8266HTTPClient 进行交流;这是一个相当简单的练习。