Skip to content

Add NvramStore for router NVRAM-backed storage#65

Open
rveznaver wants to merge 2 commits intobrutella:masterfrom
rveznaver:nvram_store
Open

Add NvramStore for router NVRAM-backed storage#65
rveznaver wants to merge 2 commits intobrutella:masterfrom
rveznaver:nvram_store

Conversation

@rveznaver
Copy link

@rveznaver rveznaver commented Feb 3, 2026

Summary

Adds NvramStore, a Store implementation that uses router NVRAM for persistent storage. This is useful for running HomeKit accessories on routers with limited flash storage where filesystem-based storage isn't ideal.

Key features:

  • Configurable key prefix to support multiple independent accessories on the same router
  • Minimises flash writes by only committing to flash when pairing data changes
  • Hex-encodes binary data (configHash) for NVRAM compatibility
  • Converts pairing keys to readable UUID format to stay under NVRAM's 64-char key limit

Commit strategy

To preserve flash longevity, non-critical data (uuid, keypair, schema, version, configHash) is written to NVRAM RAM but not committed to flash. Only pairing changes trigger a flash commit. This means:

  • Normal startup: 0 flash writes
  • Per pairing added/removed: 1 flash write

If power is lost before first pairing, non-pairing data is regenerated on next startup. Once paired, the commit includes all pending changes, keeping keypair and pairing in sync.

Usage

store := hap.NewNvramStore("hap_")
server, err := hap.NewServer(store, accessory.A)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant