繁体   English   中英

使用 IFTTT 与我的 ESP8266 发送消息时出现问题

[英]Problem sending message with my ESP8266 using IFTTT

我正在尝试制作一个简单的项目,其中 esp8266 使用 IFTTT 向我的手机发送短信。 我已经测试了我的 IFTTT 小程序/食谱,它运行良好。 我认为这可能是我的 wifi 的连接问题,我发现这也不是问题。 所以我检查了与主机的连接问题,这似乎是问题所在。 它根据这段代码打印连接失败:

if (.client,connect(host, httpsPort)) {

Serial.println("连接失败");

返回;

有人可以帮我解决这个问题。 谢谢

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>


const char* ssid = "ssid";

const char* password = "pass";


const char* host = "maker.ifttt.com";

const int httpsPort = 443;


 


void setup() {

  Serial.begin(115200);

  
  WiFi.begin(ssid, password);


  WiFiClientSecure client;


  if (!client.connect(host, httpsPort)) {

    Serial.println("connection failed");

    return;

  }


 


  String url = "/trigger/ESP8266/json/with/key/xxxxxxxxxx";


  client.print(String("GET ") + url + " HTTP/1.1\r\n" +

               "Host: " + host + "\r\n" +

               "User-Agent: BuildFailureDetectorESP8266\r\n" +

               "Connection: close\r\n\r\n");



  while (client.connected()) {

    String line = client.readStringUntil('\n');

    if (line == "\r") {

      break;

    }

  }

  String line = client.readStringUntil('\n');


}


void loop() {

}```


  [1]: https://i.stack.imgur.com/RkQqL.png

您必须等待开发板连接到您的 wifi 网络,然后才能发起 http 呼叫。

以下是连接 wifi 的示例:

#define WIFI_TIMEOUT 5000
#define WIFI_DEBUG true

/*
  This function will wait for a wifi to connect.
  If the connection takes more then WIFI_TIMEOUT it will return 
  false, otherwise returns true.
*/
boolean connectWifi(){
    WiFi.begin(ssid, password);
    long wifiConnStartMS = millis();
    #if WIFI_DEBUG
        Serial.printf("\nConnecting to: %s...",ssid);
    #endif
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(200);
        if( millis() - wifiConnStartMS >= WIFI_TIMEOUT ){
            #if WIFI_DEBUG
                Serial.println("\nTimeout on wifi connection. Wrong credentials?");
            #endif
            return false; 
        }
    }
    #if WIFI_DEBUG
        Serial.printf("\nWiFi Connected to: %s\n",ssid);
    #endif
    return true;
}

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

    if( connectWifi() ){
        // Begin the call after that...
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM