Skip to content

app_main: add 5 s BOOT-button factory reset to recover commissioning …#47

Merged
GuvHas merged 2 commits intomainfrom
claude/review-esp32-thread-code-EsKdn
Mar 20, 2026
Merged

app_main: add 5 s BOOT-button factory reset to recover commissioning …#47
GuvHas merged 2 commits intomainfrom
claude/review-esp32-thread-code-EsKdn

Conversation

@GuvHas
Copy link
Copy Markdown
Owner

@GuvHas GuvHas commented Mar 20, 2026

If GPIO9 (BOOT button, active-low) is held at startup for 5 s, erase nvs_matter and reboot. This clears the fabric table, PAKE verifier, ACL and group keys, returning the device to commissioning mode so that BLE advertising restarts and Home Assistant can rediscover the device.

Release the button within 5 s to cancel without side-effects.

…mode

If GPIO9 (BOOT button, active-low) is held at startup for 5 s, erase
nvs_matter and reboot.  This clears the fabric table, PAKE verifier,
ACL and group keys, returning the device to commissioning mode so that
BLE advertising restarts and Home Assistant can rediscover the device.

Release the button within 5 s to cancel without side-effects.

https://claude.ai/code/session_01SxqAiQApiRTwXefk9aQ6bR
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c90aac85bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ESP_LOGW(kTag, "Factory reset in %d s…", i - 1);
}
ESP_LOGW(kTag, "Erasing nvs_matter — device will reboot into commissioning mode");
nvs_flash_erase_partition("nvs_matter");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid erasing CHIP factory namespace during BOOT reset

nvs_flash_erase_partition("nvs_matter") wipes the entire Matter partition, but this repo routes all Matter namespaces (CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL, CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION_LABEL, and CONFIG_ESP_MATTER_NVS_PART_NAME) to nvs_matter in sdkconfig.defaults (lines 47-49), with factory credentials described as write-once data (lines 33-35). In environments where those factory entries are not automatically reprovisioned, holding BOOT for this recovery path will also delete setup/attestation material and can leave the node unable to commission again; this reset path should clear only fabric/config state (or call the platform factory-reset API) instead of erasing the whole partition.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The partition is mounted first via nvs_flash_init_partition, then each namespace is opened and cleared individually with nvs_erase_all + nvs_commit. The chip-factory namespace is never touched.

…p-factory

Replacing nvs_flash_erase_partition("nvs_matter") with targeted NVS
namespace erases: chip-config (fabric table, ACL, group keys, subscriptions)
and chip-counters are cleared, but chip-factory (discriminator, PAKE
verifier, DAC) is preserved.

Erasing the whole partition deleted write-once attestation material that
cannot be recovered without re-flashing, leaving the device unable to
commission again.

https://claude.ai/code/session_01SxqAiQApiRTwXefk9aQ6bR
@GuvHas GuvHas merged commit ddb0fd9 into main Mar 20, 2026
1 check passed
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.

2 participants