I there,
I have a problem with the "nvs.h" library. I can't understanding the mining of "my_hadle".
I need to save two strings with 50 to 100 bytes each, and read them.
I'm trying to understanding how...
"""
size_t required_size;
nvs_get_str((my_handle, "server_name", NULL, &required_size);
char* server_name = malloc(required_size);
nvs_get_str((my_handle, "server_name", server_name, &required_size);
"""
works, can some one explain to me
thanks
nvs_get_str(my_handle, "server_name", NULL, &required_size);
Re: nvs_get_str(my_handle, "server_name", NULL, &required_size);
When you want to save a value in NVS storage ... you save it as a name/value pair. For example:
name: password
value: passw0rd
I think that is pretty clear. However, imagine you have multiple libraries that are linked together to build an application. If these libraries need to read and write NVS, they could easily "step on each other". For example, if I have a library called "webserver" that saves "password" key for access to the webserver and another library called "WiFi" that saves the network password ... then we are in trouble because these two independently written libraries don't know about each other and then collide on the name.
This is where a "namespace" comes into play. A namespace is a "logical" grouping of name/value pairs. When we write libraries, we can allocate to that library a unique/distinct namespace and then within that namespace, the library can be assured that there will be no collisions. For example, the webserver library might have a namespace of "webserver" while the WiFi might have a namespace of "WiFi". What this means is that a name/value pair doesn't exist by itself, they are further qualified by a namespace. So now the data becomes:
namspace: webserver
name: password
value: passw0rd
Because it is common to work with one namespace at a time, rather than continually having to supply the namespace on each NVS API call, we have an API called "nvs_open" that opens/creates a named namespace and then returns a handle. That handle is then supplied to further API calls and the name space associated with the handle (as supplied to nvs_open) is then used.
See also:
http://esp-idf.readthedocs.io/en/latest ... flash.html
name: password
value: passw0rd
I think that is pretty clear. However, imagine you have multiple libraries that are linked together to build an application. If these libraries need to read and write NVS, they could easily "step on each other". For example, if I have a library called "webserver" that saves "password" key for access to the webserver and another library called "WiFi" that saves the network password ... then we are in trouble because these two independently written libraries don't know about each other and then collide on the name.
This is where a "namespace" comes into play. A namespace is a "logical" grouping of name/value pairs. When we write libraries, we can allocate to that library a unique/distinct namespace and then within that namespace, the library can be assured that there will be no collisions. For example, the webserver library might have a namespace of "webserver" while the WiFi might have a namespace of "WiFi". What this means is that a name/value pair doesn't exist by itself, they are further qualified by a namespace. So now the data becomes:
namspace: webserver
name: password
value: passw0rd
Because it is common to work with one namespace at a time, rather than continually having to supply the namespace on each NVS API call, we have an API called "nvs_open" that opens/creates a named namespace and then returns a handle. That handle is then supplied to further API calls and the name space associated with the handle (as supplied to nvs_open) is then used.
See also:
http://esp-idf.readthedocs.io/en/latest ... flash.html
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: nvs_get_str(my_handle, "server_name", NULL, &required_size);
Is there any example regards this particular topic?
I'm starting with esp32, and is language.
I used to use "Arduino C", for arduino family. Now I'm trying too test the ESP32, but panic is my middle name..
Thanks
I'm starting with esp32, and is language.
I used to use "Arduino C", for arduino family. Now I'm trying too test the ESP32, but panic is my middle name..
Thanks
Re: nvs_get_str(my_handle, "server_name", NULL, &required_size);
There are two examples, both are mentioned in the documentation page which Mr. Kolban has mentioned above.
https://github.com/espressif/esp-idf/tr ... s_rw_value
https://github.com/espressif/esp-idf/tr ... vs_rw_blob
(That's inside examples/storage directory of your ESP-IDF copy)
https://github.com/espressif/esp-idf/tr ... s_rw_value
https://github.com/espressif/esp-idf/tr ... vs_rw_blob
(That's inside examples/storage directory of your ESP-IDF copy)
Re: nvs_get_str(my_handle, "server_name", NULL, &required_size);
Thanks everyone for the help, it was this kind of information that I needed to realize how it works.
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot] and 113 guests