我对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,它会自动发送一个webhook POST请求,我会在手机上收到一个通知,但最后,它什么也没有出来。
谢谢您抽时间见我。
发布于 2019-10-17 02:57:48
如果这是我的IFTTTWebhook库,我将提取该库。不要用它。我没有时间去维护它。我不想发布一个不安全地与IFTTT通信的库。处理HTTPS一直是一个不断变化的目标(有很好的理由),所以我正在撤除库。很抱歉在这上面浪费了你的时间。我建议阅读IFTTT API并直接与ESP8266HTTPClient进行通信;这是一个相当简单的练习。
https://stackoverflow.com/questions/58419236
复制相似问题