From bd3f00bbd2f468a21b089c9561a5007b699979ba Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Thu, 24 Apr 2025 14:42:13 +0800 Subject: [PATCH 1/2] connectedhomeip: Update connectedhomeip submodule to f6c3c8382 --- .gitlab-ci.yml | 2 +- README.md | 2 +- components/esp_matter/CMakeLists.txt | 4 +++- components/esp_matter/utils/cluster_select/Kconfig.in | 8 ++++++++ .../esp_matter/utils/cluster_select/cluster_dir.cmake | 6 ++++++ .../zap_common/app/PluginApplicationCallbacks.h | 1 + components/esp_matter/zap_common/app/callback-stub.cpp | 5 +++++ .../esp_matter/zap_common/app/cluster-init-callback.cpp | 3 +++ components/esp_matter/zap_common/zap-generated/access.h | 6 ++++++ connectedhomeip/connectedhomeip | 2 +- examples/light/sdkconfig.defaults | 3 +++ 11 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5286bc182..3a72dff21 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ variables: IDF_CHECKOUT_REF: "v5.4.1" # This variable represents the short hash of the connectedhomeip submodule. # Note: Do change this short hash on submodule update MRs. - CHIP_SHORT_HASH: "326cabf99c" + CHIP_SHORT_HASH: "f6c3c83820" DOCKER_IMAGE_NAME: "espressif/chip-idf" .add_gitlab_ssh_key: &add_gitlab_ssh_key | diff --git a/README.md b/README.md index 44c6f54c2..6e2e4c247 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ section in the ESP-Matter Programming Guide. ## Supported ESP-IDF and connectedhomeip versions -- This SDK currently works with commit [326cabf99c](https://github.com/project-chip/connectedhomeip/tree/326cabf99c) of connectedhomeip. +- This SDK currently works with commit [f6c3c83820](https://github.com/project-chip/connectedhomeip/tree/326cabf99c) of connectedhomeip. - For Matter projects development with this SDK, it is recommended to utilize ESP-IDF [v5.4.1](https://github.com/espressif/esp-idf/tree/v5.4.1). ## Documentation diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index b0d20f2d0..047b81410 100644 --- a/components/esp_matter/CMakeLists.txt +++ b/components/esp_matter/CMakeLists.txt @@ -8,6 +8,7 @@ set(SRC_DIRS_LIST "." "${MATTER_SDK_PATH}/src/app/reporting" # TODO Use esp-matter data model and remove ember codes "${MATTER_SDK_PATH}/src/data-model-providers/codegen" + "${MATTER_SDK_PATH}/src/app/server-cluster" ) set(INCLUDE_DIRS_LIST "." @@ -16,7 +17,8 @@ set(INCLUDE_DIRS_LIST "." "${MATTER_SDK_PATH}/third_party/nlfaultinjection/include" "${MATTER_SDK_PATH}/src") -set(EXCLUDE_SRCS_LIST ) +# TODO: This file has compilation errors +set(EXCLUDE_SRCS_LIST "${MATTER_SDK_PATH}/src/app/clusters/closure-control-server/closure-control-server.cpp") if (CONFIG_ESP_MATTER_ENABLE_DATA_MODEL) include("utils/cluster_select/cluster_dir.cmake") diff --git a/components/esp_matter/utils/cluster_select/Kconfig.in b/components/esp_matter/utils/cluster_select/Kconfig.in index 9d5f90945..3e09787f6 100644 --- a/components/esp_matter/utils/cluster_select/Kconfig.in +++ b/components/esp_matter/utils/cluster_select/Kconfig.in @@ -53,6 +53,10 @@ config SUPPORT_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER bool "Support BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER" default y +config SUPPORT_CAMERA_AV_SETTINGS_USER_LEVEL_MANAGEMENT_CLUSTER + bool "Support CAMERA_AV_SETTINGS_USER_LEVEL_MANAGEMENT_CLUSTER" + default y + config SUPPORT_CAMERA_AV_STREAM_MANAGEMENT_CLUSTER bool "Support CAMERA_AV_STREAM_MANAGEMENT_CLUSTER" default y @@ -77,6 +81,10 @@ config SUPPORT_CLOSURE_CONTROL_CLUSTER bool "Support CLOSURE_CONTROL_CLUSTER" default y +config SUPPORT_CLOSURE_DIMENSION_CLUSTER + bool "Support CLOSURE_DIMENSION_CLUSTER" + default y + config SUPPORT_COLOR_CONTROL_CLUSTER bool "Support COLOR_CONTROL_CLUSTER" default y diff --git a/components/esp_matter/utils/cluster_select/cluster_dir.cmake b/components/esp_matter/utils/cluster_select/cluster_dir.cmake index bace6f109..75cee0f3f 100644 --- a/components/esp_matter/utils/cluster_select/cluster_dir.cmake +++ b/components/esp_matter/utils/cluster_select/cluster_dir.cmake @@ -42,6 +42,9 @@ function(get_supported_cluster_dirs source_dirs) if(CONFIG_SUPPORT_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER) list(APPEND temp_list "${MATTER_SDK_PATH}/src/app/clusters/bridged-device-basic-information-server") endif() + if(CONFIG_SUPPORT_CAMERA_AV_SETTINGS_USER_LEVEL_MANAGEMENT_CLUSTER) + list(APPEND temp_list "${MATTER_SDK_PATH}/src/app/clusters/camera-av-settings-user-level-management-server") + endif() if(CONFIG_SUPPORT_CAMERA_AV_STREAM_MANAGEMENT_CLUSTER) list(APPEND temp_list "${MATTER_SDK_PATH}/src/app/clusters/camera-av-stream-management-server") endif() @@ -60,6 +63,9 @@ function(get_supported_cluster_dirs source_dirs) if(CONFIG_SUPPORT_CLOSURE_CONTROL_CLUSTER) list(APPEND temp_list "${MATTER_SDK_PATH}/src/app/clusters/closure-control-server") endif() + if(CONFIG_SUPPORT_CLOSURE_DIMENSION_CLUSTER) + list(APPEND temp_list "${MATTER_SDK_PATH}/src/app/clusters/closure-dimension-server") + endif() if(CONFIG_SUPPORT_COLOR_CONTROL_CLUSTER) list(APPEND temp_list "${MATTER_SDK_PATH}/src/app/clusters/color-control-server") endif() diff --git a/components/esp_matter/zap_common/app/PluginApplicationCallbacks.h b/components/esp_matter/zap_common/app/PluginApplicationCallbacks.h index a1b81b3c8..88ff22843 100644 --- a/components/esp_matter/zap_common/app/PluginApplicationCallbacks.h +++ b/components/esp_matter/zap_common/app/PluginApplicationCallbacks.h @@ -39,6 +39,7 @@ void MatterDishwasherModePluginServerInitCallback(); void MatterDoorLockPluginServerInitCallback(); void MatterEcosystemInformationPluginServerInitCallback(); void MatterElectricalEnergyMeasurementPluginServerInitCallback(); +void MatterElectricalGridConditionsPluginServerInitCallback(); void MatterElectricalPowerMeasurementPluginServerInitCallback(); void MatterEnergyEvsePluginServerInitCallback(); void MatterEnergyEvseModePluginServerInitCallback(); diff --git a/components/esp_matter/zap_common/app/callback-stub.cpp b/components/esp_matter/zap_common/app/callback-stub.cpp index ad8f4980d..150d134bd 100644 --- a/components/esp_matter/zap_common/app/callback-stub.cpp +++ b/components/esp_matter/zap_common/app/callback-stub.cpp @@ -201,6 +201,11 @@ void __attribute__((weak)) emberAfElectricalEnergyMeasurementClusterInitCallback // To prevent warning (void) endpoint; } +void __attribute__((weak)) emberAfElectricalGridConditionsClusterInitCallback(EndpointId endpoint) +{ + // To prevent warning + (void) endpoint; +} void __attribute__((weak)) emberAfElectricalPowerMeasurementClusterInitCallback(EndpointId endpoint) { // To prevent warning diff --git a/components/esp_matter/zap_common/app/cluster-init-callback.cpp b/components/esp_matter/zap_common/app/cluster-init-callback.cpp index 209b37fa7..f67b806b9 100644 --- a/components/esp_matter/zap_common/app/cluster-init-callback.cpp +++ b/components/esp_matter/zap_common/app/cluster-init-callback.cpp @@ -130,6 +130,9 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId) case app::Clusters::ElectricalEnergyMeasurement::Id: emberAfElectricalEnergyMeasurementClusterInitCallback(endpoint); break; + case app::Clusters::ElectricalGridConditions::Id: + emberAfElectricalGridConditionsClusterInitCallback(endpoint); + break; case app::Clusters::ElectricalPowerMeasurement::Id: emberAfElectricalPowerMeasurementClusterInitCallback(endpoint); break; diff --git a/components/esp_matter/zap_common/zap-generated/access.h b/components/esp_matter/zap_common/zap-generated/access.h index a4fabb5f9..6bb6faf6c 100644 --- a/components/esp_matter/zap_common/zap-generated/access.h +++ b/components/esp_matter/zap_common/zap-generated/access.h @@ -191,6 +191,7 @@ 0x0000002D, /* Cluster: Unit Localization, Attribute: TemperatureUnit, Privilege: manage */ \ 0x00000030, /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: administer */ \ 0x00000031, /* Cluster: Network Commissioning, Attribute: InterfaceEnabled, Privilege: administer */ \ + 0x00000039, /* Cluster: Bridged Device Basic Information, Attribute: NodeLabel, Privilege: manage */ \ 0x0000003F, /* Cluster: Group Key Management, Attribute: GroupKeyMap, Privilege: manage */ \ 0x00000041, /* Cluster: User Label, Attribute: LabelList, Privilege: manage */ \ 0x0000005C, /* Cluster: Smoke CO Alarm, Attribute: SmokeSensitivityLevel, Privilege: manage */ \ @@ -315,6 +316,7 @@ 0x00000000, /* Cluster: Unit Localization, Attribute: TemperatureUnit, Privilege: manage */ \ 0x00000000, /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: administer */ \ 0x00000004, /* Cluster: Network Commissioning, Attribute: InterfaceEnabled, Privilege: administer */ \ + 0x00000005, /* Cluster: Bridged Device Basic Information, Attribute: NodeLabel, Privilege: manage */ \ 0x00000000, /* Cluster: Group Key Management, Attribute: GroupKeyMap, Privilege: manage */ \ 0x00000000, /* Cluster: User Label, Attribute: LabelList, Privilege: manage */ \ 0x0000000B, /* Cluster: Smoke CO Alarm, Attribute: SmokeSensitivityLevel, Privilege: manage */ \ @@ -439,6 +441,7 @@ chip::Access::Privilege::kManage, /* Cluster: Unit Localization, Attribute: TemperatureUnit, Privilege: manage */ \ chip::Access::Privilege::kAdminister, /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: administer */ \ chip::Access::Privilege::kAdminister, /* Cluster: Network Commissioning, Attribute: InterfaceEnabled, Privilege: administer */ \ + chip::Access::Privilege::kManage, /* Cluster: Bridged Device Basic Information, Attribute: NodeLabel, Privilege: manage */ \ chip::Access::Privilege::kManage, /* Cluster: Group Key Management, Attribute: GroupKeyMap, Privilege: manage */ \ chip::Access::Privilege::kManage, /* Cluster: User Label, Attribute: LabelList, Privilege: manage */ \ chip::Access::Privilege::kManage, /* Cluster: Smoke CO Alarm, Attribute: SmokeSensitivityLevel, Privilege: manage */ \ @@ -912,6 +915,7 @@ 0x0000001F, /* Cluster: Access Control, Event: AccessControlEntryChanged, Privilege: administer */ \ 0x0000001F, /* Cluster: Access Control, Event: AccessControlExtensionChanged, Privilege: administer */ \ 0x0000001F, /* Cluster: Access Control, Event: FabricRestrictionReviewUpdate, Privilege: administer */ \ + 0x0000050E, /* Cluster: Account Login, Event: LoggedOut, Privilege: administer */ \ 0x00000751, /* Cluster: Commissioner Control, Event: CommissioningRequestResult, Privilege: manage */ \ } @@ -920,6 +924,7 @@ 0x00000000, /* Cluster: Access Control, Event: AccessControlEntryChanged, Privilege: administer */ \ 0x00000001, /* Cluster: Access Control, Event: AccessControlExtensionChanged, Privilege: administer */ \ 0x00000002, /* Cluster: Access Control, Event: FabricRestrictionReviewUpdate, Privilege: administer */ \ + 0x00000000, /* Cluster: Account Login, Event: LoggedOut, Privilege: administer */ \ 0x00000000, /* Cluster: Commissioner Control, Event: CommissioningRequestResult, Privilege: manage */ \ } @@ -928,6 +933,7 @@ chip::Access::Privilege::kAdminister, /* Cluster: Access Control, Event: AccessControlEntryChanged, Privilege: administer */ \ chip::Access::Privilege::kAdminister, /* Cluster: Access Control, Event: AccessControlExtensionChanged, Privilege: administer */ \ chip::Access::Privilege::kAdminister, /* Cluster: Access Control, Event: FabricRestrictionReviewUpdate, Privilege: administer */ \ + chip::Access::Privilege::kAdminister, /* Cluster: Account Login, Event: LoggedOut, Privilege: administer */ \ chip::Access::Privilege::kManage, /* Cluster: Commissioner Control, Event: CommissioningRequestResult, Privilege: manage */ \ } diff --git a/connectedhomeip/connectedhomeip b/connectedhomeip/connectedhomeip index 326cabf99..f6c3c8382 160000 --- a/connectedhomeip/connectedhomeip +++ b/connectedhomeip/connectedhomeip @@ -1 +1 @@ -Subproject commit 326cabf99c0cd2d8e9099ea0a5cc849c8e28dda7 +Subproject commit f6c3c8382019e623cc276e2a45b59c935e4e78f4 diff --git a/examples/light/sdkconfig.defaults b/examples/light/sdkconfig.defaults index 288b3dbcc..cd746cae3 100644 --- a/examples/light/sdkconfig.defaults +++ b/examples/light/sdkconfig.defaults @@ -50,10 +50,13 @@ CONFIG_SUPPORT_APPLICATION_LAUNCHER_CLUSTER=n CONFIG_SUPPORT_AUDIO_OUTPUT_CLUSTER=n CONFIG_SUPPORT_BOOLEAN_STATE_CONFIGURATION_CLUSTER=n CONFIG_SUPPORT_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER=n +CONFIG_SUPPORT_CAMERA_AV_SETTINGS_USER_LEVEL_MANAGEMENT_CLUSTER=n CONFIG_SUPPORT_CARBON_DIOXIDE_CONCENTRATION_MEASUREMENT_CLUSTER=n CONFIG_SUPPORT_CARBON_MONOXIDE_CONCENTRATION_MEASUREMENT_CLUSTER=n CONFIG_SUPPORT_CHANNEL_CLUSTER=n CONFIG_SUPPORT_CHIME_CLUSTER=n +CONFIG_SUPPORT_CLOSURE_CONTROL_CLUSTER=n +CONFIG_SUPPORT_CLOSURE_DIMENSION_CLUSTER=n CONFIG_SUPPORT_COMMISSIONER_CONTROL_CLUSTER=n CONFIG_SUPPORT_CONTENT_LAUNCHER_CLUSTER=n CONFIG_SUPPORT_CONTENT_CONTROL_CLUSTER=n From 850bd16974e3d032f45d32ac5493cc5aefe90823 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Thu, 24 Apr 2025 14:43:12 +0800 Subject: [PATCH 2/2] example: update light_wifi_prov to use network_provisioning and add thread support for it --- .gitlab-ci.yml | 14 ++ docs/en/faq.rst | 5 +- examples/.build-rules.yml | 8 +- .../CMakeLists.txt | 2 +- .../README.md | 23 +- .../main/CMakeLists.txt | 4 +- .../main/app_driver.cpp | 0 .../main/app_main.cpp | 46 ++-- .../main/app_network.cpp} | 208 +++++++++++++----- .../main/app_network.h} | 56 +++-- .../main/app_priv.h | 0 .../main/idf_component.yml | 2 +- .../network_prov_scheme_matter_ble.cpp} | 25 ++- .../network_prov_scheme_matter_ble.h | 29 +++ .../protocomm_matter_ble.cpp | 0 .../protocomm_matter_ble.h | 0 .../paa_cert/RainMaker-Claim-PAA-Cert.der | Bin .../partitions.csv | 0 .../sdkconfig.defaults | 3 + .../sdkconfig.defaults.esp32c3 | 0 .../sdkconfig.defaults.esp32h2 | 48 ++++ .../sdkconfig.defaults.esp32s3 | 0 .../wifi_prov_scheme_matter_ble.h | 29 --- 23 files changed, 356 insertions(+), 146 deletions(-) rename examples/{light_wifi_prov => light_network_prov}/CMakeLists.txt (98%) rename examples/{light_wifi_prov => light_network_prov}/README.md (89%) rename examples/{light_wifi_prov => light_network_prov}/main/CMakeLists.txt (62%) rename examples/{light_wifi_prov => light_network_prov}/main/app_driver.cpp (100%) rename examples/{light_wifi_prov => light_network_prov}/main/app_main.cpp (90%) rename examples/{light_wifi_prov/main/app_wifi.cpp => light_network_prov/main/app_network.cpp} (70%) rename examples/{light_wifi_prov/main/app_wifi.h => light_network_prov/main/app_network.h} (65%) rename examples/{light_wifi_prov => light_network_prov}/main/app_priv.h (100%) rename examples/{light_wifi_prov => light_network_prov}/main/idf_component.yml (88%) rename examples/{light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.cpp => light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.cpp} (85%) create mode 100644 examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.h rename examples/{light_wifi_prov/main/wifi_prov_scheme => light_network_prov/main/network_prov_scheme}/protocomm_matter_ble.cpp (100%) rename examples/{light_wifi_prov/main/wifi_prov_scheme => light_network_prov/main/network_prov_scheme}/protocomm_matter_ble.h (100%) rename examples/{light_wifi_prov => light_network_prov}/paa_cert/RainMaker-Claim-PAA-Cert.der (100%) rename examples/{light_wifi_prov => light_network_prov}/partitions.csv (100%) rename examples/{light_wifi_prov => light_network_prov}/sdkconfig.defaults (96%) rename examples/{light_wifi_prov => light_network_prov}/sdkconfig.defaults.esp32c3 (100%) create mode 100644 examples/light_network_prov/sdkconfig.defaults.esp32h2 rename examples/{light_wifi_prov => light_network_prov}/sdkconfig.defaults.esp32s3 (100%) delete mode 100644 examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.h diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3a72dff21..3f8a56a2c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -380,6 +380,20 @@ build_ext_plat_c6_thread_controller_examples: - *build_esp32c6_wifi_thread_example - *build_controller_otbr_example +build_zap_light_example: + extends: + - .build_examples_template + needs: + - job: build_image + optional: true + script: + - cd ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip + - source ./scripts/activate.sh + + - cd ${ESP_MATTER_PATH}/examples/zap_light + - idf.py set-target esp32c3 build + - idf.py set-target esp32h2 build + build_esp_matter_examples: extends: - .build_examples_template diff --git a/docs/en/faq.rst b/docs/en/faq.rst index 4b57329d0..fed1344ba 100644 --- a/docs/en/faq.rst +++ b/docs/en/faq.rst @@ -374,7 +374,7 @@ For more advanced BLE usage, you can use the external platform feature. It also serves as a way to integrate custom BLE usage with Matter. Please refer to the `advance setup`_ section in the programming guide. -This has been demonstrated in the `blemesh_bridge`_ and `light_wifi_prov`_ examples. +This has been demonstrated in the `blemesh_bridge`_ examples. A1.16 Moving BSS Segments to PSRAM to Reduce Memory Usage @@ -411,7 +411,6 @@ Please check `#1123`_ for relevant discussion on Github issue. .. _blecent_scan(): https://github.com/espressif/esp-idf/blob/b5ac4fbdf9e9fb320bb0a98ee4fbaa18f8566f37/examples/bluetooth/nimble/blecent/main/main.c#L435 .. _advance setup: https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html#advanced-setup .. _blemesh_bridge: https://github.com/espressif/esp-matter/tree/main/examples/bridge_apps/blemesh_bridge -.. _light_wifi_prov: https://github.com/espressif/esp-matter/tree/main/examples/light_wifi_prov#4-external-platform .. _getting the repository: https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html#getting-the-repository .. _requirements.txt: https://github.com/espressif/esp-matter/blob/main/requirements.txt .. _generate_setup_payload.py: https://github.com/project-chip/connectedhomeip/tree/master/src/setup_payload/python @@ -424,4 +423,4 @@ Please check `#1123`_ for relevant discussion on Github issue. .. _`#1123`: https://github.com/espressif/esp-matter/issues/1123 .. _`#1126`: https://github.com/espressif/esp-matter/issues/1126 .. _`#1128`: https://github.com/espressif/esp-matter/issues/1128 -.. _`#13303`: https://github.com/project-chip/connectedhomeip/issues/13303 \ No newline at end of file +.. _`#13303`: https://github.com/project-chip/connectedhomeip/issues/13303 diff --git a/examples/.build-rules.yml b/examples/.build-rules.yml index c9935aa0e..061720bb5 100644 --- a/examples/.build-rules.yml +++ b/examples/.build-rules.yml @@ -11,9 +11,9 @@ examples/bridge_apps/blemesh_bridge: examples/zap_light: enable: - - if: IDF_TARGET in ["esp32", "esp32h2"] + - if: IDF_TARGET in [""] temporary: true - reason: the other targets are not tested yet + reason: this should be compiled in Matter environment, another CI has been added examples/light_switch: enable: @@ -111,9 +111,9 @@ examples/ota_provider: temporary: true reason: the other targets are not tested yet -examples/light_wifi_prov: +examples/light_network_prov: enable: - - if: IDF_TARGET in ["esp32s3", "esp32c3"] + - if: IDF_TARGET in ["esp32s3", "esp32c3", "esp32h2"] temporary: true reason: the other targets are not tested yet diff --git a/examples/light_wifi_prov/CMakeLists.txt b/examples/light_network_prov/CMakeLists.txt similarity index 98% rename from examples/light_wifi_prov/CMakeLists.txt rename to examples/light_network_prov/CMakeLists.txt index 992d6ed74..bf0fb733c 100644 --- a/examples/light_wifi_prov/CMakeLists.txt +++ b/examples/light_network_prov/CMakeLists.txt @@ -22,7 +22,7 @@ set(EXTRA_COMPONENT_DIRS "${ESP_MATTER_PATH}/components" ${extra_components_dirs_append}) -project(light-wifi-prov) +project(light-network-prov) # WARNING: This is just an example for using key for decrypting the encrypted OTA image # Please do not use it as is. diff --git a/examples/light_wifi_prov/README.md b/examples/light_network_prov/README.md similarity index 89% rename from examples/light_wifi_prov/README.md rename to examples/light_network_prov/README.md index 5c362f33e..e5bfeef29 100644 --- a/examples/light_wifi_prov/README.md +++ b/examples/light_network_prov/README.md @@ -8,10 +8,9 @@ See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/de - ESP32-S3-DevKitM / ESP32-C3-DevKitM - chip-tool (For Matter commissioning) -- Android RainMaker APP of version 3.4.1 or iOS RainMaker APP of version 3.2.0 (For RainMaker Provisioning) +- Android RainMaker APP of version 3.5.0+ or iOS RainMaker APP of version 3.2.1+ (For RainMaker Network Provisioning) - [ESP-IDF](https://github.com/espressif/esp-idf) on tag v5.2.2 -- [ESP RainMaker](https://github.com/espressif/esp-rainmaker/tree/fd781295) on commit fd78129500aa1a8b2eee9e0dcc0720d7b14cd3dc -- [ESP Secure Cert Manager](https://github.com/espressif/esp_secure_cert_mgr) +- [RainMaker CLI](https://github.com/espressif/esp-rainmaker-cli) ## 2. Additional Environment Setup @@ -19,10 +18,16 @@ See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/de This example will use [host driven claiming](https://rainmaker.espressif.com/docs/claiming/#host-driven-claiming) via the RainMaker CLI. +Install esp-rainmaker-cli and login your RainMaker account: + +``` +python3 -m pip install esp-rainmaker-cli +esp-rainmaker-cli login +``` + Make sure your device is connected to the host machine, login into the CLI and execute this: ``` -$ cd $RMAKER_PATH/cli -$ ./rainmaker.py claim --matter +$ esp-rainmaker-cli claim --matter ``` The CLI will fetch the device certificates and flash them into the secure cert partition of your device. The certificates will be used for both the Matter device attestation verification and RainMaker MQTT connection. @@ -62,13 +67,11 @@ $ ./chip-tool pairing ble-wifi /-onb_codes.csv`. -## 4. External platform +## 4. Additional BLE GATT Service and BLE Advertisements -This example uses [external platform](../common/secondary_ble_adv/). +This example uses the BLEManagerImpl::ConfigureExtraServices() to configure the additional BLE GATT service for RainMaker Provisioning. The function should be called before start Matter stack. -In the external platform, `SetSecondaryXX()` APIs are added in the `BLEManagerImpl` class for setting up the secondary BLE advertisement and services. After you call these APIs of `BLEManagerImpl`, there will be an additional BLE advertisement and corresponding service for wifi_provisioning after you initialize the Matter stack. - -There are also some WiFi stack initialization changes to avoid duplicated Wi-Fi stack initialization of wifi_provisioning and Matter stack. +And you can also configure other BLE advertisements with the ble_gap_ext_adv_XX() APIs after the Matter BLE advertisement is started. ## 5. RainMaker Provisioning diff --git a/examples/light_wifi_prov/main/CMakeLists.txt b/examples/light_network_prov/main/CMakeLists.txt similarity index 62% rename from examples/light_wifi_prov/main/CMakeLists.txt rename to examples/light_network_prov/main/CMakeLists.txt index 7915017c0..08892aea3 100644 --- a/examples/light_wifi_prov/main/CMakeLists.txt +++ b/examples/light_network_prov/main/CMakeLists.txt @@ -1,5 +1,5 @@ -idf_component_register(SRC_DIRS "." "./wifi_prov_scheme" - PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils" "./wifi_prov_scheme") +idf_component_register(SRC_DIRS "." "./network_prov_scheme" + PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils" "./network_prov_scheme") set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/light_wifi_prov/main/app_driver.cpp b/examples/light_network_prov/main/app_driver.cpp similarity index 100% rename from examples/light_wifi_prov/main/app_driver.cpp rename to examples/light_network_prov/main/app_driver.cpp diff --git a/examples/light_wifi_prov/main/app_main.cpp b/examples/light_network_prov/main/app_main.cpp similarity index 90% rename from examples/light_wifi_prov/main/app_main.cpp rename to examples/light_network_prov/main/app_main.cpp index 1e79c5ec1..9df61ff42 100644 --- a/examples/light_wifi_prov/main/app_main.cpp +++ b/examples/light_network_prov/main/app_main.cpp @@ -6,13 +6,12 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "esp_matter_attribute_utils.h" -#include "esp_rmaker_user_mapping.h" #include #include #include #include +#include #include #include @@ -22,17 +21,18 @@ #include #include #include +#include #include #include -#include +#include #include #include "app-common/zap-generated/ids/Attributes.h" #include "app-common/zap-generated/ids/Clusters.h" -#include "platform/CHIPDeviceEvent.h" +#include "network_provisioning/manager.h" #include "platform/PlatformManager.h" -#include "wifi_provisioning/manager.h" #if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include #include #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI @@ -41,7 +41,7 @@ #include #include -#include +#include static const char *TAG = "app_main"; uint16_t light_endpoint_id = 0; @@ -269,7 +269,7 @@ extern "C" void app_main() ESP_LOGE(TAG, "Error create default event loop"); return; } - app_wifi_init(); + app_network_init(); esp_rmaker_config_t rainmaker_cfg = { .enable_time_sync = false, }; @@ -297,18 +297,31 @@ extern "C" void app_main() esp_rmaker_schedule_enable(); - err = app_wifi_set_custom_mfg_data(MGF_DATA_DEVICE_TYPE_LIGHT, MFG_DATA_DEVICE_SUBTYPE_LIGHT); + err = app_network_set_custom_mfg_data(MGF_DATA_DEVICE_TYPE_LIGHT, MFG_DATA_DEVICE_SUBTYPE_LIGHT); - err = app_wifi_start(POP_TYPE_MAC); + err = app_network_start(POP_TYPE_MAC); if (err != ESP_OK) { ESP_LOGE(TAG, "Could not start Wifi. Aborting!!!"); abort(); } - /* Matter start */ + /* Matter start */ err = esp_matter::start(app_event_cb); ABORT_APP_ON_FAILURE(err == ESP_OK, ESP_LOGE(TAG, "Failed to start Matter, err:%d", err)); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + esp_openthread_platform_config_t ot_config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + set_openthread_platform_config(&ot_config); + // This will not really initiaize Thread stack as the thread stack has been initialzed in app_network. + // We call this function to pass the OpenThread instance to GenericThreadStackManagerImpl_OpenThread + // so that it can be used for SRP service registration and network commissioning driver. + chip::DeviceLayer::ThreadStackMgr().InitThreadStack(); +#endif + /* Starting driver with default values */ app_driver_light_set_defaults(light_endpoint_id); @@ -316,11 +329,14 @@ extern "C" void app_main() err = esp_matter_ota_requestor_encrypted_init(s_decryption_key, s_decryption_key_len); ABORT_APP_ON_FAILURE(err == ESP_OK, ESP_LOGE(TAG, "Failed to initialized the encrypted OTA, err: %d", err)); #endif // CONFIG_ENABLE_ENCRYPTED_OTA - // If Wi-Fi is provisioned and RainMaker user node mapping is done, deinitialize the BLE. - bool is_wifi_provisioned = false; - wifi_prov_mgr_is_provisioned(&is_wifi_provisioned); - if (is_wifi_provisioned && esp_rmaker_user_node_mapping_get_state() == ESP_RMAKER_USER_MAPPING_DONE) { - chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t){ chip::DeviceLayer::Internal::BLEMgr().Shutdown(); }); + bool is_network_provisioned = false; +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI + network_prov_mgr_is_wifi_provisioned(&is_network_provisioned); +#else + network_prov_mgr_is_thread_provisioned(&is_network_provisioned); +#endif + if (is_network_provisioned && esp_rmaker_user_node_mapping_get_state() == ESP_RMAKER_USER_MAPPING_DONE) { + chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) { chip::DeviceLayer::Internal::BLEMgr().Shutdown(); }); } #if CONFIG_ENABLE_CHIP_SHELL diff --git a/examples/light_wifi_prov/main/app_wifi.cpp b/examples/light_network_prov/main/app_network.cpp similarity index 70% rename from examples/light_wifi_prov/main/app_wifi.cpp rename to examples/light_network_prov/main/app_network.cpp index ff13dbd61..1bd120b52 100644 --- a/examples/light_wifi_prov/main/app_wifi.cpp +++ b/examples/light_network_prov/main/app_network.cpp @@ -10,16 +10,17 @@ #include #include #include +#include #include #include #include #include #include -#include -#include +#include +#include -#include +#include #include #include #include @@ -28,9 +29,24 @@ #include #include -ESP_EVENT_DEFINE_BASE(APP_WIFI_EVENT); +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD +#include +#include +#include +#include +#include +#include -static const char *TAG = "app_wifi"; +#include +#include +#include +#include +#include +#endif + +ESP_EVENT_DEFINE_BASE(APP_NETWORK_EVENT); + +static const char *TAG = "app_network"; #define PROV_QR_VERSION "v1" @@ -43,9 +59,9 @@ static const char *TAG = "app_wifi"; #define POP_STR_SIZE 9 static esp_timer_handle_t prov_stop_timer; /* Timeout period in minutes */ -#define APP_WIFI_PROV_TIMEOUT_PERIOD 30 +#define APP_NETWORK_PROV_TIMEOUT_PERIOD 30 /* Autofetch period in micro-seconds */ -static uint64_t prov_timeout_period = (APP_WIFI_PROV_TIMEOUT_PERIOD * 60 * 1000000LL); +static uint64_t prov_timeout_period = (APP_NETWORK_PROV_TIMEOUT_PERIOD * 60 * 1000000LL); #define APP_PROV_STOP_ON_CREDS_MISMATCH @@ -63,7 +79,7 @@ char esp_rainmaker_ascii_art[] = static uint8_t *custom_mfg_data = NULL; static size_t custom_mfg_data_len = 0; -esp_err_t app_wifi_set_custom_mfg_data(uint16_t device_type, uint8_t device_subtype) +esp_err_t app_network_set_custom_mfg_data(uint16_t device_type, uint8_t device_subtype) { int8_t mfg_data[] = {(int8_t)MFG_DATA_HEADER, MGF_DATA_APP_ID, MFG_DATA_VERSION, MFG_DATA_CUSTOMER_ID}; size_t mfg_data_len = sizeof(mfg_data) + 4; // 4 bytes of device type, subtype, and extra-code @@ -89,7 +105,7 @@ static esp_err_t qrcode_display(const char *text) return esp_qrcode_generate(&cfg, text); } -static void app_wifi_print_qr(const char *name, const char *pop, const char *transport) +static void app_network_print_qr(const char *name, const char *pop, const char *transport) { if (!name || !transport) { ESP_LOGW(TAG, "Cannot generate QR code payload. Data missing."); @@ -111,7 +127,7 @@ static void app_wifi_print_qr(const char *name, const char *pop, const char *tra qrcode_display(payload); ESP_LOGI(TAG, "If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", QRCODE_BASE_URL, payload); - esp_event_post(APP_WIFI_EVENT, APP_WIFI_EVENT_QR_DISPLAY, payload, strlen(payload) + 1, portMAX_DELAY); + esp_event_post(APP_NETWORK_EVENT, APP_NETWORK_EVENT_QR_DISPLAY, payload, strlen(payload) + 1, portMAX_DELAY); } /* Event handler for catching system events */ @@ -120,12 +136,13 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_ static int retries = 0; static int failed_cnt = 0; - if (event_base == WIFI_PROV_EVENT) { + if (event_base == NETWORK_PROV_EVENT) { switch (event_id) { - case WIFI_PROV_START: + case NETWORK_PROV_START: ESP_LOGI(TAG, "Provisioning started"); break; - case WIFI_PROV_CRED_RECV: { +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI + case NETWORK_PROV_WIFI_CRED_RECV: { wifi_sta_config_t *wifi_sta_cfg = (wifi_sta_config_t *)event_data; ESP_LOGI(TAG, "Received Wi-Fi credentials" @@ -133,35 +150,55 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_ (const char *)wifi_sta_cfg->ssid, (const char *)wifi_sta_cfg->password); break; } - case WIFI_PROV_CRED_FAIL: { - wifi_prov_sta_fail_reason_t *reason = (wifi_prov_sta_fail_reason_t *)event_data; + case NETWORK_PROV_WIFI_CRED_FAIL: { + network_prov_wifi_sta_fail_reason_t *reason = (network_prov_wifi_sta_fail_reason_t *)event_data; ESP_LOGE(TAG, "Provisioning failed!\n\tReason : %s" "\n\tPlease reset to factory and retry provisioning", - (*reason == WIFI_PROV_STA_AUTH_ERROR) ? "Wi-Fi station authentication failed" + (*reason == NETWORK_PROV_WIFI_STA_AUTH_ERROR) ? "Wi-Fi station authentication failed" : "Wi-Fi access-point not found"); retries++; if (retries >= 5) { ESP_LOGI(TAG, "Failed to connect with provisioned AP, reseting provisioned credentials"); - wifi_prov_mgr_reset_sm_state_on_failure(); - esp_event_post(APP_WIFI_EVENT, APP_WIFI_EVENT_PROV_RESTART, NULL, 0, portMAX_DELAY); + network_prov_mgr_reset_wifi_sm_state_on_failure(); + esp_event_post(APP_NETWORK_EVENT, APP_NETWORK_EVENT_PROV_RESTART, NULL, 0, portMAX_DELAY); ESP_LOGW(TAG, "Failed to connect with provisioned AP, please reset to provisioning manually"); retries = 0; } break; } - case WIFI_PROV_CRED_SUCCESS: + case NETWORK_PROV_WIFI_CRED_SUCCESS: ESP_LOGI(TAG, "Provisioning successful"); retries = 0; break; - case WIFI_PROV_END: +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD + case NETWORK_PROV_THREAD_DATASET_RECV: { + break; + } + case NETWORK_PROV_THREAD_DATASET_FAIL: { + retries++; + if (retries >= 5) { + ESP_LOGI(TAG, "Failed to connect with provisioned network, reseting provisioned dataset"); + network_prov_mgr_reset_thread_sm_state_on_failure(); + esp_event_post(APP_NETWORK_EVENT, APP_NETWORK_EVENT_PROV_RESTART, NULL, 0, portMAX_DELAY); + retries = 0; + } + break; + } + case NETWORK_PROV_THREAD_DATASET_SUCCESS: + ESP_LOGI(TAG, "Provisioning successful"); + retries = 0; + break; +#endif + case NETWORK_PROV_END: if (prov_stop_timer) { esp_timer_stop(prov_stop_timer); esp_timer_delete(prov_stop_timer); prov_stop_timer = NULL; } /* De-initialize manager once provisioning is finished */ - wifi_prov_mgr_deinit(); + network_prov_mgr_deinit(); break; default: break; @@ -178,21 +215,61 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_ ESP_LOGE(TAG, "Received incorrect PoP or invalid security params! event: %d", (int)event_id); if (++failed_cnt >= 5) { /* stop provisioning for security reasons */ - wifi_prov_mgr_stop_provisioning(); + network_prov_mgr_stop_provisioning(); ESP_LOGW(TAG, "Max PoP attempts reached! Provisioning disabled for security reasons. Please reboot device " "to restart provisioning"); - esp_event_post(APP_WIFI_EVENT, APP_WIFI_EVENT_PROV_CRED_MISMATCH, NULL, 0, portMAX_DELAY); + esp_event_post(APP_NETWORK_EVENT, APP_NETWORK_EVENT_PROV_CRED_MISMATCH, NULL, 0, portMAX_DELAY); } break; default: break; } +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { ESP_LOGI(TAG, "Disconnected. Connecting to the AP again..."); esp_wifi_connect(); +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI } } +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD +static esp_netif_t* init_openthread_netif(const esp_openthread_platform_config_t* config) +{ + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD(); + esp_netif_t* netif = esp_netif_new(&cfg); + assert(netif != NULL); + ESP_ERROR_CHECK(esp_netif_attach(netif, esp_openthread_netif_glue_init(config))); + + return netif; +} + +static void ot_task_worker(void* aContext) +{ + esp_openthread_platform_config_t config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + /* Initialize the OpenThread stack */ + ESP_ERROR_CHECK(esp_openthread_init(&config)); +#if CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC + /* The OpenThread log level directly matches ESP log level */ + (void)otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL); +#endif + esp_netif_t *openthread_netif = init_openthread_netif(&config); + /* Initialize the esp_netif bindings */ + esp_netif_set_default_netif(openthread_netif); + + /* Run the main loop */ + esp_openthread_launch_mainloop(); + /* Clean up */ + esp_netif_destroy(openthread_netif); + esp_openthread_netif_glue_deinit(); + + esp_vfs_eventfd_unregister(); + vTaskDelete(NULL); +} +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD /* Free random_bytes after use only if function returns ESP_OK */ static esp_err_t read_random_bytes_from_nvs(uint8_t **random_bytes, size_t *len) @@ -225,7 +302,7 @@ static esp_err_t read_random_bytes_from_nvs(uint8_t **random_bytes, size_t *len) } static char *custom_pop; -esp_err_t app_wifi_set_custom_pop(const char *pop) +esp_err_t app_network_set_custom_pop(const char *pop) { /* NULL PoP is not allowed here. Use POP_TYPE_NONE instead. */ if (!pop) { @@ -251,9 +328,9 @@ static esp_err_t get_device_service_name(char *service_name, size_t max) const char *ssid_prefix = "PROV"; size_t nvs_random_size = 0; if ((read_random_bytes_from_nvs(&nvs_random, &nvs_random_size) != ESP_OK) || nvs_random_size < 3) { - uint8_t eth_mac[6]; - esp_wifi_get_mac(WIFI_IF_STA, eth_mac); - snprintf(service_name, max, "%s_%02x%02x%02x", ssid_prefix, eth_mac[3], eth_mac[4], eth_mac[5]); + uint8_t mac_addr[6]; + esp_read_mac(mac_addr, ESP_MAC_BASE); + snprintf(service_name, max, "%s_%02x%02x%02x", ssid_prefix, mac_addr[3], mac_addr[4], mac_addr[5]); } else { snprintf(service_name, max, "%s_%02x%02x%02x", ssid_prefix, nvs_random[nvs_random_size - 3], nvs_random[nvs_random_size - 2], nvs_random[nvs_random_size - 1]); @@ -264,7 +341,7 @@ static esp_err_t get_device_service_name(char *service_name, size_t max) return ESP_OK; } -static char *get_device_pop(app_wifi_pop_type_t pop_type) +static char *get_device_pop(app_network_pop_type_t pop_type) { if (pop_type == POP_TYPE_NONE) { return NULL; @@ -282,10 +359,10 @@ static char *get_device_pop(app_wifi_pop_type_t pop_type) } if (pop_type == POP_TYPE_MAC) { - uint8_t eth_mac[6]; - esp_err_t err = esp_wifi_get_mac(WIFI_IF_STA, eth_mac); + uint8_t mac_addr[6]; + esp_err_t err = esp_read_mac(mac_addr, ESP_MAC_BASE); if (err == ESP_OK) { - snprintf(pop, POP_STR_SIZE, "%02x%02x%02x%02x", eth_mac[2], eth_mac[3], eth_mac[4], eth_mac[5]); + snprintf(pop, POP_STR_SIZE, "%02x%02x%02x%02x", mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); return pop; } else { ESP_LOGE(TAG, "Failed to get MAC address to generate PoP."); @@ -311,8 +388,9 @@ pop_err: return NULL; } -void app_wifi_init(void) +void app_network_init(void) { +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI wifi_init_config_t cfg; esp_err_t err = esp_netif_init(); if (err != ESP_OK) { @@ -336,35 +414,47 @@ void app_wifi_init(void) ESP_LOGE(TAG, "Failed to initialize esp_wifi"); return; } +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD + /* Initialize TCP/IP */ + esp_netif_init(); + esp_vfs_eventfd_config_t eventfd_config = { + .max_fds = 3, + }; + ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config)); + xTaskCreate(ot_task_worker, "ot_task", 6144, xTaskGetCurrentTaskHandle(), 5, NULL); +#endif /* Register our event handler for Wi-Fi, IP and Provisioning related events */ - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_register(NETWORK_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); #ifdef APP_PROV_STOP_ON_CREDS_MISMATCH ESP_ERROR_CHECK( esp_event_handler_register(PROTOCOMM_SECURITY_SESSION_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); #endif +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI } -static void app_wifi_prov_stop(void *priv) +static void app_network_prov_stop(void *priv) { ESP_LOGW(TAG, "Provisioning timed out. Please reboot device to restart provisioning."); - wifi_prov_mgr_stop_provisioning(); - esp_event_post(APP_WIFI_EVENT, APP_WIFI_EVENT_PROV_TIMEOUT, NULL, 0, portMAX_DELAY); + network_prov_mgr_stop_provisioning(); + esp_event_post(APP_NETWORK_EVENT, APP_NETWORK_EVENT_PROV_TIMEOUT, NULL, 0, portMAX_DELAY); } -esp_err_t app_wifi_start_timer(void) +esp_err_t app_network_start_timer(void) { if (prov_timeout_period == 0) { return ESP_OK; } - esp_timer_create_args_t prov_stop_timer_conf = {.callback = app_wifi_prov_stop, + esp_timer_create_args_t prov_stop_timer_conf = {.callback = app_network_prov_stop, .arg = NULL, .dispatch_method = ESP_TIMER_TASK, .name = "app_wifi_prov_stop_tm"}; if (esp_timer_create(&prov_stop_timer_conf, &prov_stop_timer) == ESP_OK) { esp_timer_start_once(prov_stop_timer, prov_timeout_period); - ESP_LOGI(TAG, "Provisioning will auto stop after %d minute(s).", APP_WIFI_PROV_TIMEOUT_PERIOD); + ESP_LOGI(TAG, "Provisioning will auto stop after %d minute(s).", APP_NETWORK_PROV_TIMEOUT_PERIOD); return ESP_OK; } else { ESP_LOGE(TAG, "Failed to create Provisioning auto stop timer."); @@ -372,11 +462,11 @@ esp_err_t app_wifi_start_timer(void) return ESP_FAIL; } -esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type) +esp_err_t app_network_start(app_network_pop_type_t pop_type) { /* Configuration for the provisioning manager */ - wifi_prov_mgr_config_t config = { - .scheme = wifi_prov_scheme_matter_ble, + network_prov_mgr_config_t config = { + .scheme = network_prov_scheme_matter_ble, /* Any default scheme specific event handler that you would * like to choose. Since our example application requires @@ -386,16 +476,21 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type) * appropriate scheme specific event handler allows the manager * to take care of this automatically. This can be set to * WIFI_PROV_EVENT_HANDLER_NONE when using wifi_prov_scheme_softap*/ - .scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, + .scheme_event_handler = NETWORK_PROV_EVENT_HANDLER_NONE, }; /* Initialize provisioning manager with the * configuration parameters set above */ - ESP_ERROR_CHECK(wifi_prov_mgr_init(config)); + ESP_ERROR_CHECK(network_prov_mgr_init(config)); bool provisioned = false; /* Let's find out if the device is provisioned */ - wifi_prov_mgr_is_provisioned(&provisioned); +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI + network_prov_mgr_is_wifi_provisioned(&provisioned); +#endif +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD + network_prov_mgr_is_thread_provisioned(&provisioned); +#endif /* If device is not yet provisioned start provisioning service */ if (!provisioned) { ESP_LOGI(TAG, "Starting provisioning"); @@ -420,7 +515,7 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type) * using X25519 key exchange and proof of possession (pop) and AES-CTR * for encryption/decryption of messages. */ - wifi_prov_security_t security = WIFI_PROV_SECURITY_1; + network_prov_security_t security = NETWORK_PROV_SECURITY_1; /* Do we want a proof-of-possession (ignored if Security 0 is selected): * - this should be a string with length > 0 @@ -445,13 +540,13 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type) /* 12th and 13th bit will be replaced by internal bits. */ 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, }; - esp_err_t err = wifi_prov_scheme_matter_ble_set_service_uuid(custom_service_uuid, sizeof(custom_service_uuid)); + esp_err_t err = network_prov_scheme_matter_ble_set_service_uuid(custom_service_uuid, sizeof(custom_service_uuid)); if (err != ESP_OK) { ESP_LOGE(TAG, "wifi_prov_scheme_ble_set_service_uuid failed %d", err); return err; } if (custom_mfg_data) { - err = wifi_prov_scheme_matter_ble_set_mfg_data(custom_mfg_data, custom_mfg_data_len); + err = network_prov_scheme_matter_ble_set_mfg_data(custom_mfg_data, custom_mfg_data_len); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to set mfg data, err=0x%x", err); return err; @@ -459,22 +554,31 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type) } /* Start provisioning service */ - ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key)); + ESP_ERROR_CHECK(network_prov_mgr_start_provisioning(security, pop, service_name, service_key)); /* Print QR code for provisioning */ - app_wifi_print_qr(service_name, pop, PROV_TRANSPORT_BLE); + app_network_print_qr(service_name, pop, PROV_TRANSPORT_BLE); ESP_LOGI(TAG, "Provisioning Started. Name : %s, POP : %s", service_name, pop ? pop : ""); if (pop) { free(pop); } - app_wifi_start_timer(); + app_network_start_timer(); } else { ESP_LOGI(TAG, "Already provisioned, starting Wi-Fi STA"); /* We don't need the manager as device is already provisioned, * so let's release it's resources */ - wifi_prov_mgr_deinit(); + network_prov_mgr_deinit(); +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_start()); esp_wifi_connect(); +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD + esp_openthread_lock_acquire(portMAX_DELAY); + otInstance* instance = esp_openthread_get_instance(); + (void)otIp6SetEnabled(instance, true); + (void)otThreadSetEnabled(instance, true); + esp_openthread_lock_release(); +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD esp_rmaker_start(); } if (custom_mfg_data) { diff --git a/examples/light_wifi_prov/main/app_wifi.h b/examples/light_network_prov/main/app_network.h similarity index 65% rename from examples/light_wifi_prov/main/app_wifi.h rename to examples/light_network_prov/main/app_network.h index b53465c44..186574342 100644 --- a/examples/light_wifi_prov/main/app_wifi.h +++ b/examples/light_network_prov/main/app_network.h @@ -24,19 +24,19 @@ #define MFG_DATA_DEVICE_EXTRA_CODE 0x00 /** ESP RainMaker Event Base */ -ESP_EVENT_DECLARE_BASE(APP_WIFI_EVENT); +ESP_EVENT_DECLARE_BASE(APP_NETWORK_EVENT); /** App Wi-Fir Events */ typedef enum { /** QR code available for display. Associated data is the NULL terminated QR payload. */ - APP_WIFI_EVENT_QR_DISPLAY = 1, + APP_NETWORK_EVENT_QR_DISPLAY = 1, /** Provisioning timed out */ - APP_WIFI_EVENT_PROV_TIMEOUT, + APP_NETWORK_EVENT_PROV_TIMEOUT, /** Provisioning has restarted due to failures (Invalid SSID/Passphrase) */ - APP_WIFI_EVENT_PROV_RESTART, + APP_NETWORK_EVENT_PROV_RESTART, /** Provisioning closed due to invalid credentials */ - APP_WIFI_EVENT_PROV_CRED_MISMATCH, -} app_wifi_event_t; + APP_NETWORK_EVENT_PROV_CRED_MISMATCH, +} app_network_event_t; /** Types of Proof of Possession */ typedef enum { @@ -52,25 +52,45 @@ typedef enum { * Set a custom PoP using app_wifi_set_custom_pop() first. */ POP_TYPE_CUSTOM -} app_wifi_pop_type_t; +} app_network_pop_type_t; -/** Initialize Wi-Fi +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD +#include +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_NATIVE, \ + } + +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + } + +#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ + { \ + .storage_partition_name = "nvs", \ + .netif_queue_size = 10, \ + .task_queue_size = 10, \ + } +#endif // CONFIG_ESP_RMAKER_NETWORK_OVER_THREAD + +/** Initialize network * - * This initializes Wi-Fi and the Wi-Fi provisioning manager + * This initializes network and the network provisioning manager */ -void app_wifi_init(); +void app_network_init(); -/** Start Wi-Fi +/** Start network * - * This will start provisioning if the node is not provisioned and will connect to Wi-Fi - * if node is provisioned. Function will return successfully only after Wi-Fi is connect + * This will start provisioning if the node is not provisioned and will connect to Wi-Fi/Thread + * if node is provisioned. Function will return successfully only after Wi-Fi/Thread is connect * * @param[in] pop_type The type for Proof of Possession (PoP) pin - * - * @return ESP_OK on success (Wi-Fi connected). + * + * @return ESP_OK on success (Wi-Fi/Thread connected). * @return error in case of failure. */ -esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type); +esp_err_t app_network_start(app_network_pop_type_t pop_type); /** Set custom manufacturing data * @@ -84,7 +104,7 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t app_wifi_set_custom_mfg_data(uint16_t device_type, uint8_t device_subtype); +esp_err_t app_network_set_custom_mfg_data(uint16_t device_type, uint8_t device_subtype); /** Set custom PoP * @@ -96,4 +116,4 @@ esp_err_t app_wifi_set_custom_mfg_data(uint16_t device_type, uint8_t device_subt * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t app_wifi_set_custom_pop(const char *pop); +esp_err_t app_network_set_custom_pop(const char *pop); diff --git a/examples/light_wifi_prov/main/app_priv.h b/examples/light_network_prov/main/app_priv.h similarity index 100% rename from examples/light_wifi_prov/main/app_priv.h rename to examples/light_network_prov/main/app_priv.h diff --git a/examples/light_wifi_prov/main/idf_component.yml b/examples/light_network_prov/main/idf_component.yml similarity index 88% rename from examples/light_wifi_prov/main/idf_component.yml rename to examples/light_network_prov/main/idf_component.yml index 40283433b..cb6ddc057 100644 --- a/examples/light_wifi_prov/main/idf_component.yml +++ b/examples/light_network_prov/main/idf_component.yml @@ -4,6 +4,6 @@ dependencies: espressif/led_strip: version: "^2.0.0" espressif/esp_rainmaker: - version: "1.3.0" + version: "^1.4.2" espressif/qrcode: version: "^0.1.0~2" diff --git a/examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.cpp b/examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.cpp similarity index 85% rename from examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.cpp rename to examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.cpp index c1a83adcd..f6cbcab3d 100644 --- a/examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.cpp +++ b/examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.cpp @@ -6,7 +6,7 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "wifi_prov_scheme_matter_ble.h" +#include "network_prov_scheme_matter_ble.h" #include "protocomm_matter_ble.h" #include @@ -17,7 +17,7 @@ #include #include -#define TAG "WIFI_PROV" +#define TAG "NETWORK_PROV" static uint8_t custom_service_uuid[BLE_UUID128_VAL_LENGTH]; static bool custom_service_uuid_set = false; @@ -62,7 +62,7 @@ static esp_err_t prov_stop(protocomm_t *pc) return protocomm_matter_ble_stop(pc); } -esp_err_t wifi_prov_scheme_matter_ble_set_service_uuid(uint8_t *uuid, size_t uuid_size) +esp_err_t network_prov_scheme_matter_ble_set_service_uuid(uint8_t *uuid, size_t uuid_size) { if (uuid_size != sizeof(custom_service_uuid)) { return ESP_ERR_INVALID_ARG; @@ -72,7 +72,7 @@ esp_err_t wifi_prov_scheme_matter_ble_set_service_uuid(uint8_t *uuid, size_t uui return ESP_OK; } -esp_err_t wifi_prov_scheme_matter_ble_set_mfg_data(uint8_t *mfg_data, size_t mfg_data_len) +esp_err_t network_prov_scheme_matter_ble_set_mfg_data(uint8_t *mfg_data, size_t mfg_data_len) { if (custom_manufacturer_data) { free(custom_manufacturer_data); @@ -180,10 +180,13 @@ static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, ui return ESP_OK; } -const wifi_prov_scheme_t wifi_prov_scheme_matter_ble = {.prov_start = prov_start, - .prov_stop = prov_stop, - .new_config = new_config, - .delete_config = delete_config, - .set_config_service = set_config_service, - .set_config_endpoint = set_config_endpoint, - .wifi_mode = WIFI_MODE_STA}; +const network_prov_scheme_t network_prov_scheme_matter_ble = {.prov_start = prov_start, + .prov_stop = prov_stop, + .new_config = new_config, + .delete_config = delete_config, + .set_config_service = set_config_service, + .set_config_endpoint = set_config_endpoint, +#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI + .wifi_mode = WIFI_MODE_STA +#endif +}; diff --git a/examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.h b/examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.h new file mode 100644 index 000000000..1f938d690 --- /dev/null +++ b/examples/light_network_prov/main/network_prov_scheme/network_prov_scheme_matter_ble.h @@ -0,0 +1,29 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#pragma once + +#include +#include +#include +#include + +#include + +extern const network_prov_scheme_t network_prov_scheme_matter_ble; + +#define NETWORK_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM { \ + .event_cb = network_prov_scheme_ble_event_cb_free_btdm, \ + .user_data = NULL \ +} + +void network_prov_scheme_matter_ble_event_cb_free_btdm(void *user_data, network_prov_cb_event_t event, void *event_data); + +esp_err_t network_prov_scheme_matter_ble_set_service_uuid(uint8_t *uuid, size_t uuid_size); + +esp_err_t network_prov_scheme_matter_ble_set_mfg_data(uint8_t *mfg_data, size_t mfg_data_len); diff --git a/examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.cpp b/examples/light_network_prov/main/network_prov_scheme/protocomm_matter_ble.cpp similarity index 100% rename from examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.cpp rename to examples/light_network_prov/main/network_prov_scheme/protocomm_matter_ble.cpp diff --git a/examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.h b/examples/light_network_prov/main/network_prov_scheme/protocomm_matter_ble.h similarity index 100% rename from examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.h rename to examples/light_network_prov/main/network_prov_scheme/protocomm_matter_ble.h diff --git a/examples/light_wifi_prov/paa_cert/RainMaker-Claim-PAA-Cert.der b/examples/light_network_prov/paa_cert/RainMaker-Claim-PAA-Cert.der similarity index 100% rename from examples/light_wifi_prov/paa_cert/RainMaker-Claim-PAA-Cert.der rename to examples/light_network_prov/paa_cert/RainMaker-Claim-PAA-Cert.der diff --git a/examples/light_wifi_prov/partitions.csv b/examples/light_network_prov/partitions.csv similarity index 100% rename from examples/light_wifi_prov/partitions.csv rename to examples/light_network_prov/partitions.csv diff --git a/examples/light_wifi_prov/sdkconfig.defaults b/examples/light_network_prov/sdkconfig.defaults similarity index 96% rename from examples/light_wifi_prov/sdkconfig.defaults rename to examples/light_network_prov/sdkconfig.defaults index e9657ed4a..ef0065d17 100644 --- a/examples/light_wifi_prov/sdkconfig.defaults +++ b/examples/light_network_prov/sdkconfig.defaults @@ -60,6 +60,9 @@ CONFIG_MBEDTLS_ERROR_STRINGS=n # Fix for Timer Overflows CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120 +# Decrease Max endpoints +CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=2 + # Additional configurations CONFIG_ESP_RMAKER_USER_ID_CHECK=y CONFIG_ESP_RMAKER_NO_CLAIM=y diff --git a/examples/light_wifi_prov/sdkconfig.defaults.esp32c3 b/examples/light_network_prov/sdkconfig.defaults.esp32c3 similarity index 100% rename from examples/light_wifi_prov/sdkconfig.defaults.esp32c3 rename to examples/light_network_prov/sdkconfig.defaults.esp32c3 diff --git a/examples/light_network_prov/sdkconfig.defaults.esp32h2 b/examples/light_network_prov/sdkconfig.defaults.esp32h2 new file mode 100644 index 000000000..9c5b31626 --- /dev/null +++ b/examples/light_network_prov/sdkconfig.defaults.esp32h2 @@ -0,0 +1,48 @@ +CONFIG_IDF_TARGET="esp32h2" + +# Flash size optimization +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y +CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y +CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS=y + +# Increase IPv6 address number in netif structure +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 + +# Disable Route hook +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=n +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=n + +# Enable OpenThread +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC=n +CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y +CONFIG_OPENTHREAD_DNS64_CLIENT=y +CONFIG_ENABLE_THREAD_TELEMETRY=y + +# esp_matter::start() will not initialize Thread stack as we initialize it in app_network. +CONFIG_ESP_MATTER_ENABLE_OPENTHREAD=n + +# Use platform mDNS +CONFIG_USE_MINIMAL_MDNS=n + +# Disable Matter over Wi-Fi +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_TELEMETRY=n + +# Disable ECDSA Peripheral +CONFIG_USE_ESP32_ECDSA_PERIPHERAL=n +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Memory Optimization +CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE=512 +CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE=256 +CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE=256 +CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=2 + +# BSP Configuration +CONFIG_BUTTON_PERIOD_TIME_MS=20 +CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 +CONFIG_BSP_BUTTONS_NUM=1 +CONFIG_BSP_BUTTON_1_GPIO=9 +CONFIG_BSP_LED_TYPE_RGB=y +CONFIG_BSP_LED_RGB_GPIO=8 diff --git a/examples/light_wifi_prov/sdkconfig.defaults.esp32s3 b/examples/light_network_prov/sdkconfig.defaults.esp32s3 similarity index 100% rename from examples/light_wifi_prov/sdkconfig.defaults.esp32s3 rename to examples/light_network_prov/sdkconfig.defaults.esp32s3 diff --git a/examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.h b/examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.h deleted file mode 100644 index 94eba6c9c..000000000 --- a/examples/light_wifi_prov/main/wifi_prov_scheme/wifi_prov_scheme_matter_ble.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - -#pragma once - -#include -#include -#include -#include - -#include - -extern const wifi_prov_scheme_t wifi_prov_scheme_matter_ble; - -#define WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM { \ - .event_cb = wifi_prov_scheme_ble_event_cb_free_btdm, \ - .user_data = NULL \ -} - -void wifi_prov_scheme_matter_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event_t event, void *event_data); - -esp_err_t wifi_prov_scheme_matter_ble_set_service_uuid(uint8_t *uuid, size_t uuid_size); - -esp_err_t wifi_prov_scheme_matter_ble_set_mfg_data(uint8_t *mfg_data, size_t mfg_data_len);