Skip to content
Back to skills

Esp32 Nvs And Config

ASecurity

Use when settings do not survive a reboot - the key is missing after an OTA, a write fails with no space, credentials vanish, or a config change needs migrating. Covers NVS namespaces, wear, encryption and versioning.

  • 16 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
ai-agents

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 7, 2026

npx -y skills add Esmail-sarhadi/esp32-agent-skills --skill esp32-nvs-and-config --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Esp32 Nvs And Config?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Esp32 Nvs And Config
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/esmail-sarhadi-esp32-nvs-and-config/badge)](https://www.skillsdirectory.com/skills/esmail-sarhadi-esp32-nvs-and-config)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: esp32-nvs-and-config
description: Use when settings do not survive a reboot - the key is missing after an OTA, a write fails with no space, credentials vanish, or a config change needs migrating. Covers NVS namespaces, wear, encryption and versioning.
license: MIT
---

# NVS: configuration that survives

NVS is a key-value store in a flash partition, not a file system. It is small,
it is wear-levelled, and it fails in ways that a file system does not.

## What it cannot do

- Keys are limited to 15 characters; values to 4000 bytes for a blob, less when
  the partition is small (a blob must fit in about half the free space).
- No transactions across keys. Two writes are two operations; a power cut
  between them leaves the first one applied.
- No ordering guarantee for enumeration. Do not depend on the order of keys.

## The 20 kB default is smaller than it looks

The default `nvs` partition is 24 kB (20 kB usable). Each namespace has an
overhead, and NVS keeps both old and new copies of an entry until a page is
compacted. Writing a 1 kB blob every minute fills it in days and then every
write fails with `ESP_ERR_NVS_NOT_ENOUGH_SPACE` - while reads keep working, so
the firmware looks fine until the first save.

Rule: store settings, not telemetry. Counters and logs belong in a file system or
in RAM with periodic flush.

## Credentials and encryption

NVS is plaintext by default: anyone with `esptool read_flash` gets the Wi-Fi
password. If the device leaves your desk, either enable NVS encryption (which
requires flash encryption and a key partition) or do not store secrets there.

The order matters: flash encryption and the NVS key partition must be created
before the first boot that writes NVS, or you have to erase the partition and
start over.

## After an OTA, NVS survives - the layout may not

An OTA update replaces the app, not NVS. But if the new firmware uses a new
partition table with a different NVS offset, the old data is somewhere else and
reads return `NOT_FOUND`. Treat a config read failure as "first boot" and write
defaults, never as a crash.

## Versioning the schema

Add a `cfg_ver` key. On boot:

1. Read it. Missing means first boot: write defaults, set the version.
2. Older than current: run the migration, then update the version.
3. Newer than the firmware knows: this is a downgrade. Refuse to run, or reset
   to defaults - do not guess.

| Symptom | Usually |
|---|---|
| settings lost after flashing | `esptool erase_flash` erased NVS too |
| write fails, reads fine | partition full, needs `nvs_flash_erase` or a bigger partition |
| credentials readable in a dump | NVS encryption not enabled |
| value is garbage after an OTA | struct layout changed between versions |
| first boot hangs | NVS partition not in the table, `nvs_flash_init` returned an error that was ignored |

Files in this skill

  • LICENSE.txt857 B
  • SKILL.md2.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.