nvs_entry_find Getting ERROR:ESP_ERR_INVALID_ARG

Zeni241
Posts: 86
Joined: Tue Nov 20, 2018 4:28 am

nvs_entry_find Getting ERROR:ESP_ERR_INVALID_ARG

Postby Zeni241 » Tue Aug 01, 2023 9:39 am

I am trying to use the bellow code to find an entry in my NVS storage but I am getting error: ESP_ERR_INVALID_ARG.
My partition table is:

Code: Select all

#
# Name	   Type	 SubType	 Offset	   Size	 Flags
	 
nvs	      data	 nvs		   0x6000
otadata	      data	    ota		   0x2000
ota_0	       app	  ota_0	   	   0x180000	
ota_1	       app	  ota_1	   	   0x180000	
storage	       data	  spiffs	   0x6000


Code: Select all

Code:
const char *nswifi = "nswifi";
nvs_handle_t nwifi; 


void mysearch()
{
    err = nvs_open(nswifi, NVS_READWRITE, &nwifi);
    if (err != ESP_OK)
    {
        printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
        return;
    }
    else
    {
        nvs_iterator_t it = NULL;

        esp_err_t res = nvs_entry_find(NULL, nswifi, 0x01, &it);
        while (res == ESP_OK)
        {
            nvs_entry_info_t info;
            nvs_entry_info(it, &info); // Can omit error check if parameters are guaranteed to be non-NULL
            printf("key '%s', type '%d' \n", info.key, info.type);
            res = nvs_entry_next(&it);
        }

        ESP_LOGE(TAG, "Error: %s", esp_err_to_name(res));

        nvs_release_iterator(it);
    }
}
I keep on getting error: E (3607) scan: Error: ESP_ERR_INVALID_ARG
I couldn’t figure out which argument is invalid in the code.

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: nvs_entry_find Getting ERROR:ESP_ERR_INVALID_ARG

Postby MicroController » Tue Aug 01, 2023 10:49 am

nvs_entry_find(...):

Code: Select all

esp_err_t nvs_entry_find(const char *part_name, const char *namespace_name, nvs_type_t type, nvs_iterator_t *output_iterator)
{
    if (part_name == nullptr || output_iterator == nullptr) {
        return ESP_ERR_INVALID_ARG;
    }
You need to pass it a partition name, not NULL.

Zeni241
Posts: 86
Joined: Tue Nov 20, 2018 4:28 am

Re: nvs_entry_find Getting ERROR:ESP_ERR_INVALID_ARG

Postby Zeni241 » Tue Aug 01, 2023 12:22 pm

Thanks MicroController for your quick response.

In fact somewhere in ESP-IDF documentation its written that
part_name – [in] Partition name NVS in the partition table. If pass a NULL than will use NVS_DEFAULT_PART_NAME (“nvs”).
Anyway I changed the code as bellow and its working fine.

Code: Select all


const char *nswifi = "nswifi";
nvs_handle_t nwifi; 

 err = nvs_open(nswifi, NVS_READWRITE, &nwifi);
    if (err != ESP_OK)
    {
        printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
        return;
    }
    else
    {
        nvs_iterator_t it = NULL;
        esp_err_t res = nvs_entry_find(NVS_DEFAULT_PART_NAME, nswifi, NVS_TYPE_ANY, &it);
        if (res != ESP_OK)
        {
            ESP_LOGE(TAG, "Error: %s", esp_err_to_name(res));
        }
        else
        {
            while (res == ESP_OK)
            {
                nvs_entry_info_t info;
                nvs_entry_info(it, &info); // Can omit error check if parameters are guaranteed to be non-NULL
                printf("key '%s', type '%d' \n", info.key, info.type);
                res = nvs_entry_next(&it);
            }
        }
        nvs_release_iterator(it);
    }
Thanks again.

Who is online

Users browsing this forum: No registered users and 231 guests