How can I store permanent data with spiffs on esp32?

Hayden
Posts: 16
Joined: Thu Jul 01, 2021 8:10 am

How can I store permanent data with spiffs on esp32?

Postby Hayden » Fri Sep 17, 2021 7:43 am

How can I store permanent data with spiffs on esp32?
Example:
Variablefloat_one 126.658
Variablefloat_two 2.85
Variablefloat_....
These variables use my program, I can change these variables on STONE display. When I push the save button, then write the variables into storage. And when the esp32 restarts, I read the variables in the setup loop.
I use float and int variables.
I would like to use one file. And I save and read the name of the variable in the file.
Can I do it?
Thanks!

ullixesp
Posts: 83
Joined: Wed Oct 16, 2019 9:34 am
Location: Germany

Re: How can I store permanent data with spiffs on esp32?

Postby ullixesp » Sat Sep 18, 2021 12:03 pm

Yes, you can do that. But 2 comments:

First, I wouldn't use SPIFFS for anything. If you must use a filesystem, use LittleFS or FFat. See e.g. https://forum.arduino.cc/t/esp32-mit-sp ... phe/621573

Second, in your case I would NOT use any filesystem. Instead, use the NVS space for storage employing the Preferences lib.
https://docs.espressif.com/projects/esp ... flash.html
https://github.com/espressif/arduino-es ... references

I am storing single variables, bigger structs, and big 2k strings. For small sizes (~ 100 bytes) it is clearly faster than a file system, for bigger ones it is about on par. Corruption has so far never been an issue for me with NVS, but it surely has with a filesystem. I am using a file system for data files 10k ... 1000k.

Hayden
Posts: 16
Joined: Thu Jul 01, 2021 8:10 am

Re: How can I store permanent data with spiffs on esp32?

Postby Hayden » Wed Sep 22, 2021 5:51 am

Thanks for the reply, I'll adopt your advice!

Who is online

Users browsing this forum: No registered users and 55 guests