|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
Non-Volatile Storage handle. More...
Classes | |
| class | error_category |
| Error category for NVS errors. More... | |
| class | flash |
Public Types | |
| enum class | errc : esp_err_t { not_initialized = 0x1101 , not_found = 0x1102 , type_mismatch = 0x1103 , read_only = 0x1104 , not_enough_space = 0x1105 , invalid_name = 0x1106 , invalid_handle = 0x1107 , remove_failed = 0x1108 , key_too_long = 0x1109 , invalid_state = 0x110b , invalid_length = 0x110c , no_free_pages = 0x110d , value_too_long = 0x110e , part_not_found = 0x110f , new_version_found = 0x1110 , xts_encr_failed = 0x1111 , xts_decr_failed = 0x1112 , xts_cfg_failed = 0x1113 , xts_cfg_not_found = 0x1114 , encr_not_supported = 0x1115 , keys_not_initialized = 0x1116 , corrupt_key_part = 0x1117 , wrong_encryption = 0x1119 } |
| Error codes for NVS operations. More... | |
Public Member Functions | |
| nvs (std::string_view namespace_name, bool read_only=false) | |
| Opens a NVS namespace. | |
| nvs (const partition &part, std::string_view namespace_name, bool read_only=false) | |
| Opens a NVS namespace on a specific partition. | |
| ~nvs () | |
| nvs (const nvs &)=delete | |
| nvs & | operator= (const nvs &)=delete |
| nvs (nvs &&other) noexcept | |
| Move constructor. | |
| nvs & | operator= (nvs &&other) noexcept |
| Move assignment. | |
| bool | is_writeable () const |
| Returns true if the handle allows writes. | |
| void | commit () |
| Commits pending changes to flash. | |
| void | erase (std::string_view key) |
| Erases a key. | |
| void | erase_all () |
| Erases all keys in the namespace. | |
| void | set_string (std::string_view key, std::string_view value) |
| Stores a string. | |
| std::string | get_string (std::string_view key) |
| Retrieves a string. | |
| void | set_blob (std::string_view key, const void *data, size_t length) |
| Stores binary data. | |
| void | set_blob (std::string_view key, std::span< const uint8_t > data) |
| Stores binary data. | |
| std::vector< uint8_t > | get_blob (std::string_view key) |
| Retrieves binary data. | |
| template<typename T > requires sized_integral<T> | |
| void | set_value (std::string_view key, T value) |
| Stores an integer value. | |
| template<typename T > requires sized_integral<T> | |
| T | get_value (std::string_view key) |
| Retrieves an integer value. | |
| result< void > | try_commit () |
| Commits pending changes to flash. | |
| result< void > | try_erase (std::string_view key) |
| Erases a key. | |
| result< void > | try_erase_all () |
| Erases all keys in the namespace. | |
| result< void > | try_set_string (std::string_view key, std::string_view value) |
| Stores a string. | |
| result< std::string > | try_get_string (std::string_view key) |
| Retrieves a string. | |
| result< void > | try_set_blob (std::string_view key, const void *data, size_t length) |
| Stores binary data. | |
| result< void > | try_set_blob (std::string_view key, std::span< const uint8_t > data) |
| Stores binary data. | |
| result< std::vector< uint8_t > > | try_get_blob (std::string_view key) |
| Retrieves binary data. | |
| template<typename T > requires sized_integral<T> | |
| result< void > | try_set_value (std::string_view key, T value) |
| Stores an integer value. | |
| template<typename T > requires sized_integral<T> | |
| result< T > | try_get_value (std::string_view key) |
| Retrieves an integer value. | |
Static Public Member Functions | |
| static result< nvs > | make (std::string_view namespace_name, bool read_only=false) |
| Opens a NVS namespace. | |
| static result< nvs > | make (const partition &part, std::string_view namespace_name, bool read_only=false) |
| Opens a NVS namespace on a specific partition. | |
Non-Volatile Storage handle.
Provides persistent key-value storage in flash memory. Supports strings, binary blobs, and integer types from 8 to 64 bits.
This type is non-copyable and move-only. Result-returning methods on a moved-from object return nvs::errc::invalid_handle. Simple accessors return default values.
Changes are not persisted until commit() is called.
|
strong |
Error codes for NVS operations.
| Enumerator | |
|---|---|
| not_initialized | NVS storage was not initialized. Call nvs::flash::init() first. |
| not_found | A requested entry couldn’t be found or namespace doesn’t exist yet and mode is NVS_READONLY |
| type_mismatch | The type of set or get operation doesn't match the type of value stored in NVS |
| read_only | Storage handle was opened as read only |
| not_enough_space | There is not enough space in the underlying storage to save the value |
| invalid_name | Namespace name doesn’t satisfy constraints |
| invalid_handle | Handle has been closed or is NULL |
| remove_failed | 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. |
| key_too_long | Key name is too long |
| invalid_state | NVS is in an inconsistent state due to a previous error. Call nvs::flash::init() again and create a new nvs object. |
| invalid_length | String or blob length is not sufficient to store data |
| no_free_pages | NVS partition doesn't contain any empty pages. This may happen if NVS partition was truncated. Erase the whole partition and call nvs::flash::init() again. |
| value_too_long | Value doesn't fit into the entry or string or blob length is longer than supported by the implementation |
| part_not_found | Partition with specified name is not found in the partition table |
| new_version_found | NVS partition contains data in new format and cannot be recognized by this version of code |
| xts_encr_failed | XTS encryption failed while writing NVS entry |
| xts_decr_failed | XTS decryption failed while reading NVS entry |
| xts_cfg_failed | XTS configuration setting failed |
| xts_cfg_not_found | XTS configuration not found |
| encr_not_supported | NVS encryption is not supported in this version |
| keys_not_initialized | NVS key partition is uninitialized |
| corrupt_key_part | NVS key partition is corrupt |
| wrong_encryption | NVS partition is marked as encrypted with generic flash encryption. This is forbidden since the NVS encryption works differently. |
Opens a NVS namespace.
| namespace_name | Namespace name (max 15 characters). |
| read_only | If true, opens in read-only mode. |
| std::system_error | on failure. |
|
explicit |
Opens a NVS namespace on a specific partition.
| part | The partition to open NVS storage from. |
| namespace_name | Namespace name (max 15 characters). |
| read_only | If true, opens in read-only mode. |
| std::system_error | on failure. |
| idfxx::nvs::~nvs | ( | ) |
|
noexcept |
Move constructor.
Transfers handle ownership.
|
inline |
Commits pending changes to flash.
| std::system_error | on error. |
Definition at line 174 of file nvs.hpp.
References try_commit(), and idfxx::unwrap().
|
inline |
Erases a key.
| key | The key to erase. |
| std::system_error | on error. |
Definition at line 182 of file nvs.hpp.
References try_erase(), and idfxx::unwrap().
|
inline |
Erases all keys in the namespace.
| std::system_error | on error. |
Definition at line 189 of file nvs.hpp.
References try_erase_all(), and idfxx::unwrap().
|
inline |
Retrieves binary data.
| key | Key name. |
| std::system_error | on error. |
Definition at line 235 of file nvs.hpp.
References try_get_blob(), and idfxx::unwrap().
|
inline |
Retrieves a string.
| key | Key name. |
| std::system_error | on error. |
Definition at line 207 of file nvs.hpp.
References try_get_string(), and idfxx::unwrap().
|
inline |
Retrieves an integer value.
| T | Integer type (8 to 64 bits, signed or unsigned). |
| key | Key name. |
| std::system_error | on error. |
Definition at line 261 of file nvs.hpp.
References idfxx::unwrap().
|
inline |
|
static |
Opens a NVS namespace on a specific partition.
| part | The partition to open NVS storage from. |
| namespace_name | Namespace name (max 15 characters). |
| read_only | If true, opens in read-only mode. |
|
static |
Opens a NVS namespace.
| namespace_name | Namespace name (max 15 characters). |
| read_only | If true, opens in read-only mode. |
Stores binary data.
| key | Key name. |
| data | Data pointer. |
| length | Data size in bytes. |
| std::system_error | on error. |
Definition at line 217 of file nvs.hpp.
References try_set_blob(), and idfxx::unwrap().
Stores binary data.
| key | Key name. |
| data | Data to store. |
| std::system_error | on error. |
Definition at line 226 of file nvs.hpp.
References try_set_blob(), and idfxx::unwrap().
|
inline |
Stores a string.
| key | Key name. |
| value | String value. |
| std::system_error | on error. |
Definition at line 198 of file nvs.hpp.
References try_set_string(), and idfxx::unwrap().
Stores an integer value.
| T | Integer type (8 to 64 bits, signed or unsigned). |
| key | Key name. |
| value | Value to store. |
| std::system_error | on error. |
Definition at line 247 of file nvs.hpp.
References try_set_value(), and idfxx::unwrap().
Retrieves binary data.
| key | Key name. |
Referenced by get_blob().
| result< std::string > idfxx::nvs::try_get_string | ( | std::string_view | key | ) |
Retrieves a string.
| key | Key name. |
Referenced by get_string().
Retrieves an integer value.
| T | Integer type (8 to 64 bits, signed or unsigned). |
| key | Key name. |
Stores binary data.
| key | Key name. |
| data | Data pointer. |
| length | Data size in bytes. |
Referenced by set_blob(), and set_blob().
Stores binary data.
| key | Key name. |
| data | Data to store. |
Stores a string.
| key | Key name. |
| value | String value. |
Referenced by set_string().
Stores an integer value.
| T | Integer type (8 to 64 bits, signed or unsigned). |
| key | Key name. |
| value | Value to store. |
Referenced by set_value().