Error while reading/writing config.dat in 1051

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Error while reading/writing config.dat in 1051

#1 Post by jgrad » 09 Mar 2021, 20:34

Hi,

last days I am experiencing error "FS : Error while reading/writing config.dat in 1051" when saving DeviceTask configuration. It wasnt happening before. HW is Sonoff 4CH.

what could be reason?

BRJ.

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Error while reading/writing config.dat in 1051

#2 Post by jgrad » 09 Mar 2021, 20:52

forgot to add info - ESP version is 20201227.
resetFlashWriteCounter doesnt help.

I can repair problem only by reflashing ESP software on device.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Error while reading/writing config.dat in 1051

#3 Post by Ath » 09 Mar 2021, 21:25

I would expect that the flash chip is starting to fail, even though an external rewrite seems to (temporarily) resolve it.

If you have the skill of that type of miniature soldering, you could try to replace the flash chip, else you might start to plan a replace of the entire device.
/Ton (PayPal.me)

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Error while reading/writing config.dat in 1051

#4 Post by jgrad » 09 Mar 2021, 21:34

:( sonoff 4CH does not have external flash

TD-er
Core team member
Posts: 8642
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Error while reading/writing config.dat in 1051

#5 Post by TD-er » 09 Mar 2021, 22:05

On an ESP8285 you only have 1M flash and thus roughly 120k of SPIFFS.
given the way how SPIFFS works, you need some completely free blocks of N pages (8k blocks of 32 pages each) which are not part of a file.

So that leaves only a few blocks free. (as in really free)
Every time a part of the settings file is written, it is taking a new page. But a complete block of 32 pages must have all pages no longer assigned to a file to be able to erase it.
This makes fragmentation on such a small SPIFFS very likely to happen.

What you can do, is perform a reboot, which does try to call the garbage collector of SPIFFS at boot.
But this can only erase blocks which do have all pages not linked to a file, so it may only help in some cases.

Another work-around is to trim the size of the config.dat file.
Only the first 36k of the file is being used, so if you download it, trim the last 28k of it, upload it again to the unit and reboot before changing anything else, you may get a system which is less likely to be bitten by fragmentation of the file system.

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Error while reading/writing config.dat in 1051

#6 Post by jgrad » 09 Mar 2021, 23:03

TD-er, thanks for explanation.

Last time just reflashing version file didnt help. Then I tried to flash blank1M.bin first and then flash it with version file again and now it works. After reflashing I uploaded previous config.

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Error while reading/writing config.dat in 1051

#7 Post by jgrad » 10 Mar 2021, 08:36

TD-er, another question for explanation - does applying "Factory reset" (and what level) help by "cleaning" fragmented SPIFFS.

Asking in order to clarify procedure I have to take in such cases:
* download current config file in Tools->Settings->Save
* do factory reset in Tools-> Factory Reset (what config can be prevented - eg Wifi settings)
* after reboot Upload previously downloaded config file
* enter login parameters for MQTT broker in Controller configuration (I recognized that this parameters are not part of config file)

thanks for explanation in advance.

J.

TD-er
Core team member
Posts: 8642
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Error while reading/writing config.dat in 1051

#8 Post by TD-er » 10 Mar 2021, 15:13

Factory reset does format the SPIFFS, so it is indeed a somewhat elaborate "Garbage Collection" :)

Credentials are stored in security.dat file.
If possible, try to reduce the config.dat file before upload to 36k (as in 36x1024 bytes) in size.
This will make it easier to manage on such a small SPIFFS file system.

Config preservation is present in the factory reset page, but I have gotten some reports that it isn't working, so I guess you will probably have to redo the entering of WiFi credentials.

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Error while reading/writing config.dat in 1051

#9 Post by jgrad » 20 Dec 2021, 10:26

just to share with community how I solved this problem (if somebody finds this useful)

* download current config file in Tools->Settings->Save and rename it to config_original.dat
* "shorten" config file (in MacOS i use command split -b 36k config_original.dat config_trimmed.dat - this generates config_trimmed.dataa (36K) and config_trimmed.datab (28k)
* rename config_trimmed.dataa to config.dat
* upload "trimmed" config.dat file Tools->Settings->Upload
* reboot
* enter login parameters for MQTT broker in Controller configuration (I recognized that this parameters are not part of config file)

TD-er
Core team member
Posts: 8642
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Error while reading/writing config.dat in 1051

#10 Post by TD-er » 20 Dec 2021, 16:18

I think we should let it strip by ESPEasy itself, especially on 1M nodes.
However I am not sure if we can save 36k and the current 64k file at the same time on the file system.
I think I already made new config files to be created as the smaller variant

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests