Espressif ESP32-S2 Programming Manual page 728

Table of Contents

Advertisement

Chapter 2. API Reference
• [in] handle: Handle obtained from nvs_open function.
• [in] key: Key name. Maximal length is (NVS_KEY_NAME_MAX_SIZE-1) characters.
Shouldn't be empty.
• out_value: Pointer to the output value. May be NULL for nvs_get_str and nvs_get_blob, in this
case required length will be returned in length argument.
esp_err_t nvs_get_u8(nvs_handle_t
get uint8_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_i16(nvs_handle_t
get int16_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_u16(nvs_handle_t
get uint16_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_i32(nvs_handle_t
get int32_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_u32(nvs_handle_t
get uint32_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_i64(nvs_handle_t
get int64_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_u64(nvs_handle_t
get uint64_t value for given key
This function is the same as nvs_get_i8 except for the data type.
esp_err_t nvs_get_str(nvs_handle_t
get string value for given key
These functions retrieve the data of an entry, given its key. If key does not exist, or the requested variable type
doesn't match the type which was used when setting a value, an error is returned.
In case of any error, out_value is not modified.
All functions expect out_value to be a pointer to an already allocated variable of the given type.
nvs_get_str and nvs_get_blob functions support WinAPI-style length queries. To get the size necessary to
store the value, call nvs_get_str or nvs_get_blob with zero out_value and non-zero pointer to length. Variable
pointed to by length argument will be set to the required length. For nvs_get_str, this length includes the zero
terminator. When calling nvs_get_str and nvs_get_blob with non-zero out_value, length has to be non-zero and
has to point to the length available in out_value. It is suggested that nvs_get/set_str is used for zero-terminated
C strings, and nvs_get/set_blob used for arbitrary data structures.
// Example (without error checking) of using nvs_get_str to get a string
dynamic array:
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);
// Example (without error checking) of using nvs_get_blob to get a binary data
into a static array:
uint8_t mac_addr[6];
Espressif Systems
handle, const char *key, uint8_t *out_value)
handle, const char *key, int16_t *out_value)
handle, const char *key, uint16_t *out_value)
handle, const char *key, int32_t *out_value)
handle, const char *key, uint32_t *out_value)
handle, const char *key, int64_t *out_value)
handle, const char *key, uint64_t *out_value)
handle, const char *key, char *out_value, size_t *length)
717
Submit Document Feedback
into␣
(continues on next page)
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF