From 11c2f668c5497e330aa3242217cd68ea64f632e5 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Thu, 12 Dec 2024 17:07:40 +0530 Subject: [PATCH] components/esp_matter_console: add the "matter esp factoryreset" "matter device factoryreset" just erases the non volatile storage of connectedhomeip SDK. This adds one more command which clears the non volatile storage of esp-matter SDK as well. --- RELEASE_NOTES.md | 5 +++ components/esp_matter_console/CMakeLists.txt | 2 +- .../esp_matter_console/esp_matter_console.h | 9 +++++ .../esp_matter_console_factory_reset.cpp | 40 +++++++++++++++++++ docs/en/developing.rst | 2 +- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 components/esp_matter_console/esp_matter_console_factory_reset.cpp diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1f5b04789..97894d396 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,8 @@ +# 27-December-2024 + +Added ``matter esp factoryreset`` command to factory reset a Matter device. +This command erases the esp-matter and connectedhomeip SDK's non-volatile storage. + # 15-Oct-2024 API Change diff --git a/components/esp_matter_console/CMakeLists.txt b/components/esp_matter_console/CMakeLists.txt index bbfad816e..159f822df 100644 --- a/components/esp_matter_console/CMakeLists.txt +++ b/components/esp_matter_console/CMakeLists.txt @@ -3,7 +3,7 @@ if (CONFIG_ENABLE_CHIP_SHELL) list(APPEND src_dirs ".") endif() -set(priv_req chip mbedtls esp_timer bt openthread) +set(priv_req chip mbedtls esp_timer bt openthread esp_matter) if ("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") list(APPEND priv_req esp_rcp_update) endif() diff --git a/components/esp_matter_console/esp_matter_console.h b/components/esp_matter_console/esp_matter_console.h index cf9454937..b513cc9cc 100644 --- a/components/esp_matter_console/esp_matter_console.h +++ b/components/esp_matter_console/esp_matter_console.h @@ -155,5 +155,14 @@ esp_err_t otcli_register_commands(); */ esp_err_t udc_register_commands(); +/** Add Factory Reset Commands + * + * Adds the default factory reset commands. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t factoryreset_register_commands(); + } // namespace console } // namespace esp_matter diff --git a/components/esp_matter_console/esp_matter_console_factory_reset.cpp b/components/esp_matter_console/esp_matter_console_factory_reset.cpp new file mode 100644 index 000000000..1156ba2a2 --- /dev/null +++ b/components/esp_matter_console/esp_matter_console_factory_reset.cpp @@ -0,0 +1,40 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +namespace esp_matter { +namespace console { + +static engine factoryreset; + +static esp_err_t factoryreset_dispatch(int argc, char *argv[]) +{ + return factory_reset(); +} + +esp_err_t factoryreset_register_commands() +{ + static const command_t command = { + .name = "factoryreset", + .description = "factoryreset the device. Usage: matter esp factoryreset.", + .handler = factoryreset_dispatch, + }; + return add_commands(&command, 1); +} +} // namespace console +} // namespace esp_matter diff --git a/docs/en/developing.rst b/docs/en/developing.rst index d0e9bbb6a..d62a24409 100644 --- a/docs/en/developing.rst +++ b/docs/en/developing.rst @@ -521,7 +521,7 @@ The console on the device can be used to run commands for testing. It is configu :: - matter device factoryreset + matter esp factoryreset - On-boarding codes: Dump the on-boarding pairing code payloads: