nvs_set_str() causes exception resulting in reboot

raadiy@yahoo.com
Posts: 6
Joined: Sat Oct 06, 2018 1:02 am

nvs_set_str() causes exception resulting in reboot

Postby raadiy@yahoo.com » Sun Nov 04, 2018 1:43 pm

Hi, I find that writing to NVS the first time, is successfull, using nvs_set_str(), but a later update of the the value causes an exception. I saw few other posts on this subject, but did not find a way out of this issue. Is this a known issue? Does any one else have the same issue?

Here is the exception and code snippet:

exception:
D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/freertos/queue.c:1442 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x40091ce1 on core 0
0x40091ce1: xQueueGenericReceive at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/freertos/queue.c:2037


Backtrace: 0x400934ec:0x3ffdbc60 0x40093719:0x3ffdbc80 0x40091ce1:0x3ffdbca0 0x400e3a89:0x3ffdbce0 0x400d4672:0x3ffdbd20 0x400d447c:0x3ffdbd50 0x400d538d:0x3ffdbd80 0x4014aee3:0x3ffdc1c0 0x4014ab1d:0x3ffdc1f0 0x4014ab69:0x3ff
dc280 0x4014bc1c:0x3ffdc2a0 0x4014b628:0x3ffdc2c0 0x4014b69c:0x3ffdc300 0x40091431:0x3ffdc320
0x400934ec: invoke_abort at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp32/panic.c:680

0x40093719: abort at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp32/panic.c:680

0x40091ce1: xQueueGenericReceive at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/freertos/queue.c:2037

0x400e3a89: nvs::Lock::Lock() at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/nvs_flash/src/nvs_api.cpp:486
(inlined by) nvs_set_str at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/nvs_flash/src/nvs_api.cpp:412

0x400d4672: ssb_nvs_write at D:/raadiy/esp32/msys32/home/raadiy/esp/test_app/main/ssb_nvs.c:70

0x400d447c: ssb_change_label at D:/raadiy/esp32/msys32/home/raadiy/esp/test_app/main/ssb_util.c:116

0x400d538d: ssb_post_handler at D:/raadiy/esp32/msys32/home/raadiy/esp/test_app/main/ssb_wifi.c:174

0x4014aee3: httpd_uri at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp_http_server/src/httpd_uri.c:216

0x4014ab1d: httpd_parse_req at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp_http_server/src/httpd_parse.c:706

0x4014ab69: httpd_req_new at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp_http_server/src/httpd_parse.c:706

0x4014bc1c: httpd_sess_process at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp_http_server/src/httpd_sess.c:188

0x4014b628: httpd_server at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp_http_server/src/httpd_main.c:185

0x4014b69c: httpd_thread at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/esp_http_server/src/httpd_main.c:215

0x40091431: vPortTaskWrapper at D:/raadiy/esp32/msys32/home/raadiy/esp/esp-idf/components/freertos/port.c:403


Code: Select all

int ssb_nvs_write(char *key, char *value)
{
      esp_err_t err;

//    if (nvs_erase_key(ssb_nvs_handle, key) == ESP_OK)
//        nvs_commit(ssb_nvs_handle);

    err = nvs_set_str(ssb_nvs_handle, key, value);                                 /* <-----------------------------Line 70 */

    switch (err)
    {
        case ESP_OK:
        {
            ESP_LOGI(SSB_DEVICE, "Successfully wrote tag <%s>: value <%s>", key, value);
            nvs_commit(ssb_nvs_handle);
            ESP_LOGI(SSB_DEVICE, "Committed changes");
            return SSB_SUCCESS;
        }
        default :
        	ESP_LOGE(SSB_DEVICE, "Error (%s) writing!\n", esp_err_to_name(err));
    }

    return SSB_FAILURE;
}

Thanks in advance

krishnatejakvs
Posts: 1
Joined: Thu Nov 29, 2018 11:11 am

Re: nvs_set_str() causes exception resulting in reboot

Postby krishnatejakvs » Thu Nov 29, 2018 11:19 am

Hi,

esp32 nvs expects string to be zero terminated. add the last character to the string to '\0' like value[lengthofvalue] = '\0';and then call nvs_set_str();

Ps: erase the nvs before starting with above changes

Hope it helps.

raadiy@yahoo.com
Posts: 6
Joined: Sat Oct 06, 2018 1:02 am

Re: nvs_set_str() causes exception resulting in reboot

Postby raadiy@yahoo.com » Thu Dec 06, 2018 10:46 am

Hi Krishnateja,

The strings I use are null terminated. I upgraded to a new version of ESP-IDF and it resolved the problem.

Thanks

Who is online

Users browsing this forum: No registered users and 137 guests