Add struct-based NVS storage for ESPHome compatibility#684
Add struct-based NVS storage for ESPHome compatibility#684jesserockz with Copilot wants to merge 8 commits into
Conversation
- Created NVS partition builder module with ESP32 NVS format support - Extended Manifest interface with customFields and nvsPartition properties - Added CONFIGURATION state to install dialog - Implemented configuration form rendering with text, password, number, and checkbox fields - Integrated NVS partition generation into flash process - Configuration values are collected from form and used to build NVS partition - NVS partition is flashed alongside firmware at specified offset Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
- Created comprehensive NVS_CONFIGURATION.md documentation - Added example manifest with configuration fields - Updated README with feature overview Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
- Fix NVS key length handling to support full 15-character keys - Remove unnecessary blank line in install-dialog.ts - Update test file to use relative path for manifest - Improve test documentation Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
- Add blob type support to NVS partition builder - Implement packStruct() function for binary struct packing - Update manifest schema to support struct-based storage with numeric keys - Add struct configuration option alongside individual fields - Update buildESPHomeWiFiNVS() to use correct struct format - Add example-esphome-wifi.json with proper ESPHome configuration - Update documentation to explain struct vs individual field storage - Handle boolean to number conversion for struct fields Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
- Fix incomplete JSON in documentation - Improve boolean-to-number conversion to explicitly check numeric types - Add test functions for struct packing - Add ESPHome WiFi struct test - Add packStruct() export to test page Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
- Document blob type and struct packing features - Update manifest schema examples with both modes - Add ESPHome WiFi struct example with firmware integration - Document version changes and ESPHome compatibility fix - Update testing section with struct tests Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
|
Would it be preferred to write NVS storage over Improv? The downside is that we will not be able to scan for Wifi networks. |
In certain cases yes, this came up when discussing how to compile firmware on a different (cloud hosted) server without passing through your secrets to the builder. This would allow for the build to be clean, then utilize your own browser to embed the wifi and api encryption key into the nvs partition before flashing. It was less for general purpose web tools flashing and more for personal usage. Edit: Maybe this repo was not the best place to put something like this? maybe esptool.js could do with this feature directly? |
ESPHome stores preferences using numeric hash keys with binary structs, not individual string-keyed entries. The initial implementation stored WiFi credentials as separate
"ssid"and"password"keys, which doesn't match ESPHome'sglobal_preferences->make_preference<T>(hash)API.Changes
NVS Builder (
src/nvs-partition-builder.ts)BLOBtype support for binary data storagepackStruct()to pack multiple fields into C struct layoutpackStruct()for reuseManifest Schema (
src/const.ts)Extended
NVSPartitionConfigwith two storage modes:Install Flow (
src/install-dialog.ts)nvsPartition.structis definedUsage
ESPHome WiFi credentials (correct format):
{ "customFields": [ { "name": "wifi_ssid", "label": "WiFi SSID", "type": "text", "required": true }, { "name": "wifi_password", "label": "WiFi Password", "type": "password", "required": true } ], "nvsPartition": { "offset": 36864, "namespace": "esphome", "struct": { "key": 88491487, "fields": [ { "name": "wifi_ssid", "type": "string", "maxLength": 33 }, { "name": "wifi_password", "type": "string", "maxLength": 65 } ] } } }Matches ESPHome's
SavedWifiSettingsstruct:The
fieldsmode remains available for non-ESPHome use cases requiring individual NVS entries.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.