OTA from https server url

I'm attempting to update my ESP32 from my server, but I'm facing some difficulties with the example code I've been using. The process seems to stall at a certain point, and when I check the serial output, I see the following:

Connecting...
Connected to WiFi
Downloading firmware...
HTTP_CODE_OK
http.getStreamPtr
Uploading firmware.

i run export compiled binary in arduino ide and that file i add to my server

#include <WiFi.h>
#include <HTTPClient.h>
#include <Update.h>

void OTA() {
  const char* ssid = "test";
  const char* password = "123456789";
  const char* firmwareUrl = "https://example.com/FW/1.bin";
  const unsigned long timeoutDuration = 30000; // Timeout duration in milliseconds (30 seconds)

  Serial.println("Starting OTA update...");

  Serial.println("Connecting to WiFi...");
  WiFi.begin(ssid, password);
  int attempts = 0;
  while (WiFi.status() != WL_CONNECTED && attempts < 10) {
    delay(1000);
    Serial.println("Connecting...");
    attempts++;
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("Connected to WiFi");

    HTTPClient http;
    http.begin(firmwareUrl);

    Serial.println("Downloading firmware...");
    unsigned long startTime = millis(); // Record start time
    int httpCode = http.GET();
    if (httpCode == HTTP_CODE_OK) {
      Serial.println("HTTP_CODE_OK");

      WiFiClient* stream = http.getStreamPtr();
      Serial.println("http.getStreamPtr");

      if (Update.begin()) {
        Serial.println("Uploading firmware...");
        size_t written = 0;
        unsigned long uploadStartTime = millis(); // Record upload start time
        do {
          written = Update.writeStream(*stream);
          if (written > 0) {
            Serial.print("Bytes written: ");
            Serial.println(written);
          }
        } while (written > 0 && millis() - uploadStartTime < timeoutDuration); // Continue writing until timeout or all data is written
        
        if (written == http.getSize()) {
          Serial.println("Firmware upload successful");
        } else {
          Serial.println("Firmware upload failed");
        }

        if (Update.end()) {
          Serial.println("OTA update successful");
          ESP.restart();
        } else {
          Serial.println("OTA update failed");
        }
      } else {
        Serial.println("Could not begin firmware update");
      }
    } else {
      Serial.println("Failed to download firmware");
    }

    http.end();
  } else {
    Serial.println("Failed to connect to WiFi");
  }
}

void setup() {
  Serial.begin(9600);
  OTA(); // Call OTA function to initiate the update process
}

void loop() {
    Serial.println("V1 - test");
   delay(1000);
}

you are using HTTPClient for a https (secure) request (https://example.com/FW/1.bin)

could you ensure this is working fine, try printing the bytes you get from the server

i tried
const char* firmwareUrl = "http://serverIP:80/FW/1.bin";

but same thing , in serial i see

Connecting...

Connected to WiFi

Downloading firmware...

HTTP_CODE_OK

http.getStreamPtr

Uploading firmware...

and code dont go any further so i dont get any other message

does your server work with HTTP or HTTPS ?

if you curl that URL, do you get something?

http and https are ok . if i open that url a binary file start to download

OK so server is working

would be good to see if you can get the same byte stream in your code (instead of passing that to update)

rxa_eb mem fail tid=%drap mem fail tid=%d%s %d
failed to start addba timeraddba index: unknow conn=%ptap to index: null conntap to index: null bssaddba response cb: status %d not success, no need to configure hardwareaddba response cb: ap bss deletedaddba response cb: ap conn deletedaddba response cb: bssid change from %02x:%02x:%02x:%02x:%02x:%02x to %02x:%02x:%02x:%02x:%02x:%02xaddba response cb: sta bss deletedaddba response cb: sta conn deletedaddba response invalid param%s %d
%s %d
%s %d
%s %d
alloc challenge: out of memory!%s %d
ioctl_process: invalid argioctl: unsupported ioctl cmd=%dioctl: invalid cmd(%d)ioctl: null paraminvalid ipc cfgwpa2 ent enable, invalid param(%p)wifi stop stage error, stage=%d
In function %s, fail to register function!
invalid core id %drx ba window %d errormanagement short buf number %d is out of rangetx buf type %d errordynamic tx buf number %d is out of rangestatic tx buf number %d is out of rangedynamic rx buf number %d is out of rangestatic rx buf number %d is out of rangewpa crypto funcs expected size=%d version=%d, actual size=%d version=%dinvalid magic number %x, call WIFI_INIT_CONFIG_DEFAULT to init configparameter config should not be NULL%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
Channel number %d is out of range from %d to %d in country code cc=%c%c%c.sta is connecting, return errorinit nvs: failed, ret=%xwifi nvs cfg alloc out of memorynvs invalid min %d max %dinvalid wifi nvs key index %d%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
%s %d
setup rate: out of memory!%s %d
%s %d
%s %d
null wpa_parse_wpa_ienull wpa_parse_wpa_ienull wpa_parse_wpa_ieSAE H2E disabledwpa_config_parse_string is null%s %d
%s %d
Mem alloc fail for SA Q r

does it match the bin file ?
do you get it all?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.