lucian_v
lucian_v

Reputation: 121

ESP32 OTA update including data folder in bin firmware

I saw there are few libs and tutorial about esp32 OTA update but as far as I saw this is working only for the code and not for the data folder. In my case I have a web server which store all html, css, js etc under "data" folder. Is there any way to have OTA update including these files as well?

Thanks

Upvotes: 1

Views: 2921

Answers (2)

romkey
romkey

Reputation: 7089

There are two tools that you can use from the command line to do what you're asking.

First you'll need to make a binary file containing an image of the filesystem - you can't update individual files, you'll have to overwrite the entire filesystem, which means you'll lose any data your program might have stored there.

Then you'll need to do an OTA update of the filesystem.

To make the binary file you'll use spiffsgen.py. You can download it from here. You'll need a working copy of Python on your computer to use it:

python3 spiffsgen.py 409600 data filesystem.bin

You should replace

  • 409600 with the size of the binary image of the filesystem - this must be a multiple of the flash page size, which should be 4096
  • data with the name of the directory holding the files
  • filesystem.bin with the name of the output file

The maximum size of the binary file will depend on the the partition scheme you choose for your ESP32's flash storage; obviously the minimum must be large enough to hold the files you want to copy.

Once you've generated the filesystem you can upload it via OTA using espota.py. The same tool can upload firmware or filesystem images, and works with

python3 espota.py -s -r -f .pio/build/lolin32/spiffs.bin -I ip-address -p 3232
  • -s is means transmit a SPIFFS filesystem rather than do a firmware update
  • -r means display a progress bar
  • -f is followed by the name of the file holding the filesystem image
  • -I is followed by the IP address or hostname of the device you want to update
  • -p is followed by the port number the ESP32 is listening on (usually 3232 for an ESP32, 8266 for an ESP8266)

Your application will need to use the ArduinoOTA library in order to support this. The library has built-in support for filesystem updates; your Arduino code doesn't need to do anything special to support it.

Upvotes: 2

Tarmo
Tarmo

Reputation: 4772

AFAIK there are no shrink wrapped solutions for updating files on a file system, so you get to create your own. Fortunately it's easy, because it's only data. You can either download a compressed archive (there are libraries supporting tar.gz on ESP32 and probably many others) and update your files by decompressing this archive. Or, alternatively you can also update the entire file system partition if you have the means of creating an image file. E.g. the SPIFFS includes a utility script spiffsgen.py which generates an image file, ready to be downloaded and flashed raw into the relevant partition using the SPI Flash API.

Upvotes: 1

Related Questions