WiFiClientSecure fails to connect - how do I get the error to know where it's failing

Hi,

I have a working wifi connection on my ESP8266. I can ping it.

I have the following code:

const char* whost = "api.openweathermap.org";
const int httpsPort = 443;

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

SImple. I just want a way to know what is the error. Is it SSL negotiation, maybe the web address is not getting resolved... etc.

Is there a way to get a more detailed error from the client class?

Thank you

I cannot figure out what is happening, most of the relevant code is missing.

on the TCP level connect sends a packet and waits for a packet with a response. if the response doesn't arrive, it has no information why. then the connection ends on a timeout (around 10 seconds)
if connect returns immediately, then the server refused the connection.

WiFiClientSecure also initializes the secure level. here it can fail on certificates validity. To test this, try to connect with WiFiClient. if WiFiClient connects, then the problem is with the secure level.

and to have this comment complete, connect can also fail on server name resolution. that you can test with WiFi.hostByName function.

Thanks @Juraj ..

I take it there isn't a way then to get an error describing what is happening to the failure. I will have to experiment...

Thanks.

I found
https://arduino-esp8266.readthedocs.io/en/3.1.2/esp8266wifi/bearssl-client-secure-class.html#errors

First thing I test if WiFiClientSecure can't connect is to use setInsecure(). If it works with "insecure", then the problem is in certificates.
https://arduino-esp8266.readthedocs.io/en/3.1.2/esp8266wifi/bearssl-client-secure-class.html#setinsecure

Thank you...

Got it. Using "getLastSSLError" I get:

1000 Unable to allocate memory for SSL structures and buffers

Sucks! :slight_smile: need more memory...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.