NeuStorage is a high-performance, lightweight NVS (Non-Volatile Storage) wrapper for ESP32. It is designed to be simple for beginners while providing advanced power for professionals by utilizing C++ templates and avoiding the overhead of the String class.
- No String Overhead: Completely avoids
Stringclass to prevent memory fragmentation. - Zero Dynamic Allocation: Uses binary blobs for maximum speed and stability.
- Type Safety: Includes
static_assertto prevent saving incompatible data types (like pointers). - Powerfull Templates: Save and load entire
structsor arrays in a single line. - Beginner Friendly: Provides simple
putInt,putFloat, andputBoolshortcuts. - Auto-Initialization: Automatically handles NVS flash initialization and error recovery.
- In the Arduino IDE, go to Sketch > Include Library > Manage Libraries...
- Search for NeuStorage
- Click Install
lib_deps = ulywae/NeuStorage- Download the repository as
.zip - Open Arduino IDE
- Go to Sketch > Include Library > Add .ZIP Library
- Select the downloaded file
#include <NeuStorage.h>
void setup() {
NeuStorage.begin();
// Save data
NeuStorage.putInt("boot_count", 10);
// Get data with default value fallback
int boots = NeuStorage.getInt("boot_count", 0);
NeuStorage.end(); // Always call end() to commit changes
}struct Config {
float threshold;
bool alarmEnabled;
};
void saveConfig() {
NeuStorage.begin();
Config myCfg = {25.5f, true};
NeuStorage.put("sys_cfg", myCfg); // Saves the whole struct
NeuStorage.end();
}| Method | Description |
|---|---|
begin() |
Opens the default namespace and initializes flash hardware. |
isExists(key) |
Checks if a specific key exists in the current namespace. |
put<T>(key, val) |
Stores any trivially copyable data (struct, int, float, etc). |
get<T>(key, var) |
Retrieves data. Returns true if found, variable remains unchanged if not. |
get<T>(key, var, def) |
Retrieves data with an automatic default value fallback. |
putInt(key, val) |
Shortcut to store a 32-bit integer. |
getInt(key, def) |
Shortcut to get an integer with a default value. |
putFloat(key, val) |
Shortcut to store a float. |
getFloat(key, def) |
Shortcut to get a float with a default value. |
putBool(key, val) |
Shortcut to store a boolean. |
getBool(key, def) |
Shortcut to get a boolean with a default value. |
remove(key) |
Deletes a specific key-value pair. |
clear() |
Erases all keys within the current namespace. |
end() |
Commits pending changes and closes the NVS handle. |
To keep the library "pure" and high-performance, please note the following:
- No Pointers in Structs: You cannot store structs that contain pointers (e.g.,
char*,int*) or dynamic containers (e.g.,std::vector,std::string). Only "Trivially Copyable" data is allowed. - Key Length: NVS keys are limited to a maximum of 15 characters.
- Namespace Length: Namespace names are also limited to 15 characters.
- No Strings: This library intentionally does not support the Arduino
Stringclass to ensure memory stability. Use fixed-size char arrays (char[32]) inside your structs instead. - Flash Wear: Like all NVS operations, frequent writing in a tight loop can wear out your ESP32's flash memory. Always manage your write cycles responsibly.
Created by Ulywae (@neufa) Part of the NEU Ecosystem
This library is licensed under the MIT License.