Uno WiFi R4 OTA upload via http hosted file?

Hi,

I have an Uno WiFi R4 that works with the File > Example > OTAUpdates sketch that points to

static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/UNOR4WIFI_Animation.ota";

I can download this file. Host it myself via HTTP (not HTTPS), and OTAUpdates works pointed to the file on my webserver.

What I cant seem to do is figure out how to compile a sketch into a format the OTAUpdates sketch will actually download.

I've located the compiled exports from the IDE at:

C:\Users\USERNAME\AppData\Local\arduino\sketches\03CB4EDBD33F2F24AF5F98C5DFDFC182

Where I have a .bin, .hex, .map, .efl etc.

All attempts to host this .bin and point OAUpdates to it result in it hanging or failing at ota.download.

Even for the example PlayAnimation sketch, the .bin is 53KB, VS the .ota linked in the example being 29KB.

Am I beating my head against file size limits? Some way to make a .OTA file beyond just compiling that also compresses?

OTAUpdates Example I'm using:


#include "WiFiS3.h"
#include "OTAUpdate.h"
#include "root_ca.h"
#include "arduino_secrets.h"

const char* ssid     = "SSID";
const char* pass = "Pass";   // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

OTAUpdate ota;



static char const OTA_FILE_LOCATION[] = "http://192.168.1.100/files/PlayAnimation.bin";



/* -------------------------------------------------------------------------- */
void setup() {
/* -------------------------------------------------------------------------- */
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  delay(1000);

  // check for the Wi-Fi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with Wi-Fi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wi-Fi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 1 seconds for connection:
    delay(1000);
  }

  delay(1000);

  printWiFiStatus();


  Serial.println("about to ota.begin");
  delay(100);
  int ret = ota.begin("/update.bin");
  if(ret != OTAUpdate::OTA_ERROR_NONE) {
    Serial.println("ota.begin() error: ");
    Serial.println((int)ret);
    return;
  }
  // Serial.println("about to ota.setCACert");
  // delay(100);
  // ret = ota.setCACert(root_ca);
  // if(ret != OTAUpdate::OTA_ERROR_NONE) {
  //   Serial.println("ota.setCACert() error: ");
  //   Serial.println((int)ret);
  //   return;
  // }
  Serial.println("about to ota.download");
  delay(100);
  int ota_size = ota.download(OTA_FILE_LOCATION, "/update.bin");
  if(ota_size <= 0) {
    Serial.println("ota.download() error: ");
    Serial.println(ota_size);
    return;
  }
  Serial.println("about to ota.verify");
  delay(100);
  ret = ota.verify();
  if(ret != OTAUpdate::OTA_ERROR_NONE) {
    Serial.println("ota.verify() error: ");
    Serial.println((int)ret);
    return;
  }
  Serial.println("about to ota.update");
  delay(100);
  ret = ota.update("/update.bin");
  if(ret != OTAUpdate::OTA_ERROR_NONE) {
    Serial.println("ota.update() error: ");
    Serial.println((int)ret);
    return;
  }
}

/* -------------------------------------------------------------------------- */
void loop() {
/* -------------------------------------------------------------------------- */
  delay(1000);
}

/* -------------------------------------------------------------------------- */
void printWiFiStatus() {
/* -------------------------------------------------------------------------- */
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Any help appreciated.

try to use Export from the Sketch menu. it puts the exported binary file next to the ino file

Hi, you'll need to use these tools to compress/convert the .bin to a .ota

Thanks for the replies! :slight_smile:

Thats what I was after steve9

Next will be seeing if I can update the firmware on the ESP32 side to host the webserver / file while retaining its USB to Serial function. :slight_smile:

why do you want the esp32 to host the webserver? it is the esp32 which downloads the update and then applies it to the main MCU.

Because if the on board ESP32 can host the web server I can have a fully self contained remote OTA programable Uno WiFi R4, without the need for another device to act as web server.

did you try my ArduinoOTA library?

Having it all in one similar to ElegantOTAS rather than appear as a device to the IDE lets me do it over the web too :slight_smile:

I have a similar problem with OTA on UNO R4 WIFI

I have
C:\Users...\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.5.1\platform.local.txt
Using OTANonBlocking, I can load and run the demo file:
" https://downloads.arduino.cc/ota/UNOR4WIFI_Animation.ota "
I can load and run this file also from my server
I have stripped out the .lzss part of the demo .ota file, and successfully
reconstructed the .ota file (crc etc). This loads and runs.
I can run the blink demo from IDE 1.8.19
I cannot run python lzss.py - missing files Win7
I can put the uncompressed compliled Blink .bin file into a .ota file
It will load to the board and verify ok, but then nothing happens.
Resetting the board doesn't seem to help.

Does anyone have an lzss.exe program?
Does anyone have any other ideas please?

After some frustration, I have created a Bin2Ota windows program

that takes an arduino .bin file and produces a compressed .ota file

ready to save on a server that can be uploaded via an ota procedure

as in the example OTANonBlocking.ino

It is available for downloading at:

Must run in a Command Prompt ( dos box)

Usage: Bin2Ota Boardtype file
Boardtype = [ MKR_WIFI_1010 | NANO_33_IOT | PORTENTA_H7_M7 | NANO_RP2040_CONNECT | NICLA_VISION | OPTA | GIGA | NANO_ESP32 | ESP32 | UNOR4WIFI | PORTENTA_C33]

Input File: file.bin

Output File: file.ota

Only tested in Win7 with UNOR4WIFI