hi, I'm trying to store a key-value using nvs_set_str and it fails with ESP_ERR_NVS_NOT_ENOUGH_SPACE.
String has length = 3436 bytes and it is the only key-value pair my program uses.
I don't quite understand the NVS description from the dev book... is there a limit for a single value, or rather all stored values combined? is there any way to determine free storage left?
I'm using DevkitC board.
cheers
nvs_set_str - max length of string
Re: nvs_set_str - max length of string
The maximum length of a single string value is 4000 bytes (including the zero terminator byte). The error you are getting indicates that there is not enough space left in the partition to fit such a key value pair. You may try increasing NVS partition size in the partition table by one sector (for default partition tables this would mean moving NVS somewhere after the factory app).
NVS doesn't have an API to get available space. It has been requested, but hasn't been implemented yet.
NVS doesn't have an API to get available space. It has been requested, but hasn't been implemented yet.
Re: nvs_set_str - max length of string
thanks, got it.
Although what bothers me is the fact that I get this error only occasionally when updating my key-value pair.
Since this is the only kv in my program, and nvs partition size is 0x6000 ("Single factory app, no OTA") there should be way enough space to store it (even if OS uses some nvs too). So now I wonder if NVS checks remaining space properly when value is replaced for the existing key
Although what bothers me is the fact that I get this error only occasionally when updating my key-value pair.
Since this is the only kv in my program, and nvs partition size is 0x6000 ("Single factory app, no OTA") there should be way enough space to store it (even if OS uses some nvs too). So now I wonder if NVS checks remaining space properly when value is replaced for the existing key
Code: Select all
it should be
assert sizeof(key.new_value) < nvs_partition.remaining_space() - sizeof(key.old_value)
rather than
assert sizeof(key.new_value) < nvs_partition.remaining_space()
Re: nvs_set_str - max length of string
If you make a dump of nvs partition using 'epstool.py read_flash' command, i can help check what you have in your nvs partition.
The proposal about size calculation makes sense, but this is not how nvs works. One of the design principles of nvs is that there should be no possibility of data loss due to a power off event. Therefore if new data has to be written, it is written first, and then the old data is erased.
Looking at the code again, I see that NVS might be a bit pessimistic in some cases when huge key-value pairs are written... The algorithm was optimized mostly for smaller sizes.
It this point I recommend to see if you can split the data into multiple key-value pairs instead of storing it in one string. I'll put the issue with large key-value pairs onto a list of improvements for the next version of NVS.
The proposal about size calculation makes sense, but this is not how nvs works. One of the design principles of nvs is that there should be no possibility of data loss due to a power off event. Therefore if new data has to be written, it is written first, and then the old data is erased.
Looking at the code again, I see that NVS might be a bit pessimistic in some cases when huge key-value pairs are written... The algorithm was optimized mostly for smaller sizes.
It this point I recommend to see if you can split the data into multiple key-value pairs instead of storing it in one string. I'll put the issue with large key-value pairs onto a list of improvements for the next version of NVS.
Who is online
Users browsing this forum: MicroController and 96 guests