vshymanskyy / Preferences

Preferences library for Arduino, ESP8266, RP2040, Particle, Realtek Ameba
MIT License
76 stars 15 forks source link
arduino config configuration embedded settings storage

Preferences

Arduino Library Manager PlatformIO Registry

Provides ESP32-compatible Preferences API for a wider variety of platforms:

Available from: Arduino Library Manager, PlatformIO, Particle Build

Stand With Ukraine

How does it work?

#include <Preferences.h>
Preferences prefs;

void setup() {
  Serial.begin(115200);
  prefs.begin("my-app");

  int counter = prefs.getInt("counter", 1); // default to 1
  Serial.print("Reboot count: ");
  Serial.println(counter);
  counter++;
  prefs.putInt("counter", counter);
}

void loop() {}

Preferences are stored in the internal flash filesystem in a bunch of /nvs/{namespace}/{property} files.
Filesystem should handle flash wearing, bad sectors and atomic rename file operation.

API

Check out ESP32 Preferences library API. Differences:

[!IMPORTANT] Keys are ASCII strings. The maximum key length is 15 characters

Known issues