我正在开发一个简单的设备,它会在按下按钮时提醒我。目前我只是想让 ESP8266 自己激活 webhook 事件。它将连接到 wifi,但不会激活事件。我不知道我是否会以错误的方式进行处理。http.Get() 命令返回一个 -1。如何激活 webhook?任何帮助表示赞赏。代码如下。
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid="ATT2506";
const char* password = "XXXXXXXX";
int ledPin = 2;
void setup() {
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,HIGH);
Serial.begin(115200);
Serial.println();
Serial.print("Wifi connecting to ");
Serial.println( ssid );
WiFi.begin(ssid,password);
Serial.println();
Serial.print("Connecting");
while( WiFi.status() != WL_CONNECTED ){
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("Wifi Connected Success!");
Serial.print("NodeMCU IP Address : ");
Serial.println(WiFi.localIP() );
digitalWrite( ledPin , LOW);
}
void loop() {
if (WiFi.status() != WL_CONNECTED){
digitalWrite( ledPin , HIGH);
}
if (1==1) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin("https://maker.ifttt.com/trigger/csalarm/with/key/XXXXXXXXXXX"); //Specify request destination
int httpCode = http.GET(); //Send the request
Serial.println(httpCode);
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(1); //Print the response payload
}
http.end(); //Close connection
}
delay(30000); //Send a request every 30 seconds
}