NVS abstraction layer.
More...
#include "esp_err.h"
#include "nvs_flash.h"
Go to the source code of this file.
NVS abstraction layer.
- Author
- Abanoub Salah
- Designed to decouple application logic from ESP-NVS by abstracting function calls
- Data integrity by CRC16-Modbus checking when saving/loading data
◆ NVS_MANAGER_MAX_MQTT_PASSWORD_SIZE
| #define NVS_MANAGER_MAX_MQTT_PASSWORD_SIZE (64) |
NVS key size of MQTT password
◆ NVS_MANAGER_MAX_MQTT_URI_SIZE
| #define NVS_MANAGER_MAX_MQTT_URI_SIZE (128) |
◆ NVS_MANAGER_MAX_MQTT_USER_SIZE
| #define NVS_MANAGER_MAX_MQTT_USER_SIZE (64) |
NVS key size of MQTT user
◆ NVS_MANAGER_MAX_WIFI_PASSWORD_SIZE
| #define NVS_MANAGER_MAX_WIFI_PASSWORD_SIZE (64) |
NVS key size of WiFi password
◆ NVS_MANAGER_MAX_WIFI_SSID_SIZE
| #define NVS_MANAGER_MAX_WIFI_SSID_SIZE (32) |
NVS key size of WiFi SSID
◆ nvs_keys_t
NVS manager keys enum.
| Enumerator |
|---|
| NVS_MANAGER_KEYS_WIFI_SSID | WiFi SSID
|
| NVS_MANAGER_KEYS_WIFI_PASS | WiFi password
|
| NVS_MANAGER_KEYS_MQTT_URI | MQTT URI
|
| NVS_MANAGER_KEYS_MQTT_USER | MQTT user
|
| NVS_MANAGER_KEYS_MQTT_PASS | MQTT password
|
| NVS_MANAGER_KEYS_BB_WRITE_OFFSET | Blackbox Logger write offset
|
| NVS_MANAGER_KEYS_BB_REPLAY_OFFSET | Blackbox Logger replay offset
|
| NVS_MANAGER_KEYS_BB_LAST_ID | Blackbox Logger last ID
|
| NVS_MANAGER_KEYS_MAX | Keys count
|
◆ nvs_manager_deinit()
| void nvs_manager_deinit |
( |
void |
| ) |
|
Deinitialize NVS manager.
Deinitialize NVS manager by commit data, close handle, delete timer and deinit flash
◆ nvs_manager_flush_cfg()
| esp_err_t nvs_manager_flush_cfg |
( |
void |
| ) |
|
Flush configuration structure to flash.
- Returns
- esp_err_t Flush result
- Return values
-
| ESP_OK | Flush success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| any | Any error from down layers propagates upward |
◆ nvs_manager_init()
Initialize NVS manager.
Initialize NVS manager by calling flash init, if succeeded load config, If failed with 'flash full' or 'new NVS version' erase flash then try to call flash init again. Finally initiate periodic timer to commit configuration if it was flagged dirty and newer than shadow structure
- Parameters
-
| ops_ptr | Pointer to NVS manager operations structure |
- Returns
- esp_err_t Initialize result
- Return values
-
| ESP_OK | Initialize success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| any | Any error from down layers propagates upward |
- Note
- Assumes default name for NVS partition typically 'nvs'
-
WARNING: If there are no free-pages or NVS-full NVS partition gets erased
◆ nvs_manager_read_cfg()
| esp_err_t nvs_manager_read_cfg |
( |
nvs_keys_t |
key, |
|
|
void * |
value_void_ptr |
|
) |
| |
Read configuration from flash.
Read configuration from flash cached in configuration structure
- Parameters
-
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Pointer to data |
- Returns
- esp_err_t Read result
- Return values
-
| ESP_OK | Read success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
◆ nvs_manager_set_default()
| esp_err_t nvs_manager_set_default |
( |
nvs_keys_t |
key, |
|
|
const void * |
value_void_ptr, |
|
|
size_t |
value_size |
|
) |
| |
Set configuration default.
Set configuration default values in case it was missing from flash
- Parameters
-
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Pointer to data |
| value_size | Value size |
- Returns
- esp_err_t Set result
- Return values
-
| ESP_OK | Set success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
- Note
- Defaults has no effect after initialization it should be used before initialization
◆ nvs_manager_write_cfg()
| esp_err_t nvs_manager_write_cfg |
( |
nvs_keys_t |
key, |
|
|
const void * |
value_void_ptr, |
|
|
size_t |
value_size |
|
) |
| |
Write configuration to flash.
Write configuration to flash by writing to configuration structure and flush it when preset time has passed
- Parameters
-
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Pointer to data |
| value_size | Value size |
- Returns
- esp_err_t Write result
- Return values
-
| ESP_OK | Write success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |