Chapter 2. API Reference
• other error codes from the underlying storage driver
Parameters
• [in] part_name: Label (name) of the partition of interest for object read/write/erase
• [in] name: Namespace name. Maximal length is (NVS_KEY_NAME_MAX_SIZE-1) charac-
ters. Shouldn’t be empty.
• [in] open_mode: NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will
open a handle for reading only. All write requests will be rejected for this handle.
• [out] out_handle: If successful (return code is zero), handle will be returned in this argument.
esp_err_t nvs_set_blob(nvs_handle_t handle, const char *key, const void *value, size_t length)
set variable length binary value for given key
This family of functions set value for the key, given its name. Note that actual storage will not be updated until
nvs_commit function 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 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.
• [in] length: length of binary value to set, in bytes; Maximum length is 508000 bytes or (97.6%
of the partition size - 4000) bytes whichever is lower.
esp_err_t nvs_erase_key(nvs_handle_t handle, const char *key)
Erase key-value pair with given key name.
Note that actual storage may not be updated until nvs_commit function is called.
Return
• ESP_OK if erase operation was successful
• ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
• ESP_ERR_NVS_READ_ONLY if handle was opened as read only
• ESP_ERR_NVS_NOT_FOUND if the requested key doesn’t exist
• other error codes from the underlying storage driver
Parameters
• [in] handle: Storage handle obtained with nvs_open. 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.
esp_err_t nvs_erase_all(nvs_handle_t handle)
Erase all key-value pairs in a namespace.
Note that actual storage may not be updated until nvs_commit function is called.
Return
• ESP_OK if erase operation was successful
• ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
• ESP_ERR_NVS_READ_ONLY if handle was opened as read only
• other error codes from the underlying storage driver
Parameters
Espressif Systems 719
Submit Document Feedback
Release v4.4