> For the complete documentation index, see [llms.txt](https://irnas.gitbook.io/opencollar/-MDJCI9OmpOqWrQzjNIR/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://irnas.gitbook.io/opencollar/-MDJCI9OmpOqWrQzjNIR/firmware/settings-module/nvs-storage.md).

# NVS storage

NVS storage system is used for permanent settings and values storage. nvs\_storage.c and nvs\_storage.h files provide user interface for accessing and storing values.

## Defines

Values and settings are stored in NVS system by their assigned ID. IDs are ordered as follows:

* Each setting, defined in Main\_settings struc is stored by setting  ID, defined in Settings.JSON file.&#x20;
  * Basic settings IDs 0x01  - 0x0F
  * Advanced settings IDs 0x11 - 0x9F
* Other values that needs to be permanently stored for fimware operation are shifted for 8 bits and start with 0x0100.

nvs\_storage.h contains list of stored values IDs, that are not part of Main\_settings:

* STORAGE\_unix\_time 0x0100
* STORAGE\_latitude  0x0101
* STORAGE\_longitude 0x0102
* STORAGE\_altitude  0x0103

## Initialisation

NVS storage is initialised with `int nvs_storage_init(void)` function, returning 0 on success or negative error code.&#x20;

## Functions

### Clearing

To clear whole NVS system, `int nvs_storage_clear(void)` function is used. To delete only single entry by ID `int nvs_storage_delete(uint16_t id)` can be used.&#x20;

### Reading and writing

To read from NVS by value ID `int nvs_storage_read(uint16_t id, const void *data, size_t len)` function returns 0 on sucess.

To write to NVS storage `int nvs_storage_write(uint16_t id, const void *data, size_t len)` function attempts to write new or existing value.&#x20;
