Description
Basic Infos
- This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- [N/A] If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: [ESP-12E]
- Core Version: [Core 5.0.1 Espressif8266 2.6.2]
- Development Env: [Platformio]
- Operating System: [Windows]
Settings in IDE
- Module: [AIThinker]
- Flash Mode: [qio]
- Flash Size: [4MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [160MHz]
- Upload Using: [SERIAL]
- Upload Speed: [921600] (serial upload only)
Problem Description
I am experiencing a problem with the ESP8266 WiFiClientSecure where it connects to my site, but drops the connection the moment the GET request is sent. The exact same code will work for other sites (e.g. www.google.com/index.html) but not this specific site. I have tested using fingerprint, trusted root certificate, and inscure modes; all have the same result: successful SSL connection, but connection lost the moment any HTTP GET is sent. The site works properly when tested with openssl (openssl s_client -crlf -connect mysite.com:443) or from any browser.
The SSL error returned (296) is not decoded successfully so debugging is difficult. Any guidance would be appreciated; the site is open so you can issue the Additional error handling is requested to provide useful feedback as to why a connection is dropped. More documentation will help too (I will be happy to write it once this is solved).
MCVE Sketch
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
char ssid[] = "myssid";
char psk[] = "mykey";
void ICACHE_FLASH_ATTR setup()
{
Serial.begin(115200);
// Start WiFI network
WiFi.mode(WIFI_STA);
delay(2000);
WiFi.begin(ssid,psk);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
delay(1000);
WiFiClientSecure client;
client.setInsecure();
HTTPClient http;
// works
//http.begin(client, "https://www.google.com/index.html");
// doesn't work but works with: openssl s_client -crlf -connect mysite.com:443
http.begin(client, "https://www.mysite.com/index.html");
int httpResult = http.GET();
if (httpResult == HTTP_CODE_OK) {
Serial.println(http.getString());
} else {
Serial.printf("HTTP error: %d\r\n", httpResult);
}
char sslErrorMsg[80];
int sslError = client.getLastSSLError(sslErrorMsg, sizeof(sslErrorMsg));
if (sslError) {
Serial.printf("SSL error: %d: %s\r\n", sslError, sslErrorMsg);
}
http.end();
}
void ICACHE_FLASH_ATTR loop()
{
yield();
}
Debug Messages
BSSL:Connected!
[HTTP-Client] connected to www.mysite.com:443
[HTTP-Client] sending request header
-----
GET /index.html HTTP/1.1
Host: www.mysite.com
User-Agent: ESP8266HTTPClient
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
Connection: keep-alive
Content-Length: 0
-----
[HTTP-Client][returnError] error(-5): connection lost
HTTP error: -5
SSL error: 296: Unknown error code.
[HTTP-Client][end] tcp is closed