Skip to content

SPIFFS

As a developer, I would like to make a list of where all the paired devices are stored so I won’t have to pair them again

Introduction guide

To automatically repair devices that have been connected to the IoT remote we first need a place to store the addresses of the connection between the remote and the device. To store this list, we need to use a file system which in our case is SPIFFS.

SPIFFS utilizes a flat structure, which means that all the files that SPIFFS can access have to be in one folder. So things like directories aren’t allowed. This means that spiffs will read images/picture1.png as a file name and not a path.

Here is some code to use SPIFF:

First of all, you need to import SPIFF by using the

#include <esp_spiffs.h>
Then you need to configure SPIFFS. You can configure SPIFFS by creating an object of the “esp_vfs_spiffs_conf_t” struct. We chose to use the base of /spiffs since this is the standard option. we didn’t need a custom partition label so we have set it to null, which uses the standard label. We chose to set a maximum amount of files of one because we only need to store one list.

  esp_vfs_spiffs_conf_t conf = {
        .base_path = "/spiffs",
        .partition_label = NULL,
        .max_files = 1,
        .format_if_mount_failed = true};

Then we need to register SPIFFS.

The esp_vfs_spiffs_register() method both mounts and registers SPIFFS.

To see if the registration has been successful we make a variable that stores the condition of the registration.

esp_err_t ret = esp_vfs_spiffs_register(&conf)

The List

To make a list we need to store a file in the embedded directory which we send to the esp32. The file has to be specifically in a directory that is called data otherwise SPIFFS isn’t able to recognize the file.

you can download the list here

Source

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/spiffs.html

https://randomnerdtutorials.com/install-esp32-filesystem-uploader-arduino-ide/


Last update: June 9, 2023