Page 1 of 1

Config file, read or write - safety.

Posted: Thu May 28, 2020 2:55 pm
by prem111
What is the safest option for reading and writing the configuration file? I am afraid that when saving, for example, if there was no power, the file might not be saved completely ...

The next thing is the format ... Maybe json?

Re: Config file, read or write - safety.

Posted: Wed Jun 10, 2020 6:23 am
by jimmo
prem111 wrote:
Thu May 28, 2020 2:55 pm
What is the safest option for reading and writing the configuration file? I am afraid that when saving, for example, if there was no power, the file might not be saved completely ...
The two things to ensure:
- Use LittleFS rather than FAT
- Don't overwrite the in-use file, write a new file, then delete the old one. Detect the correct one to use at startup.
prem111 wrote:
Thu May 28, 2020 2:55 pm
The next thing is the format ... Maybe json?
JSON is good because there's built-in support and working with dictionaries is easy. The other common option is to write it as a Python file, then you can just import the file directly.

Re: Config file, read or write - safety.

Posted: Thu Jun 11, 2020 7:18 pm
by prem111
Thanks ! one more question... why littlefs ?

Re: Config file, read or write - safety.

Posted: Fri Jun 12, 2020 7:05 am
by kevinkk525
prem111 wrote:
Thu Jun 11, 2020 7:18 pm
why littlefs ?
viewtopic.php?f=2&t=7228