Page 1 of 1

How can I store permanent data with spiffs on esp32?

Posted: Fri Sep 17, 2021 7:43 am
by Hayden
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!

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

Posted: Sat Sep 18, 2021 12:03 pm
by ullixesp
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.

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

Posted: Wed Sep 22, 2021 5:51 am
by Hayden
Thanks for the reply, I'll adopt your advice!