Page 1 of 1

nvs_get_stats is giving wrong results

Posted: Sat Sep 30, 2023 8:42 am
by Chinmay_D
Hello,
I have one structure that I want to store inside nvs using nvs blob. Before setting for the first time nvs_get_stats gives a result of used entries as 1. (Probably it is storing some data data).

I used a structure as below:
  1. typedef struct struct_name{
  2.     uint32_t var1;
  3.     uint32_t var2;
  4.     uint32_t var3;
  5. }struct_name;
  1. ESP_ERROR_CHECK(nvs_open_from_partition("device_data", "device_data", NVS_READWRITE, &handle));
  2. nvs_get_stats("device_data",&nvsStats);
  3. ESP_LOGI("storage","used: %d, free: %d, total: %d, namespace count: %d", nvsStats.used_entries,
  4.                 nvsStats.free_entries, nvsStats.total_entries, nvsStats.namespace_count);
  5. esp_err_t result= nvs_get_blob(handle,DEVICE_DATA_KEY,(void *)&m_data, &size);
But after nvs_set_blob, the used entries will go from 1 to 4 even if I used nvs_set_blob only once.
Please guide for this. I have to sue used entries as I want to store these structure for 100 times sequencially with different keys. To generate keys I have to use "used entries" from nvs_get_stats.

Thanks in advance.
Chinmay.

Re: nvs_get_stats is giving wrong results

Posted: Mon Oct 02, 2023 1:02 am
by ESP_Sprite
See the docs: blobs have a variable amount of entries, plus they use some for housekeeping. Additionally, a namespace also takes up an entry.