Espduino connection to SSL REST fails with "client handshake failed"


I’m trying to post some sensor data to AWS API Gateway. That service requires a SSL connection. Unfortunately the POST request fails with “client handshake failed”. Is there any special parameter necessary? I’m using the stock esp8266 firmware which came with the Cactus Micro Rev2.


the original firmware can’t support SSL. I’m very sorry.

I’m a little confused. On your github page is written that the API supports SSL:

Could it be that issue where a new compilation with a new SDK version is necessary?

Could you please post your sketch code? Please also check the pushbullet sketch

#include <dht11.h>
#include <espduino.h>
#include <rest.h>
#include <MQ135.h>
#include <ArduinoJson.h>

#define LOCATION "test"
#define ROOM  "room1"

#define PIN_ENABLE_ESP 13
#define SSID  "ssid"
#define PASS  "pass!"

#define DHT11_PWPIN  8
#define DHT11_READPIN  9
#define MQ135_READPIN  10

dht11 DHT;

ESP esp(&Serial1, &Serial, PIN_ENABLE_ESP);
REST rest(&esp);
MQ135 gasSensor = MQ135(MQ135_READPIN);

boolean wifiConnected = false;

void wifiCb(void* response)
  uint32_t status;
  RESPONSE res(response);

  if (res.getArgc() == 1) {
    res.popArgs((uint8_t*)&status, 4);
    if (status == STATION_GOT_IP) {

      Serial.println("WIFI CONNECTED");

      wifiConnected = true;
    } else {
      wifiConnected = false;


void setup()

  while (!esp.ready());

  Serial.println("ARDUINO: setup rest client");
  if (!rest.begin("",443,true)) {
    Serial.println("ARDUINO: failed to setup rest client");
    while (1);

  /*setup wifi*/
  Serial.println("ARDUINO: setup wifi");
  esp.wifiConnect(SSID, PASS);
  Serial.println("ARDUINO: system started");

  // setup DHT11 power and reading
  pinMode(DHT11_PWPIN, OUTPUT);
  pinMode(DHT11_READPIN, INPUT);
  digitalWrite(DHT11_PWPIN, HIGH);


void loop()

  if (wifiConnected) {

    float rzero = gasSensor.getRZero();
    float ppm = gasSensor.getPPM();
    char ppm_str[5] ;

    char strID;

    int chk =;
    if (chk == DHTLIB_OK) {
      char str_hum[6], str_temp[6];
      dtostrf(DHT.humidity, 4, 2, str_hum);
      dtostrf(DHT.temperature, 4, 2, str_temp);

      Serial.print("Humidity: ");
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(" *C\t");
      Serial.println(" ppm CO2");

      StaticJsonBuffer<200> jsonBuffer;
      JsonObject& root = jsonBuffer.createObject();

      root["ID"] = "test_room_123";
      root["location"] = LOCATION;
      root["room"] = ROOM;
      root["timestamp"] = "1234567";
      root["co2"] = ppm_str;
      root["temp"] = str_temp;
      root["humidity"] = str_hum;

      String jsonString;
      char data_buf[300];
      jsonString.toCharArray(data_buf, 300);

  "/prod/sensors", data_buf);

    } else {

    delay(5000);                        // wait 5 sec for next readin

I can’t make sure it need a new SDK. But if you want to compile a new firmware yourself, here’s the SDK files.

Was anyone successful in retrieving the server response with SSL enabled? I am getting some garbage with getResponse(buff, size) when the connection is established with SSL.

Hi there,

I am facing the same problem. When I try to post some data to AWS API Gateway, my esp always fails with “client handshake failed” “Error: SSL error 40”. But when I use chrome to post the same message, I can get the right response. I am wondering how do you solve this problem? Any replay would be grateful.

I could not solve it. I managed to recompile the espduino firmware with a new SDK version but that didn’t make any difference. I also tried the esp-link ( lib but failed to read the sensors via the Atmel SoC. I ended up using a reserved EC2 instance with a custom PHP script that feeds the database.