Config file, read or write - safety.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
prem111
Posts: 58
Joined: Sun Feb 23, 2020 3:18 pm

Config file, read or write - safety.

Post by prem111 » 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 next thing is the format ... Maybe json?

User avatar
jimmo
Posts: 1681
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Config file, read or write - safety.

Post by jimmo » Wed Jun 10, 2020 6:23 am

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.

prem111
Posts: 58
Joined: Sun Feb 23, 2020 3:18 pm

Re: Config file, read or write - safety.

Post by prem111 » Thu Jun 11, 2020 7:18 pm

Thanks ! one more question... why littlefs ?

kevinkk525
Posts: 732
Joined: Sat Feb 03, 2018 7:02 pm

Re: Config file, read or write - safety.

Post by kevinkk525 » Fri Jun 12, 2020 7:05 am

prem111 wrote:
Thu Jun 11, 2020 7:18 pm
why littlefs ?
viewtopic.php?f=2&t=7228
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply