Storing files in ESP32 SPIFFS

Storing files in ESP32 SPIFFS

While experimenting and researching I found there are two ways of uploading files to the ESP32 via the SPIFF partition. This is separate from the main program sketch which means its content does not need uploading each time.

The partition does however need to be preformatted for its first used. Its size is limited to 1.5mb by default in the ESP 32 Dev module board type (See 2 in below picture). I selected this because it shows more options. OTA is short for Over The Air. Normally there a two program partitions which are switched between on update. The SPIFF is shared between this. NO OTA has a only one program slot but a larger SPIFF.

Note that changing the partition scheme requires the SPIFF to be reformatted and the data uploaded again.

First method and easier from experience (once setup)

The below plugin adds the ESP32 Sketch Data option (shown by 1 above). I liked this because it formats the SPIFF for me and uploads any files in the sketch data folder. It will also warn if the files are too big. I mainly used this for small sound affects (a alarm clock bell, door creaking, beeps and short phrases)

https://www.onetransistor.eu/2019/12/upload-files-esp8266-esp32-spiffs.html

Second method using a webserver

This is found in the the Arduino IDE under File menu > Examples > WebServer

A benefit from this method is you can actually read data back from SPIFFS. A single file can also be uploaded, and deleted.

  1. Add your WIFI details so the ESP32 is accessible via your computer.
const char* ssid = "wifi-ssid";
const char* password = "wifi-password";

2. I set the system to use the internal memory in SPIFFS format

#define FILESYSTEM SPIFFS

The contained data would be wiped on each reboot if true. So the program should be uploaded with the format flag set to false. Doing that will retain the data.

#define FORMAT_FILESYSTEM false

I open the serial monitor and see the IP address for the ESP32

Connected! IP address: 192.168.X.XX

I goto http://192.168.X.XX with your shown address to see a file not found message.

No files are on the SPIFFS for the web server. To resolved we need to run Tools -> ESP32 Sketch Data Upload. Note that the serial monitor needs to be closed as it actively use the ports this needs.

After the upload finishes the board reboots as if uploading a program.

The example program index page is a set of mock widgets for memory and GPIO.

To edit the files you would have to goto http://192.168.X.XX/edit

A upload/create row is at the top and files appear on the left. Right clicking on a item opens a menu as shown. HTML webpage files have the ability to view/edit the text as shown on the right. There is no save button but I found the normal save Ctrl + S did work for me.

Uploading is now a simple of choosing a file and pressing the upload button.