ESP OTA updating over https web server

Viewed 1142

I have an old code which works great and has no problem but I have been asked to change the OTA configuration so that this code can update itself from a SSL server. I have the certificate and the fingerprint needed for this (downloaded it from google chrome). I have googled and tried most of the advised method for OTA over HTTPS. but none of them worked for me. the results which I get from 'ESPhttpUpdate.update' is always "-1" which means "connection failed".

can anybody propose a method which works all right? as I don't have any correct code I don't post any. I just want a suggestion or a sample code.

thank you all in advance

1 Answers

The problem was solved.

I had split the server address into 2 parts (as the sample code suggested), URL and URI; but I don't know why, when I concatenated them together, the problem was solved.

here is the code for those who may need it:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <FS.h>
#include "ESP8266httpUpdate.h"

/********************************************************
 ******************************************************** 
 ********************************************************/
const char* ssid = "********";  // modify this
const char* password = "********";   // modify this

const char* host = "https://server/steamer_v1_2.bin";   // modify this

/********************************************************
 ******************************************************** 
 ********************************************************/
void setup() {
  Serial.begin(115200);
  
  WiFi.mode(WIFI_STA);

  for (uint8_t t = 4; t > 0; t--)
  {
    Serial.printf("[SETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }

  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);

  if (WiFi.SSID() != ssid) {
    WiFi.begin(ssid, password);
  }
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // configure time
  configTime(3 * 3600, 0, "pool.ntp.org");

  BearSSL::WiFiClientSecure client;
  const uint8_t fingerprint[20] = {0xdd, 0xa5, 0x2d, 0x31, 0x25, 0x31, 0xae, 0x7a, 0x10, 0x0b, 0x68, 0xba, 0x22, 0x84, 0x1a, 0x94, 0xec, 0x79, 0xb4, 0xbb};   // modify this
  client.setFingerprint(fingerprint);

  auto ret = ESPhttpUpdate.update(client, host);
  // if successful, ESP will restart
  Serial.println("update failed");
  Serial.println((int) ret);
}

/********************************************************
 ******************************************************** 
 ********************************************************/
void loop() {
}
Related