ESP8266和IFTTT

时间:2018-03-21 14:46:00

标签: arduino esp8266 ifttt

我正在开发一个简单的设备,当按下按钮时会提醒我。在这个时候,我只是想让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
}

0 个答案:

没有答案