Page 1 of 1


PostPosted: Fri Jan 22, 2021 2:44 am
by Jana Vitkova
Hello everyone,
I come again for advice. I'm trying to implement asynchronous HTTPS POST request into ESP8266, but I am unsuccessfull.
I use the ESPAsyncTCP library with encryption enabled.
After calling the connect function, the axtls layer returns error 40 which means SSL_ALERT_HANDSHAKE_FAILURE:
Code: Select alltcp_ssl_new: 0
_recv[1]: 7
tcp_ssl_read: 0
tcp_ssl_read: -40
tcp_ssl_read: read error: -40
_recv[1] err: -40
tcp_ssl_free: 0
Disconnected 0

relevant code is here:
Code: Select allstatic const char *REQUEST = "GET /a/check HTTP/1.1\r\nHost: www.howsmyssl.com\r\nUser-Agent: ESP8266\r\nConnection: close\r\n\r\n";

static void replyToServer(void* arg) {
   AsyncClient* client = reinterpret_cast<AsyncClient*>(arg);

   // send reply
   if (client->space() > strlen(REQUEST) && client->canSend()) {
      client->add(REQUEST, strlen(REQUEST), 0);
      Serial.print("OUT of space\r\n");

/* event callbacks */
static void handleData(void* arg, AsyncClient* client, void *data, size_t len) {
   Serial.print("Data received from ");
   Serial.print(": ");
   Serial.write((uint8_t*)data, len);

void onConnect(void* arg, AsyncClient* client) {
   IPAddress adr = client->getRemoteAddress();
   Serial.print("Client has been connected to ");

void onError(void * arg, AsyncClient * client, err_t error){
   Serial.print("Connect Error ");

void onTimeout(void * arg, AsyncClient * client, uint32_t time){
   Serial.print("TimeOut ");
   delete client;

void onDisconnect(void * arg, AsyncClient * client){
   Serial.print("Disconnected ");
   Serial.println(client->space(), 10);
   delete client;

void SendStats(uint8_t ad){

   AsyncClient* cl = new AsyncClient;
   if(!cl)//could not allocate client
      cl->onTimeout(&onTimeout, cl);
      cl->onData(&handleData, cl);
      cl->onConnect(&onConnect, cl);
      cl->onError(&onError, cl);
      cl->onDisconnect(&onDisconnect, cl);
      cl->connect("howsmyssl.com", 443, true);

void loop(){
// WiFi is connected so every few minutes send request

Any ideas or what libraries (functions) do you use?
I can't use the synchronous HTTPClient, because in the event of an internet failure (WiFi is still available), the program will freeze for too many seconds.
Many thanks