Coder Social home page Coder Social logo

arduinonvs's Introduction

Arduino NVS Library

Summary

Arduino NVS is a port for a non-volatile storage (NVS, flash) library for ESP32 to the Arduino Platform. It wraps main NVS functionality into the Arduino-styled C++ class. This lib is inspired and based on TridentTD_ESP32NVS work. This lib is a further development of it, contains a lot of improvements, bugfixes and translation (original text was published on Thai).

Introduction

NVS lib (commonly mentioned as "flash lib") is a library used for storing data values in the flash memory in the ESP32. Data are stored in a non-volatile manner, so it is remaining in the memory after power-out or reboot of the ESP32.

The ESP32 NVS stored data in the form of key-value. Keys are ASCII strings, up to 15 characters. Values can have one of the following types:

  • integer types: uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  • zero-terminated string
  • variable length binary data (blob)

Refer to the NVS ESP32 lib original documentation for a details about internal NVS lib organization.

Usage

Include the library header: #include <ArduinoNvs.h>

Then init the NVS with the command: NVS.begin();

  

Save data in NVS

bool ok; 
ok = NVS.setInt ("myInt", 23); // Stores the integer value 23 into the key named "myInt" on the NVS

String data1 = "Hello String";
ok = NVS.setString ("myString", data); // Store the data value into the key named "myString" on the NVS

Load data from NVS

int i = NVS.getInt ("myInt"); // Read the value of the key "myInt" from the NVS

String str = NVS.getString ("myString"); // Read the value of the "myString" key from the NVS 

Binary-like Objects

Storing variables other than the basic types are performed through serializing it to the blob/array form (std::vector<uint8_t> is recommended).

Store blob

uint8_t mac [6] = {0xDF, 0xEE, 0x10, 0x49, 0xA1, 0x42};
bool ok = NVS.setBlob("mac", f, sizeof(f)); // store mac [6] to key "MAC" on NVS

Load blob

size_t blobLength = NVS.getBlobSize("mac"); // retrievenig size of stored blob
uint8_t mymac[blobLength];
bool ok = NVS.getBlob("mac", mymac, sizeof(mymac));
Serial.printf ("mac:% 02X:% 02X:% 02X:% 02X:% 02X:% 02X \ n",
               mymac [1], mymac [2], mymac [3], mymac [4], mymac [5]);              

Namespaces

ArduinoNvs Library suports ESP32 Namespaces

The default namespace is "storage". To store data in the separate namaspace, use its name in the begin() parameter:

ArduinoNvs mynvs;
mynvs.begin("customNs");

All subsequent store/load with mynvs object will be performed in "customNs" namespace:

String dataSt = "Namespace String";
mynvs.setString ("myString", dataSt); // this string is stored in "customNs" namespace

Authors

  1. dRKr, Sinai RnD ([email protected])
  2. (original version) TridentTD (https://github.com/TridentTD/)

arduinonvs's People

Contributors

cmeldas-silixcon avatar rpolitex avatar tridenttd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.