Go Down

Topic: HTTPS GET Request Not Working (Read 1 time) previous topic - next topic

mobileOhm

I'm working on a small project that sends an SMS text message with the ESP8266. I found this tutorial, which uses IFTTT and an HTTPS get request (through the WiFiClientSecure library) to send the message, but for some reason I always get the below in my serial monitor:

Code: [Select]

connecting to wifi_name_hidden
.
WiFi connected
IP address:
10.0.0.58
connecting to maker.ifttt.com
connection failed


My actual code is below:

Code: [Select]

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "wifi_name_hidden";
const char* password = "wifi_password_hidden";

const char* host = "maker.ifttt.com";
const int httpsPort = 443;

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  WiFiClientSecure client;
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

 

  String url = "/trigger/event_name_hidden/with/key/c51QL4DQw5Lsl601fXXXXX";
  Serial.print("requesting URL: ");
  Serial.println(url);

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

  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client.readStringUntil('\n');

  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
}

void loop() {
}



Any thoughts? Google has failed me.

rw950431


This thread https://github.com/esp8266/Arduino/issues/2856 appears to cover similar issues


TL;DR version:

Enable debugging by adding Serial.setDebugOutput(true)


Its possible that maker.ifttt.com and your ESP8266 cant agree on a suitable cipher to use for the exchange.




redpitiusa

After much reading I think I have found a solution to the connection failed issue based on the example sketch posted here.

Changes I did below. I can't say exactly which of these fixed the issue but I can confirm that it fixed the issue for me.

Change: WiFiClientSecure client;

To: BearSSL::WiFiClientSecure client;

Add lines

const int API_TIMEOUT = 10000;  //keep it long if you want to receive headers from client

Add following lines in setup

client.setInsecure();
client.setTimeout(API_TIMEOUT);

Worked for me, maybe this will help others

Go Up