OpenThread_app
Loading...
Searching...
No Matches
NVS Storage Port

Abstraction layer for persistent data storage (Flash/EEPROM). More...

Macros

#define OT_APP_NVS_OK   (-1)
#define OT_APP_NVS_ERROR   (-2)
#define OT_APP_NVS_IS   (-3)
#define OT_APP_NVS_IS_NOT   (-4)
#define OT_APP_NVS_IS_NO_SPACE   (-5)

Functions

int8_t ot_app_nvs_saveString (const char *inData, const uint8_t keyId)
 Saves a string to non-volatile storage.
int8_t ot_app_nvs_readString (char *outBuff, uint8_t outBuffSize, const uint8_t keyId)
 Reads a string from non-volatile storage.
int8_t ot_app_nvs_init (void)
 Initializes the underlying NVS platform driver.
void ot_app_nvs_test ()
 Runs a simple read/write verification test.

Detailed Description

Abstraction layer for persistent data storage (Flash/EEPROM).

This module provides a unified interface for saving and retrieving configuration data that must survive a power cycle (e.g., paired devices list, network credentials). Platform Independence:

  • On ESP32, it maps to the NVS (Non-Volatile Storage) partition API.
  • On STM32, it typically maps to Flash Page emulation or external EEPROM. Key Concept: Data is accessed via a simplified numeric keyId (uint8_t), which the implementation translates into platform-specific keys or memory addresses.
Version
0.1
Date
24-10-2025
Author
Jan Łukaszewicz (plhar.nosp@m.eo@g.nosp@m.mail..nosp@m.com)

Macro Definition Documentation

◆ OT_APP_NVS_ERROR

#define OT_APP_NVS_ERROR   (-2)

◆ OT_APP_NVS_IS

#define OT_APP_NVS_IS   (-3)

◆ OT_APP_NVS_IS_NO_SPACE

#define OT_APP_NVS_IS_NO_SPACE   (-5)

◆ OT_APP_NVS_IS_NOT

#define OT_APP_NVS_IS_NOT   (-4)

◆ OT_APP_NVS_OK

#define OT_APP_NVS_OK   (-1)

Function Documentation

◆ ot_app_nvs_init()

int8_t ot_app_nvs_init ( void )

Initializes the underlying NVS platform driver.

Performs necessary hardware or middleware setup (e.g., nvs_flash_init() on ESP32). Should be called once at system startup before any read/write operations.

Returns
int8_t OT_APP_NVS_OK on success.

◆ ot_app_nvs_readString()

int8_t ot_app_nvs_readString ( char * outBuff,
uint8_t outBuffSize,
const uint8_t keyId )

Reads a string from non-volatile storage.

Retrieves data associated with the numeric key ID into the provided buffer. Ensures the output string is null-terminated.

Parameters
[out]outBuffDestination buffer.
[in]outBuffSizeSize of the destination buffer.
[in]keyIdUnique identifier of the data to read.
Returns
int8_t OT_APP_NVS_OK on success, or OT_APP_NVS_IS_NOT if key not found.

◆ ot_app_nvs_saveString()

int8_t ot_app_nvs_saveString ( const char * inData,
const uint8_t keyId )

Saves a string to non-volatile storage.

Writes a null-terminated string associated with a specific numeric key ID. If data already exists for this key, it is overwritten.

Parameters
inData[in] Pointer to the null-terminated string to save.
keyId[in] Unique identifier (0-255) for the data entry.
Returns
int8_t OT_APP_NVS_OK on success, or OT_APP_NVS_ERROR / OT_APP_NVS_IS_NO_SPACE.

◆ ot_app_nvs_test()

void ot_app_nvs_test ( )

Runs a simple read/write verification test.

Writes a set of test strings to keys 0-2, reads them back, verifies content, and then deletes/clears them. Results are printed to the log. Used for debugging storage integration.