elrebo-de/generic_nvsflash

1.0.0

uploaded 1 year ago
NVS flash component for ESP-IDF version 6.0+ using a C++ class

Readme

# Generic NVS Flash Component

This repository contains an ESP-IDF component for the NVS flash. It runs on
any ESP32 processor and is built using the ESP-IDF build system in version 6.0.

The component is implemented as C++ class `GenericNvsFlash`.

## Connecting the component

The constructor of class `GenericNvsFlash` has three parameters:

| Parameter    | Type of Parameter | Usage                             |
|:-------------|:------------------|:----------------------------------|
| tag          | std::string       | the tag to be used in the ESP log |
| nvsNamespace | std::string | the NVS namespace to open         |
| nvsOpenMode | nvs_open_mode_t | NVS_READONLY or NVS_READWRITE     |

The constructor opens the nvsNamespace for readonly or read/write operations.
If neccesary, NVS Flash is initialized.

The destructor commits all changes and closes the connection.

# Usage

Currently only values of type std::string are supported. 
Please call me if you want to use values of other types.

Key Value pairs can be written with Method `SetStr` and read with method `GetStr`:

```C++
/* Open NVS flash Namespace "wifi" for read/write operations */
GenericNvsFlash nvsWifi(std::string("nvsWifi"), std::string("wifi"), NVS_READWRITE);

esp_err_t ret;
ret = nvsWifi.SetStr(std::string("ssid1"), std::string("myWLANssid");

std::string ssid1;
ssid1 = nvsWifi.GetStr(std::string("ssid1"), &ret);
```

## API
The API of the component is located in the include directory ```include/generic_nvsflash.hpp``` and defines the
C++ class ```GenericNvsFlash```

```C++
class GenericNvsFlash {
public:
	GenericNvsFlash(std::string tag, std::string nvsNamespace, nvs_open_mode_t nvsOpenMode);
	virtual ~GenericNvsFlash();
    std::string GetStr(std::string key, esp_err_t *ret);
    esp_err_t SetStr(std::string key, std::string outValue);

private:	
    std::string tag = "GenericNvsFlash";
    std::string nvsNamespace;
    nvs_open_mode_t nvsOpenMode;
    nvs_handle_t nvsHandle = 0;
    bool nvsNamespaceOpen = false;
};
```

# License

This component is provided under the MIT license.

The work is based on the github repository 78/esp-wifi-connect

Links

Supports all targets

Maintainer

  • Christoph Oberle <christoph.oberle@elrebo.de>
To add this component to your project, run:

idf.py add-dependency "elrebo-de/generic_nvsflash^1.0.0"

download archive

Stats

  • Archive size
    Archive size ~ 68.45 KB
  • Downloaded in total
    Downloaded in total 104 times
  • Weekly Downloads Weekly Downloads (All Versions)
  • Downloaded this version
    This version: 10 times

Badge

elrebo-de/generic_nvsflash version: 1.0.0
|