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


#1

Hi,

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.

Thanks!


#2

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


#3

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

Could it be that issue https://github.com/tuanpmt/esp_bridge/issues/1 where a new compilation with a new SDK version is necessary?


#4

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


#5
#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()
{

  Serial1.begin(19200);
  Serial.begin(19200);
  esp.enable();
  delay(500);
  esp.reset();
  delay(500);
  while (!esp.ready());

  Serial.println("ARDUINO: setup rest client");
  if (!rest.begin("myhost.execute-api.eu-central-1.amazonaws.com",443,true)) {
    Serial.println("ARDUINO: failed to setup rest client");
    while (1);
  }

  /*setup wifi*/
  Serial.println("ARDUINO: setup wifi");
  esp.wifiCb.attach(&wifiCb);
  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()
{
  esp.process();

  if (wifiConnected) {


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

    char strID;

    int chk = DHT.read(DHT11_READPIN);
    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(str_hum);
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(str_temp);
      Serial.print(" *C\t");
      Serial.print(ppm_str);
      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;
      root.printTo(Serial);

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


      rest.setContentType("application/json");
     
      rest.post("/prod/sensors", data_buf);


    } else {
      Serial.print("error,\r\n");
    }

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

#6

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.


#7

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.


#8

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.


#9

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 (https://github.com/jeelabs/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.