What exactly is the String size which can be stored in NVS with the preferences lib?
Posted: Fri Aug 18, 2023 3:10 pm
I use an ESP32-dev with the Arduino framework (on platformio under vscode), and the NVS storage with the preferences lib for some log data. I am quite pleased how easy and reliable this lib can be used.
But I now tried to expand the storage of strings and I am running into unexpected limits.
The Espressif docu says:
Under key WARN I store "Strings" (actually chars) of a maximum size of 3500. When adding new records, I add them at the top and cut from the bottom until the new String fits into the 3500 limit, and putString() it back. So in my case with records of near 70 bytes I can keep the latest approx. 50 records. Good, that is how I want it.
However, I have another key DEVEL, also with a max size of 3500, which I would like to treat and behave the same way. Each one of the two keys is well under the 4000 char limit, yet DEVEL cannot hold more than 3150 bytes. Any attempts to save more results in the error message:
So, somewhere there is an additional limit. Where does it come from?
What do I need to set in order to get the maximum string storage with my two keys WARN and DEVEL?
Here is an excerpt of the content for these two keys with some test data:
But I now tried to expand the storage of strings and I am running into unexpected limits.
The Espressif docu says:
My 4MB flash is configured for an NVS space of 0x5000 bytes. With every key at "full", the pref lib tells me I have 288 free entries.String values are currently limited to 4000 bytes. This includes the null terminator.
Under key WARN I store "Strings" (actually chars) of a maximum size of 3500. When adding new records, I add them at the top and cut from the bottom until the new String fits into the 3500 limit, and putString() it back. So in my case with records of near 70 bytes I can keep the latest approx. 50 records. Good, that is how I want it.
However, I have another key DEVEL, also with a max size of 3500, which I would like to treat and behave the same way. Each one of the two keys is well under the 4000 char limit, yet DEVEL cannot hold more than 3150 bytes. Any attempts to save more results in the error message:
Code: Select all
[ 3063][E][Preferences.cpp:273] putString(): nvs_set_str fail: warn NOT_ENOUGH_SPACE
What do I need to set in order to get the maximum string storage with my two keys WARN and DEVEL?
Here is an excerpt of the content for these two keys with some test data:
Code: Select all
# WARN: Bytes used:3450 out of 3500 (no errors)
18 14:16:07.515 51_123456789_123456789_123456789_123456789_123456789
18 14:16:07.641 52_123456789_123456789_123456789_123456789_123456789
18 14:16:07.769 53_123456789_123456789_123456789_123456789_123456789
...
18 14:16:13.386 98_123456789_123456789_123456789_123456789_123456789
18 14:16:13.515 99_123456789_123456789_123456789_123456789_123456789
18 14:16:13.641 100_123456789_123456789_123456789_123456789_123456789
# DEVEL: 3158 out of 3500
18 14:19:30.327 1_123456789_123456789_123456789_123456789_123456789
18 14:19:30.441 2_123456789_123456789_123456789_123456789_123456789
18 14:19:30.491 3_123456789_123456789_123456789_123456789_123456789
...
18 14:19:34.312 43_123456789_123456789_123456789_123456789_123456789
18 14:19:34.441 44_123456789_123456789_123456789_123456789_123456789
18 14:19:34.587 45_123456789_123456789_123456789_123456789_123456789
# (errors 'NOT_ENOUGH_SPACE' when trying to save more)