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

Remove all network credentials and last fabric infromation once fabric removal request received from Controller (CON-1404) #1142

Closed
bilalmalik76 opened this issue Nov 4, 2024 · 4 comments

Comments

@bilalmalik76
Copy link

How to remove all saved network credentials and start Bluetooth LE advertising once fabric removal request is received from Matter controller. The device shoyld remove all saved network credentials and only keep application-specific non-volatile data? How to achieve this with esp-matter APIs?

@github-actions github-actions bot changed the title Remove all network credentials and last fabric infromation once fabric removal request received from Controller Remove all network credentials and last fabric infromation once fabric removal request received from Controller (CON-1404) Nov 4, 2024
@pimpalemahesh
Copy link
Contributor

@bilalmalik76 To address your requirements for removing network credentials and re-enabling commissioning, there are two approaches to consider:

  1. Direct factory reset upon receiving the kFabricRemoved event. However, this method will clear all data from nvs partition and "esp_matter_kvs" namespace after factory reset.
    esp_matter::factory_reset()

  2. You can follow these steps to keep application-specific data irrespective of namespace

  • Step 1: Use the esp_wifi_restore() API to reset the Wi-Fi stack to its default values
  • Step 2: Reopen the commissioning window and restart BLE advertising to allow re-commissioning.
    chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
  • Step 3: Reboot the device
    esp_restart()

You can take reference from this code snippet:

case chip::DeviceLayer::DeviceEventType::kFabricRemoved:
        {
            ESP_LOGI(TAG, "Fabric removed successfully");
            esp_err_t err = esp_wifi_restore();
            if (err != ESP_OK) {
                ESP_LOGE(TAG, "Failed to restore wifi stack");
            }
            CHIP_ERROR error = chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
            if (error != CHIP_NO_ERROR)
            {
                ESP_LOGE(TAG, "Failed to open commissioning window");
            }
            esp_restart();
        break;
        }

@bilalmalik76
Copy link
Author

@pimpalemahesh Thank you for sharing, I will try this and let you know.

@pimpalemahesh
Copy link
Contributor

@bilalmalik76 Could you close the issue if it is resolved?

@dhrishi dhrishi closed this as completed Nov 27, 2024
@dhrishi
Copy link
Collaborator

dhrishi commented Nov 27, 2024

Closing. Please re-open in case of any issues

@dhrishi dhrishi reopened this Nov 27, 2024
@dhrishi dhrishi closed this as completed Nov 27, 2024
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

3 participants