Chapter 2. API Reference
esp_err_t nvs_set_u32(nvs_handle_t handle, const char *key, uint32_t value)
set uint32_t value for given key
This function is the same as nvs_set_i8 except for the data type.
esp_err_t nvs_set_i64(nvs_handle_t handle, const char *key, int64_t value)
set int64_t value for given key
This function is the same as nvs_set_i8 except for the data type.
esp_err_t nvs_set_u64(nvs_handle_t handle, const char *key, uint64_t value)
set uint64_t value for given key
This function is the same as nvs_set_i8 except for the data type.
esp_err_t nvs_set_str(nvs_handle_t handle, const char *key, const char *value)
set string for given key
Set value for the key, given its name. Note that the actual storage will not be updated until nvs_commit is
called.
Return
• ESP_OK if value was set successfully
• ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
• ESP_ERR_NVS_READ_ONLY if storage handle was opened as read only
• ESP_ERR_NVS_INVALID_NAME if key name doesn’t satisfy constraints
• ESP_ERR_NVS_NOT_ENOUGH_SPACE if there is not enough space in the underlying storage
to save the value
• ESP_ERR_NVS_REMOVE_FAILED if the value wasn’t updated because flash write operation
has failed. The value was written however, and update will be finished after re-initialization of nvs,
provided that flash operation doesn’t fail again.
• ESP_ERR_NVS_VALUE_TOO_LONG if the string value is too long
Parameters
• [in] handle: Handle obtained from nvs_open function. Handles that were opened read only
cannot be used.
• [in] key: Key name. Maximal length is (NVS_KEY_NAME_MAX_SIZE-1) characters.
Shouldn’t be empty.
• [in] value: The value to set. For strings, the maximum length (including null character) is 4000
bytes, if there is one complete page free for writing. This decreases, however, if the free space is
fragmented.
esp_err_t nvs_get_i8(nvs_handle_t handle, const char *key, int8_t *out_value)
get int8_t value for given key
These functions retrieve value for the key, given its name. 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.
out_value has to be a pointer to an already allocated variable of the given type.
// Example of using nvs_get_i32:
int32_t max_buffer_size = 4096; // default value
esp_err_t err = nvs_get_i32(my_handle, "max_buffer_size", &max_buffer_size);
assert(err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND);
// if ESP_ERR_NVS_NOT_FOUND was returned, max_buffer_size will still
// have its default value.
Return
• ESP_OK if the value was retrieved successfully
• ESP_ERR_NVS_NOT_FOUND if the requested key doesn’t exist
• ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
• ESP_ERR_NVS_INVALID_NAME if key name doesn’t satisfy constraints
• ESP_ERR_NVS_INVALID_LENGTH if length is not sufficient to store data
Parameters
Espressif Systems 716
Submit Document Feedback
Release v4.4