0

My ESP8266 collects data and sends it to a webserver over HTTP. I would like to use TLS for this but I cannot figure out how to get ESP8266 running on the Arduino framework to use this.

My curent code is based on ESP8266HTTPClient and when searching the ESP8266 pages on GitHub 50% of the information tells me that it's impossible to use HTTPS and the other half of the info tells me it's possible but not documented with WiFiClientSecure but that looks like a whole different way of communicating HTTP..

Link: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h

void senddata() {
  String testdata = "{\"tickle\": {\"id\": " + String (package.id) + ",\"value1\": " + String (package.value1) + ",\"value2\": " + String (package.value2) + "}}";
  Serial.println("Starting the journey to Salador..");
  http.begin("https://myserver/_db/Salador/upload");
  http.addHeader("Content-Type", "application/json");
  int httpCode = http.POST(testdata);
  if(httpCode > 0) {
      Serial.println("[HTTP] POST... code: ");
      Serial.println(httpCode);

  }
  else {
      Serial.println("[HTTP] POST... failed, error: ");
      Serial.println(http.errorToString(httpCode));
  }
  http.end();
}
1

I don't think you can easily mix the HTTP wrapper and the WiFiClientSecure. At the moment if you want to do HTTPS you have to do the HTTP portion of the transaction manually by sending the individual headers and then the body, then parsing the response yourself.

It's not that hard, and the example you point to shows you how it can be done - print the headers and body to the client, then read the data back looking for specific things (like a blank line to separate headers from body, etc).


Although: I do see this clue in the BasicHttpClient.ino example:

// configure traged server and url
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS

So maybe if you know the fingerprint of your HTTPS server you can connect directly with HTTPS. How you get that fingerprint though is not something I know yet.

  • 1
    I can get the fingerprint from my browser and will try just adding it to the http.begin() – Thijs May 18 '17 at 12:48
  • you have to hard-code the cert info for each domain. it's a PITA to manage if you get new certs, and it's hard to OTA if the trusted server goes down. not all certs fit; 2k is the known max, though depending on the sketch and ram, some 4k ones work as well. – dandavis May 18 '17 at 21:19
  • Sounds like it's better to relay through something like a Pi or use a Yun. – Majenko May 18 '17 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.