Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reset matter? factory_reset() not working as expected (CON-693) #570

Closed
emmby opened this issue Aug 12, 2023 · 9 comments
Closed

Comments

@emmby
Copy link

emmby commented Aug 12, 2023

I'd like to reset matter when the user hits a button to enable them to reprovision onto a new matter network.

I tried calling esp_matter::factory_reset() per the app_reset example, but on next boot chip::DeviceLayer::ConfigurationMgr().IsFullyProvisioned() is still returning true.

What is the proper way to reset matter to enable reprovisioning?

@github-actions github-actions bot changed the title How to reset matter? factory_reset() not working as expected How to reset matter? factory_reset() not working as expected (CON-693) Aug 12, 2023
@emmby
Copy link
Author

emmby commented Aug 12, 2023

Switching to chip::DeviceLayer::ConfigurationMgr().InitiateFactoryReset() seems to solve the problem

@emmby emmby closed this as completed Aug 12, 2023
@shubhamdp
Copy link
Contributor

@emmby esp_matter::factory_reset() performs cleanup from esp-matter SDK and calls ConfigurationMgr().InitiateFactoryReset(). Any specific thing that is blocking the reset?

@smeisner
Copy link

One way I got this to work without relying on the ConfigurationMgr was to call nvs_erase() and nvs_init() before calling esp_matter::factory_reset();

Just be aware this also clears wifi credentials, so I clear NVS (_erase and _init), then rewrite wifi and application config (some parameters I need in my app) before calling factory_reset(). After these steps I can recommission the device again.

It's a big hammer, but it works until I can get ConfigurationMgr components included without generating linker errors (I am using the esp-arduino-matter library and it has some limitations. see Yacubane/esp32-arduino-matter#36 (comment))

@emmby
Copy link
Author

emmby commented Aug 14, 2023

Ah, the reason esp_matter::factory_reset() wasn't working for me is that it apparently was dumping core:

08:24:35.911 -> Factory resetting on button hold
08:24:36.218 -> Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1). 
08:24:36.218 -> 
08:24:36.218 -> Core  1 register dump:
08:24:36.218 -> PC      : 0x4009a266  PS      : 0x00060735  A0      : 0x80098c4e  A1      : 0x3ffbf1bc  
08:24:36.218 -> A2      : 0x3ffb6e98  A3      : 0x3ffbd0b4  A4      : 0x00000004  A5      : 0x00060723  
08:24:36.218 -> A6      : 0x00060723  A7      : 0x00000001  A8      : 0x3ffbd0b4  A9      : 0x00000001  
08:24:36.218 -> A10     : 0x3ffbd0b4  A11     : 0x00000001  A12     : 0x00000020  A13     : 0x3ffbf478  
08:24:36.251 -> A14     : 0x007bf5e8  A15     : 0x003fffff  SAR     : 0x0000000c  EXCCAUSE: 0x00000006  
08:24:36.251 -> EXCVADDR: 0x00000000  LBEG    : 0x40086085  LEND    : 0x4008608d  LCOUNT  : 0x00000027  
08:24:36.251 -> Core  1 was running in ISR context:
08:24:36.251 -> EPC1    : 0x400e4c53  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x00000000
08:24:36.251 -> 
08:24:36.283 -> 
08:24:36.283 -> Backtrace: 0x4009a263:0x3ffbf1bc |<-CORRUPTED
08:24:36.283 -> 
08:24:36.283 -> 
08:24:36.283 -> Core  0 register dump:
08:24:36.283 -> PC      : 0x4009a3fb  PS      : 0x00060f35  A0      : 0x80097a18  A1      : 0x3ffb7230  
08:24:36.283 -> A2      : 0x3ffb6ec0  A3      : 0xb33fffff  A4      : 0x0000abab  A5      : 0x00060f23  
08:24:36.283 -> A6      : 0x00060f20  A7      : 0x0000cdcd  A8      : 0x0000abab  A9      : 0xffffffff  
08:24:36.283 -> A10     : 0x00000003  A11     : 0x00060f23  A12     : 0x00060f20  A13     : 0x00060f23  
08:24:36.316 -> A14     : 0x007b6ec0  A15     : 0x003fffff  SAR     : 0x00000001  EXCCAUSE: 0x00000006  
08:24:36.316 -> EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  
08:24:36.316 -> 
08:24:36.316 -> 
08:24:36.316 -> Backtrace: 0x4009a3f8:0x3ffb7230 0x40097a15:0x3ffb7270 0x4008e6fe:0x3ffb72b0
08:24:36.316 -> 
08:24:36.316 -> 
08:24:36.316 -> 
08:24:36.316 -> 
08:24:36.316 -> ELF file SHA256: 3a814a1e502810a0
08:24:36.316 -> 
08:24:36.525 -> Rebooting...

Here are the versions I'm using:

esp32-arduino-matter-builder v1.0.0-beta6
Matter 08b13661b6
esp-matter 603296a
esp-idf v4.4.5
arduino-esp32 2.0.11

@emmby emmby reopened this Aug 14, 2023
@shubhamdp
Copy link
Contributor

@emmby If you have a backtrace that would help, because I cannot figure out anything from the hex dump.
Also, is the crash appear before or after calling esp_matter::factory_reset() ?

I don't think the problem is when calling esp_matter::factory_reset() because we regularly use that feature.

@emmby
Copy link
Author

emmby commented Aug 16, 2023

Sure, I'm happy to generate a backtrace for you if you can tell me how (especially using arduino tools).

Here's a diff of my code change:
image

The code in pink does not crash, the code in green crashes with the logs in my previous comment.

@shubhamdp
Copy link
Contributor

I see all your changes in pink other than the commented line. Is esp_matter::factory_reset() crashing? and chip::DeviceLayer::ConfigurationMgr().InitiateFactoryReset() not?

If yes, then can you please add some debug prints in factorty_reset() and see where it is crashing?

08:24:36.316 -> Backtrace: 0x4009a3f8:0x3ffb7230 0x40097a15:0x3ffb7270 0x4008e6fe:0x3ffb72b0

Backtrace contains PC:SP pairs. For mapping this backtrace to the code lines, you can use add2line with the generated .elf file. (you may have to look up to find the location of .elf file).

addr2line -e path/to/file.elf <space separated list of PCs>

@shubhamdp
Copy link
Contributor

@emmby were you able to collect the backtrace?

@dhrishi
Copy link
Collaborator

dhrishi commented Sep 30, 2023

@emmby If you are still seeing this issue, then please share the backtrace as requested

@dhrishi dhrishi closed this as completed Sep 30, 2023
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

No branches or pull requests

4 participants