diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 914386f76..6a32e425d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ variables: # idf_v5_0 is used for zigbee_bridge example and examples of ESP32-H2 - git clone --recursive --shallow-submodules --reference-if-able /local_references/github/ https://github.com/espressif/esp-idf.git - cd esp-idf - - git checkout 047903c612e2c7212693c0861966bf7c83430ebf + - git checkout ccdeb43cc7274a49e8dfa331de95ab06dea25183 - git submodule update --init --recursive --depth 1 - export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets" - ./install.sh diff --git a/README.md b/README.md index bba4c6a2c..54b46c7e9 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ git clone --recursive https://github.com/espressif/esp-matter.git ## Supported ESP-IDF and connectedhomeip versions -- ESP Matter currently works with [commit 06457ae](https://github.com/project-chip/connectedhomeip/tree/06457ae) of connectedhomeip. +- ESP Matter currently works with [commit 68dbb8f](https://github.com/project-chip/connectedhomeip/tree/68dbb8f) of connectedhomeip. - For Wi-Fi devices (ESP32, ESP32-C3, ESP32-S3), ESP-IDF [v4.4.2 release](https://github.com/espressif/esp-idf/releases/tag/v4.4.2) is required. -- For Thread devices (ESP32-H2), ESP-IDF master branch at [commit 047903c](https://github.com/espressif/esp-idf/commit/047903c) should be used. +- For Thread devices (ESP32-H2) and Zigbee Bridge example, ESP-IDF release/v5.0 branch at [commit ccdeb43](https://github.com/espressif/esp-idf/tree/ccdeb43) should be used. ## Documentation diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index f7da41d6c..a806f986a 100644 --- a/components/esp_matter/CMakeLists.txt +++ b/components/esp_matter/CMakeLists.txt @@ -71,7 +71,7 @@ set(INCLUDE_DIRS_LIST "." "${MATTER_SDK_PATH}/src" "${ZAP_GENERATED_PATH}/../") -set(REQUIRES_LIST chip bt esp_matter_console) +set(REQUIRES_LIST chip bt esp_matter_console nvs_flash) if ("${IDF_TARGET}" STREQUAL "esp32h2") list(APPEND REQUIRES_LIST openthread esp_matter_openthread) diff --git a/components/esp_matter_console/CMakeLists.txt b/components/esp_matter_console/CMakeLists.txt index 84e47d3ed..f69a51c9e 100644 --- a/components/esp_matter_console/CMakeLists.txt +++ b/components/esp_matter_console/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS esp_matter_console.cpp esp_matter_console_diagnostics.cpp INCLUDE_DIRS . - PRIV_REQUIRES chip esp32_mbedtls) + PRIV_REQUIRES chip esp32_mbedtls esp_timer) diff --git a/components/esp_matter_openthread/CMakeLists.txt b/components/esp_matter_openthread/CMakeLists.txt index 98e683caa..9b401dadf 100644 --- a/components/esp_matter_openthread/CMakeLists.txt +++ b/components/esp_matter_openthread/CMakeLists.txt @@ -4,4 +4,4 @@ endif() idf_component_register(SRCS ${srcs} INCLUDE_DIRS . - PRIV_REQUIRES openthread) + PRIV_REQUIRES openthread esp_netif driver) diff --git a/components/route_hook/CMakeLists.txt b/components/route_hook/CMakeLists.txt index 19cd48bc9..fcc6b5ee0 100644 --- a/components/route_hook/CMakeLists.txt +++ b/components/route_hook/CMakeLists.txt @@ -5,4 +5,4 @@ endif() idf_component_register(SRC_DIRS ${src_dirs} INCLUDE_DIRS include PRIV_INCLUDE_DIRS private_include - REQUIRES lwip) + REQUIRES lwip esp_netif) diff --git a/connectedhomeip/connectedhomeip b/connectedhomeip/connectedhomeip index 06457aea2..069b09b5f 160000 --- a/connectedhomeip/connectedhomeip +++ b/connectedhomeip/connectedhomeip @@ -1 +1 @@ -Subproject commit 06457aea2d2112e76f88c95ee4ab0e22a9dbe9f5 +Subproject commit 069b09b5f31d07d0772cfef91ba8010237f81b49 diff --git a/device_hal/device/hollow/device.c b/device_hal/device/hollow/device.c new file mode 100644 index 000000000..fa8e7d1b3 --- /dev/null +++ b/device_hal/device/hollow/device.c @@ -0,0 +1,43 @@ +// Copyright 2021 Espressif Systems (Shanghai) CO 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 + +#define LED_GPIO_PIN GPIO_NUM_8 +#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ +#define BUTTON_GPIO_PIN GPIO_NUM_9 + +static const char *TAG = "device"; + +led_driver_config_t led_driver_get_config() +{ + led_driver_config_t config = { + .gpio = LED_GPIO_PIN, + .channel = LED_CHANNEL, + }; + return config; +} + +button_config_t button_driver_get_config() +{ + button_config_t config = { + .type = BUTTON_TYPE_GPIO, + .gpio_button_config = { + .gpio_num = BUTTON_GPIO_PIN, + .active_level = 0, + } + }; + return config; +} diff --git a/device_hal/device/hollow/esp_matter_device.cmake b/device_hal/device/hollow/esp_matter_device.cmake new file mode 100644 index 000000000..a24701139 --- /dev/null +++ b/device_hal/device/hollow/esp_matter_device.cmake @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.5) + +SET(device_type hollow) +SET(led_type hollow_led) +SET(button_type hollow_button) + +SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/button") diff --git a/device_hal/led_driver/ws2812/led_driver.c b/device_hal/led_driver/ws2812/led_driver.c index 3eb160f39..5ff3f6a7f 100644 --- a/device_hal/led_driver/ws2812/led_driver.c +++ b/device_hal/led_driver/ws2812/led_driver.c @@ -28,23 +28,37 @@ led_driver_handle_t led_driver_init(led_driver_config_t *config) { ESP_LOGI(TAG, "Initializing light driver"); esp_err_t err = ESP_OK; - +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) rmt_config_t rmt_cfg = RMT_DEFAULT_CONFIG_TX(config->gpio, config->channel); rmt_cfg.clk_div = 2; err = rmt_config(&rmt_cfg); if (err != ESP_OK) { ESP_LOGE(TAG, "rmt_cfg failed"); + return NULL; } err = rmt_driver_install(rmt_cfg.channel, 0, 0); if (err != ESP_OK) { ESP_LOGE(TAG, "rmt_driver_install failed"); + return NULL; } led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t)rmt_cfg.channel); led_strip_t *strip = led_strip_new_rmt_ws2812(&strip_config); +#else + led_strip_config_t strip_config = { + .strip_gpio_num = config->gpio, + .max_leds = 1, + }; + led_strip_handle_t strip; + err = led_strip_new_rmt_device(&strip_config, &strip); + if (err != ESP_OK) { + ESP_LOGE(TAG, "led_strip initializing failed"); + return NULL; + } +#endif if (!strip) { ESP_LOGE(TAG, "W2812 driver install failed"); - err = ESP_FAIL; + return NULL; } return (led_driver_handle_t)strip; } @@ -62,6 +76,7 @@ esp_err_t led_driver_set_RGB(led_driver_handle_t handle) ESP_LOGE(TAG, "led driver handle cannot be NULL"); err = ESP_FAIL; } else { +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) led_strip_t *strip = (led_strip_t *)handle; err = strip->set_pixel(strip, 0, mRGB.red, mRGB.green, mRGB.blue); if (err != ESP_OK) { @@ -70,6 +85,11 @@ esp_err_t led_driver_set_RGB(led_driver_handle_t handle) } ESP_LOGI(TAG, "led set r:%d, g:%d, b:%d", mRGB.red, mRGB.green, mRGB.blue); err = strip->refresh(strip, 100); +#else + led_strip_handle_t strip = (led_strip_handle_t)handle; + err = led_strip_set_pixel(strip, 0, mRGB.red, mRGB.green, mRGB.blue); + err |= led_strip_refresh(strip); +#endif if (err != ESP_OK) { ESP_LOGE(TAG, "strip_refresh failed"); } diff --git a/docs/en/developing.rst b/docs/en/developing.rst index 6bedc2674..e2b6f793a 100644 --- a/docs/en/developing.rst +++ b/docs/en/developing.rst @@ -41,7 +41,7 @@ The Prerequisites for ESP-IDF and Matter: :: git clone --recursive https://github.com/espressif/esp-idf.git - cd esp-idf; git checkout 047903c; git submodule update --init --recursive; + cd esp-idf; git checkout ccdeb43cc7; git submodule update --init --recursive; ./install.sh cd .. diff --git a/examples/blemesh_bridge/CMakeLists.txt b/examples/blemesh_bridge/CMakeLists.txt index 9ad7d3037..cf6dfc9ea 100644 --- a/examples/blemesh_bridge/CMakeLists.txt +++ b/examples/blemesh_bridge/CMakeLists.txt @@ -28,7 +28,6 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(EXTRA_COMPONENT_DIRS "../common" - "${IDF_PATH}/examples/common_components/qrcode" "${MATTER_SDK_PATH}/config/esp32/components" "${ESP_MATTER_PATH}/components" "${ESP_MATTER_PATH}/device_hal/device" diff --git a/examples/common/app_ble/app_ble.cpp b/examples/common/app_ble/app_ble.cpp index 0e71b93cd..f30e090ff 100644 --- a/examples/common/app_ble/app_ble.cpp +++ b/examples/common/app_ble/app_ble.cpp @@ -13,7 +13,9 @@ #include #include +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include +#endif #include #include @@ -33,7 +35,10 @@ esp_err_t app_ble_disable() return ESP_FAIL; } nimble_port_deinit(); - esp_err_t err = esp_nimble_hci_and_controller_deinit(); + esp_err_t err = ESP_OK; +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + err = esp_nimble_hci_and_controller_deinit(); +#endif err |= esp_bt_mem_release(ESP_BT_MODE_BLE); if (err != ESP_OK) { ESP_LOGE(TAG, "BLE deinit failed"); diff --git a/examples/common/app_qrcode/idf_component.yml b/examples/common/app_qrcode/idf_component.yml new file mode 100644 index 000000000..ed852323c --- /dev/null +++ b/examples/common/app_qrcode/idf_component.yml @@ -0,0 +1,2 @@ +dependencies: + qrcode: "^0.1.0" diff --git a/examples/light/CMakeLists.txt b/examples/light/CMakeLists.txt index 9aeef3e00..8ebac2024 100644 --- a/examples/light/CMakeLists.txt +++ b/examples/light/CMakeLists.txt @@ -30,7 +30,6 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(EXTRA_COMPONENT_DIRS "../common" - "${IDF_PATH}/examples/common_components/qrcode" "${MATTER_SDK_PATH}/config/esp32/components" "${ESP_MATTER_PATH}/components" "${ESP_MATTER_PATH}/device_hal/device" @@ -38,8 +37,8 @@ set(EXTRA_COMPONENT_DIRS project(light) -idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) -idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND) # For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various # flags that depend on -Wformat -idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) +idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security;-Wformat=0" APPEND) diff --git a/examples/light/main/CMakeLists.txt b/examples/light/main/CMakeLists.txt index b9a2c8e4b..90c133dcc 100644 --- a/examples/light/main/CMakeLists.txt +++ b/examples/light/main/CMakeLists.txt @@ -5,4 +5,4 @@ idf_component_register(SRC_DIRS "." PRIV_REQUIRES ${PRIV_REQUIRES_LIST}) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14) -target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H") +target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/light/sdkconfig.defaults.esp32h2 b/examples/light/sdkconfig.defaults.esp32h2 index b94164d2f..284707ca2 100644 --- a/examples/light/sdkconfig.defaults.esp32h2 +++ b/examples/light/sdkconfig.defaults.esp32h2 @@ -1,4 +1,5 @@ CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y # Default to 921600 baud when flashing and monitoring device CONFIG_ESPTOOLPY_BAUD_921600B=y @@ -12,17 +13,12 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 # libsodium CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y - -# Enable NIMBLE which is mynewt_nimble component out of bt component -# It will be merge to bt component soon +# NIMBLE CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_USE_ESP_TIMER=n -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n # FreeRTOS should use legacy API CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y @@ -46,6 +42,7 @@ CONFIG_LWIP_MULTICAST_PING=y CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_HARDWARE_ECC=y CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n CONFIG_MBEDTLS_CMAC_C=y @@ -54,22 +51,18 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y # MDNS platform CONFIG_USE_MINIMAL_MDNS=n - -# Increase stacks size -CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120 -CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120 - -# ESP32H2 BLE using a ext 32k crystal -CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y +CONFIG_ENABLE_EXTENDED_DISCOVERY=y # Enable OTA Requestor CONFIG_ENABLE_OTA_REQUESTOR=y +# Disable STA and AP for ESP32H2 +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_AP=n + # Button CONFIG_BUTTON_PERIOD_TIME_MS=20 CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 -# disable chip-shell -# chip shell includes wifi commands which will cause a compiling error of RegisterWiFicommands -# It should be fixed on upstream repo -CONFIG_ENABLE_CHIP_SHELL=n +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/light_switch/CMakeLists.txt b/examples/light_switch/CMakeLists.txt index 669ad2260..cb549433a 100644 --- a/examples/light_switch/CMakeLists.txt +++ b/examples/light_switch/CMakeLists.txt @@ -28,7 +28,6 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(EXTRA_COMPONENT_DIRS "../common" - "${IDF_PATH}/examples/common_components/qrcode" "${MATTER_SDK_PATH}/config/esp32/components" "${ESP_MATTER_PATH}/components" "${ESP_MATTER_PATH}/device_hal/device" @@ -36,8 +35,8 @@ set(EXTRA_COMPONENT_DIRS project(light_switch) -idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) -idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND) # For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various # flags that depend on -Wformat -idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) +idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security;;-Wformat=0" APPEND) diff --git a/examples/light_switch/main/CMakeLists.txt b/examples/light_switch/main/CMakeLists.txt index b9a2c8e4b..90c133dcc 100644 --- a/examples/light_switch/main/CMakeLists.txt +++ b/examples/light_switch/main/CMakeLists.txt @@ -5,4 +5,4 @@ idf_component_register(SRC_DIRS "." PRIV_REQUIRES ${PRIV_REQUIRES_LIST}) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14) -target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H") +target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/light_switch/sdkconfig.defaults.esp32h2 b/examples/light_switch/sdkconfig.defaults.esp32h2 index b94164d2f..284707ca2 100644 --- a/examples/light_switch/sdkconfig.defaults.esp32h2 +++ b/examples/light_switch/sdkconfig.defaults.esp32h2 @@ -1,4 +1,5 @@ CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y # Default to 921600 baud when flashing and monitoring device CONFIG_ESPTOOLPY_BAUD_921600B=y @@ -12,17 +13,12 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 # libsodium CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y - -# Enable NIMBLE which is mynewt_nimble component out of bt component -# It will be merge to bt component soon +# NIMBLE CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_USE_ESP_TIMER=n -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n # FreeRTOS should use legacy API CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y @@ -46,6 +42,7 @@ CONFIG_LWIP_MULTICAST_PING=y CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_HARDWARE_ECC=y CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n CONFIG_MBEDTLS_CMAC_C=y @@ -54,22 +51,18 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y # MDNS platform CONFIG_USE_MINIMAL_MDNS=n - -# Increase stacks size -CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120 -CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120 - -# ESP32H2 BLE using a ext 32k crystal -CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y +CONFIG_ENABLE_EXTENDED_DISCOVERY=y # Enable OTA Requestor CONFIG_ENABLE_OTA_REQUESTOR=y +# Disable STA and AP for ESP32H2 +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_AP=n + # Button CONFIG_BUTTON_PERIOD_TIME_MS=20 CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 -# disable chip-shell -# chip shell includes wifi commands which will cause a compiling error of RegisterWiFicommands -# It should be fixed on upstream repo -CONFIG_ENABLE_CHIP_SHELL=n +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/zap_light/CMakeLists.txt b/examples/zap_light/CMakeLists.txt index e836ac925..c4819269f 100644 --- a/examples/zap_light/CMakeLists.txt +++ b/examples/zap_light/CMakeLists.txt @@ -30,7 +30,6 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(EXTRA_COMPONENT_DIRS "../common" - "${IDF_PATH}/examples/common_components/qrcode" "${MATTER_SDK_PATH}/config/esp32/components" "${ESP_MATTER_PATH}/components" "${ESP_MATTER_PATH}/device_hal/device" @@ -38,8 +37,8 @@ set(EXTRA_COMPONENT_DIRS project(zap_light) -idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) -idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND) # For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various # flags that depend on -Wformat -idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) +idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security;-Wformat=0" APPEND) diff --git a/examples/zap_light/main/CMakeLists.txt b/examples/zap_light/main/CMakeLists.txt index 3ac9120af..8903feced 100644 --- a/examples/zap_light/main/CMakeLists.txt +++ b/examples/zap_light/main/CMakeLists.txt @@ -5,4 +5,4 @@ idf_component_register(SRC_DIRS "." PRIV_REQUIRES ${PRIV_REQUIRES_LIST}) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14) -target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H") +target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/zap_light/sdkconfig.defaults.esp32h2 b/examples/zap_light/sdkconfig.defaults.esp32h2 index afc0fdcc8..284707ca2 100644 --- a/examples/zap_light/sdkconfig.defaults.esp32h2 +++ b/examples/zap_light/sdkconfig.defaults.esp32h2 @@ -1,4 +1,5 @@ CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y # Default to 921600 baud when flashing and monitoring device CONFIG_ESPTOOLPY_BAUD_921600B=y @@ -12,17 +13,12 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 # libsodium CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y - -# Enable NIMBLE which is mynewt_nimble component out of bt component -# It will be merge to bt component soon +# NIMBLE CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_USE_ESP_TIMER=n -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n # FreeRTOS should use legacy API CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y @@ -46,6 +42,7 @@ CONFIG_LWIP_MULTICAST_PING=y CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_HARDWARE_ECC=y CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n CONFIG_MBEDTLS_CMAC_C=y @@ -54,19 +51,18 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y # MDNS platform CONFIG_USE_MINIMAL_MDNS=n +CONFIG_ENABLE_EXTENDED_DISCOVERY=y -# Increase stacks size -CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120 -CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120 +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y -# ESP32H2 BLE using a ext 32k crystal -CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y +# Disable STA and AP for ESP32H2 +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_AP=n # Button CONFIG_BUTTON_PERIOD_TIME_MS=20 CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 -# disable chip-shell -# chip shell includes wifi commands which will cause a compiling error of RegisterWiFicommands -# It should be fixed on upstream repo -CONFIG_ENABLE_CHIP_SHELL=n +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/zigbee_bridge/CMakeLists.txt b/examples/zigbee_bridge/CMakeLists.txt index 8a6d6ac4e..1c845be57 100644 --- a/examples/zigbee_bridge/CMakeLists.txt +++ b/examples/zigbee_bridge/CMakeLists.txt @@ -7,12 +7,11 @@ if(NOT DEFINED ENV{ESP_MATTER_PATH}) endif(NOT DEFINED ENV{ESP_MATTER_PATH}) if(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH}) - if("${IDF_TARGET}" STREQUAL "esp32" OR "${IDF_TARGET}" STREQUAL "") - set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32_devkit_c) - elseif("${IDF_TARGET}" STREQUAL "esp32c3") - set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c3_devkit_m) - elseif("${IDF_TARGET}" STREQUAL "esp32s3") - set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32s3_devkit_c) + if("${IDF_TARGET}" STREQUAL "" OR "${IDF_TARGET}" STREQUAL "esp32" OR "${IDF_TARGET}" STREQUAL "esp32c3" OR "${IDF_TARGET}" STREQUAL "esp32s3") + # use hollow device type because the iot button has a require of 'esp_adc_cal' + # which is renamed to 'esp_adc' in IDF v5.0 + # TODO: set the ESP_MATTER_DEVICE_PATH to a certain target. + set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/hollow) else() message(FATAL_ERROR "Unsupported IDF_TARGET") endif() @@ -28,7 +27,6 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(EXTRA_COMPONENT_DIRS "../common" - "${IDF_PATH}/examples/common_components/qrcode" "${MATTER_SDK_PATH}/config/esp32/components" "${ESP_MATTER_PATH}/components" "${ESP_MATTER_PATH}/device_hal/device" @@ -40,4 +38,4 @@ idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES= idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) # For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various # flags that depend on -Wformat -idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) +idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security;-Wformat=0;-Wno-error=cpp" APPEND) diff --git a/examples/zigbee_bridge/main/CMakeLists.txt b/examples/zigbee_bridge/main/CMakeLists.txt index b9158b4ee..0aa019289 100644 --- a/examples/zigbee_bridge/main/CMakeLists.txt +++ b/examples/zigbee_bridge/main/CMakeLists.txt @@ -1,5 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode esp_matter_ota app_bridge - esp-zboss-lib) +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode esp_matter_ota app_bridge esp-zigbee-lib) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." diff --git a/examples/zigbee_bridge/main/app_main.cpp b/examples/zigbee_bridge/main/app_main.cpp index 1cf6b5af6..43eb8cc32 100644 --- a/examples/zigbee_bridge/main/app_main.cpp +++ b/examples/zigbee_bridge/main/app_main.cpp @@ -15,9 +15,9 @@ #include #include +#include #include #include -#include #include static const char *TAG = "app_main"; diff --git a/examples/zigbee_bridge/main/app_zboss.cpp b/examples/zigbee_bridge/main/app_zboss.cpp index 0a0e839a8..4816b45cf 100644 --- a/examples/zigbee_bridge/main/app_zboss.cpp +++ b/examples/zigbee_bridge/main/app_zboss.cpp @@ -6,15 +6,15 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "zigbee_bridge.h" #include #include #include +#include #include #include -#include +#include -#if (!defined ZB_MACSPLIT_HOST) +#if (!defined(ZB_MACSPLIT_HOST) && defined(ZB_MACSPLIT_DEVICE)) #error "Zigbee host option should be enabled to use this example" #endif @@ -22,9 +22,7 @@ static const char *TAG = "esp_zboss"; static void bdb_start_top_level_commissioning_cb(zb_uint8_t mode_mask) { - if (!bdb_start_top_level_commissioning(mode_mask)) { - ESP_LOGE(TAG, "In BDB commissioning, an error occurred (for example: the device has already been running)"); - } + ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); } /** @@ -40,21 +38,35 @@ void zboss_signal_handler(zb_bufid_t bufid) zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, &p_sg_p); zb_ret_t status = ZB_GET_APP_SIGNAL_STATUS(bufid); zb_zdo_signal_device_annce_params_t *device_annce_params = NULL; + zb_zdo_signal_macsplit_dev_boot_params_t *rcp_version = NULL; + zb_uint32_t gateway_version; switch (sig) { case ZB_ZDO_SIGNAL_SKIP_STARTUP: ESP_LOGI(TAG, "Zigbee stack initialized"); - bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION); + esp_zb_bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION); break; case ZB_MACSPLIT_DEVICE_BOOT: ESP_LOGI(TAG, "Zigbee rcp device booted"); + gateway_version = esp_zb_macsplit_get_version(); + rcp_version = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_macsplit_dev_boot_params_t); + ESP_LOGI(TAG, "Zigbee rcp device version: %d.%d.%d", (rcp_version->dev_version >> 24 & 0x000000FF), + (rcp_version->dev_version >> 16 & 0x000000FF), (rcp_version->dev_version & 0x000000FF)); + ESP_LOGI(TAG, "Zigbee gateway version: %d.%d.%d", (gateway_version >> 24 & 0x000000FF), + (gateway_version >> 16 & 0x000000FF), (gateway_version & 0x000000FF)); + if (gateway_version != rcp_version->dev_version) { + ESP_LOGE(TAG, + "rcp has different Zigbee stack version with Zigbee gateway! Please check the rcp software or " + "other issues"); + } break; case ZB_BDB_SIGNAL_DEVICE_FIRST_START: + case ZB_BDB_SIGNAL_DEVICE_REBOOT: if (status == RET_OK) { ESP_LOGI(TAG, "Start network formation"); - bdb_start_top_level_commissioning(ZB_BDB_NETWORK_FORMATION); + esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_FORMATION); } else { ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", status); } @@ -68,7 +80,7 @@ void zboss_signal_handler(zb_bufid_t bufid) ESP_LOGI(TAG, "ieee extended address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx)", ieee_address[7], ieee_address[6], ieee_address[5], ieee_address[4], ieee_address[3], ieee_address[2], ieee_address[1], ieee_address[0], ZB_PIBCACHE_PAN_ID()); - bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING); + esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING); } else { ESP_LOGI(TAG, "Restart network formation (status: %d)", status); ZB_SCHEDULE_APP_ALARM((zb_callback_t)bdb_start_top_level_commissioning_cb, ZB_BDB_NETWORK_FORMATION, @@ -85,18 +97,10 @@ void zboss_signal_handler(zb_bufid_t bufid) case ZB_ZDO_SIGNAL_DEVICE_ANNCE: device_annce_params = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_device_annce_params_t); ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", device_annce_params->device_short_addr); - status = - ZB_SCHEDULE_APP_ALARM(zigbee_bridge_match_bridged_onoff_light, bufid, MATCH_BRIDGED_DEVICE_START_DELAY); - if (status != RET_OK) { - ESP_LOGD(TAG, "Could not start schedule alarm for matching bridged device"); - } - status = - ZB_SCHEDULE_APP_ALARM(zigbee_bridge_match_bridged_onoff_light_timeout, bufid, MATCH_BRIDGED_DEVICE_TIMEOUT); - if (status != RET_OK) { - ESP_LOGD(TAG, "Could not start schedule alarm for matching bridged device timeout"); - } - // this buf will be free in zboss_match_bridged_device_callback/zboss_match_bridged_device_timeout later - bufid = 0; + esp_zb_zdo_match_desc_req_param_t cmd_req; + cmd_req.dst_nwk_addr = device_annce_params->device_short_addr; + cmd_req.addr_of_interest = device_annce_params->device_short_addr; + esp_zb_zdo_find_on_off_light(&cmd_req, zigbee_bridge_find_bridged_on_off_light_cb); break; default: @@ -109,27 +113,23 @@ void zboss_signal_handler(zb_bufid_t bufid) } } -void zboss_task() +static void zboss_task(void *pvParameters) { - ZB_INIT("zigbee bridge"); - zb_set_network_coordinator_role(IEEE_CHANNEL_MASK); - zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG); - zb_set_max_children(MAX_CHILDREN); + /* initialize Zigbee stack with Zigbee coordinator config */ + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG(); + esp_zb_init(&zb_nwk_cfg); /* initiate Zigbee Stack start without zb_send_no_autostart_signal auto-start */ - ESP_ERROR_CHECK(zboss_start_no_autostart()); - while (1) { - zboss_main_loop_iteration(); - vTaskDelay(10 / portTICK_PERIOD_MS); - } + ESP_ERROR_CHECK(esp_zb_start(false)); + esp_zb_main_loop_iteration(); } void launch_app_zboss(void) { - zb_esp_platform_config_t config = { - .radio_config = ZB_ESP_DEFAULT_RADIO_CONFIG(), - .host_config = ZB_ESP_DEFAULT_HOST_CONFIG(), + esp_zb_platform_config_t config = { + .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), }; /* load Zigbee gateway platform config to initialization */ - ESP_ERROR_CHECK(zb_esp_platform_config(&config)); + ESP_ERROR_CHECK(esp_zb_platform_config(&config)); xTaskCreate(zboss_task, "zboss_main", 10240, xTaskGetCurrentTaskHandle(), 5, NULL); } diff --git a/examples/zigbee_bridge/main/app_zboss.h b/examples/zigbee_bridge/main/app_zboss.h index ec2793a04..65490bf8f 100644 --- a/examples/zigbee_bridge/main/app_zboss.h +++ b/examples/zigbee_bridge/main/app_zboss.h @@ -8,22 +8,26 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif +#include "esp_err.h" #include -#include /*Zigbee Configuration*/ -#define IEEE_CHANNEL_MASK (1l << 22) /**< Zigbee default channel */ -#define ERASE_PERSISTENT_CONFIG ZB_TRUE /**< Full device erase for all network devices before running example. */ -#define MAX_CHILDREN 10 /**< The maximum amount of connected devices */ +#define MAX_CHILDREN 10 /* < The maximum amount of connected devices */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ -#define MATCH_DESC_REQ_ROLE ZB_NWK_BROADCAST_RX_ON_WHEN_IDLE -#define MATCH_BRIDGED_DEVICE_START_DELAY (2 * ZB_TIME_ONE_SECOND) -#define MATCH_BRIDGED_DEVICE_TIMEOUT (5 * ZB_TIME_ONE_SECOND) +#define ESP_ZB_ZC_CONFIG() \ + { \ + .esp_zb_role = ESP_ZB_DEVICE_TYPE_COORDINATOR, \ + .install_code_policy = INSTALLCODE_POLICY_ENABLE, \ + .nwk_cfg = { \ + .zczr_cfg = \ + { \ + .max_children = MAX_CHILDREN, \ + }, \ + }, \ + } -#define ZB_ESP_DEFAULT_RADIO_CONFIG() \ +#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ { \ .radio_mode = RADIO_MODE_UART_RCP, \ .radio_uart_config = { \ @@ -43,12 +47,9 @@ extern "C" { }, \ } -#define ZB_ESP_DEFAULT_HOST_CONFIG() \ +#define ESP_ZB_DEFAULT_HOST_CONFIG() \ { \ .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ } void launch_app_zboss(void); -#ifdef __cplusplus -} -#endif diff --git a/examples/zigbee_bridge/main/idf_component.yml b/examples/zigbee_bridge/main/idf_component.yml index 9825e1cd1..4aa45948f 100644 --- a/examples/zigbee_bridge/main/idf_component.yml +++ b/examples/zigbee_bridge/main/idf_component.yml @@ -1,6 +1,9 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "~=0.0.4" + espressif/esp-zboss-lib: "~0.1.0" + espressif/esp-zigbee-lib: "~0.1.1" + qrcode: "^0.1.0" + espressif/mdns: "^1.0.3" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee_bridge/main/zigbee_bridge.cpp b/examples/zigbee_bridge/main/zigbee_bridge.cpp index 7f56a1939..d81f67cc6 100644 --- a/examples/zigbee_bridge/main/zigbee_bridge.cpp +++ b/examples/zigbee_bridge/main/zigbee_bridge.cpp @@ -6,16 +6,12 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "esp_err.h" -#include "esp_matter_bridge.h" +#include #include +#include #include #include - -#include -#include -#include -#include +#include #include static const char *TAG = "zigbee_bridge"; @@ -30,6 +26,7 @@ static esp_err_t zigbee_bridge_init_bridged_onoff_light(esp_matter_bridge_device ESP_LOGE(TAG, "Invalid bridge device to be initialized"); return ESP_ERR_INVALID_ARG; } + on_off::config_t config; on_off::create(dev->endpoint, &config, CLUSTER_MASK_SERVER, ESP_MATTER_NONE_FEATURE_ID); endpoint::set_device_type_id(dev->endpoint, endpoint::on_off_light::get_device_type_id()); @@ -40,85 +37,33 @@ static esp_err_t zigbee_bridge_init_bridged_onoff_light(esp_matter_bridge_device } return ESP_OK; } - -void zigbee_bridge_match_bridged_onoff_light_cb(zb_bufid_t bufid) +void zigbee_bridge_find_bridged_on_off_light_cb(zb_uint8_t zdo_status, zb_uint16_t addr, zb_uint8_t endpoint) { - zb_zdo_match_desc_resp_t *p_resp = (zb_zdo_match_desc_resp_t *)zb_buf_begin(bufid); - zb_apsde_data_indication_t *p_ind = ZB_BUF_GET_PARAM(bufid, zb_apsde_data_indication_t); - zb_uint8_t *p_match_ep; - zb_ret_t zb_err_code; - esp_err_t ret = ESP_OK; - - if ((p_resp->status == ZB_ZDP_STATUS_SUCCESS) && (p_resp->match_len > 0)) { - p_match_ep = (zb_uint8_t *)(p_resp + 1); + ESP_LOGI(TAG, "on_off_light found: address:0x%x, endpoint:%d, response_status:%d", addr, endpoint, zdo_status); + if (zdo_status == ZB_ZDP_STATUS_SUCCESS) { node_t *node = node::get(); - ESP_GOTO_ON_FALSE(node, ESP_ERR_INVALID_STATE, exit, TAG, "Could not find esp_matter node"); - if (app_bridge_get_device_by_zigbee_shortaddr(p_ind->src_addr)) { - ESP_LOGI(TAG, "Bridged node for 0x%04x zigbee device on endpoint %d has been created", p_ind->src_addr, - app_bridge_get_matter_endpointid_by_zigbee_shortaddr(p_ind->src_addr)); + if (!node) { + ESP_LOGE(TAG, "Could not find esp_matter node"); + return; + } + if (app_bridge_get_device_by_zigbee_shortaddr(addr)) { + ESP_LOGI(TAG, "Bridged node for 0x%04x zigbee device on endpoint %d has been created", addr, + app_bridge_get_matter_endpointid_by_zigbee_shortaddr(addr)); } else { - app_bridged_device_t *bridged_device = app_bridge_create_bridged_device(node, ESP_MATTER_BRIDGED_DEVICE_TYPE_ZIGBEE, app_bridge_zigbee_address(*p_match_ep, p_ind->src_addr)); - ESP_GOTO_ON_FALSE(bridged_device, ESP_FAIL, exit, TAG, "Failed to create zigbee bridged device (on_off light)"); - ESP_GOTO_ON_ERROR(zigbee_bridge_init_bridged_onoff_light(bridged_device->dev), exit, TAG, "Failed to initialize the bridged node"); - ESP_LOGI(TAG, "Create/Update bridged node for 0x%04x zigbee device on endpoint %d", p_ind->src_addr, - app_bridge_get_matter_endpointid_by_zigbee_shortaddr(p_ind->src_addr)); - } - zb_err_code = ZB_SCHEDULE_APP_ALARM_CANCEL(zigbee_bridge_match_bridged_onoff_light_timeout, ZB_ALARM_ANY_PARAM); - if (zb_err_code != RET_OK) { - ESP_LOGE(TAG, "Failed to cancel alarm for match_bridged_device_timeout"); + app_bridged_device_t *bridged_device = app_bridge_create_bridged_device( + node, ESP_MATTER_BRIDGED_DEVICE_TYPE_ZIGBEE, app_bridge_zigbee_address(endpoint, addr)); + if (!bridged_device) { + ESP_LOGE(TAG, "Failed to create zigbee bridged device (on_off light)"); + return; + } + if (zigbee_bridge_init_bridged_onoff_light(bridged_device->dev) != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize the bridged node"); + return; + } + ESP_LOGI(TAG, "Create/Update bridged node for 0x%04x zigbee device on endpoint %d", addr, + app_bridge_get_matter_endpointid_by_zigbee_shortaddr(addr)); } } -exit: - if (bufid) { - zb_buf_free(bufid); - } -} - -void zigbee_bridge_match_bridged_onoff_light(zb_bufid_t bufid) -{ - zb_zdo_match_desc_param_t *p_req; - - zb_zdo_app_signal_hdr_t *p_sg_p = NULL; - zb_get_app_signal(bufid, &p_sg_p); - zb_zdo_signal_device_annce_params_t *dev_annce_params = - ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_device_annce_params_t); - - zb_uint16_t shortaddr = dev_annce_params->device_short_addr; - p_req = (zb_zdo_match_desc_param_t *)zb_buf_initial_alloc( - bufid, sizeof(zb_zdo_match_desc_param_t) + (1) * sizeof(zb_uint16_t)); - p_req->nwk_addr = shortaddr; - p_req->addr_of_interest = shortaddr; - p_req->profile_id = ZB_AF_HA_PROFILE_ID; - - p_req->num_in_clusters = 1; - p_req->num_out_clusters = 0; - p_req->cluster_list[0] = ZB_ZCL_CLUSTER_ID_ON_OFF; - - zb_zdo_match_desc_req(bufid, zigbee_bridge_match_bridged_onoff_light_cb); -} - -void zigbee_bridge_match_bridged_onoff_light_timeout(zb_bufid_t bufid) -{ - ESP_LOGE(TAG, "The device is not an onoff light"); - if (bufid) { - zb_buf_free(bufid); - } -} - -void zigbee_bridge_send_on(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr) -{ - app_bridged_device_t *zigbee_device = app_bridge_get_device_by_zigbee_shortaddr(zigbee_shortaddr); - ZB_ZCL_ON_OFF_SEND_REQ(buf, zigbee_shortaddr, ZB_APS_ADDR_MODE_16_ENDP_PRESENT, zigbee_device->dev_addr.zigbee_endpointid, - zigbee_device->dev->endpoint_id, ZB_AF_HA_PROFILE_ID, ZB_ZCL_DISABLE_DEFAULT_RESPONSE, - ZB_ZCL_CMD_ON_OFF_ON_ID, NULL); -} - -void zigbee_bridge_send_off(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr) -{ - app_bridged_device_t *zigbee_device = app_bridge_get_device_by_zigbee_shortaddr(zigbee_shortaddr); - ZB_ZCL_ON_OFF_SEND_REQ(buf, zigbee_shortaddr, ZB_APS_ADDR_MODE_16_ENDP_PRESENT, zigbee_device->dev_addr.zigbee_endpointid, - zigbee_device->dev->endpoint_id, ZB_AF_HA_PROFILE_ID, ZB_ZCL_DISABLE_DEFAULT_RESPONSE, - ZB_ZCL_CMD_ON_OFF_OFF_ID, NULL); } esp_err_t zigbee_bridge_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, @@ -128,9 +73,15 @@ esp_err_t zigbee_bridge_attribute_update(uint16_t endpoint_id, uint32_t cluster_ if (zigbee_device && zigbee_device->dev && zigbee_device->dev->endpoint) { if (cluster_id == OnOff::Id) { if (attribute_id == OnOff::Attributes::OnOff::Id) { - ESP_LOGD(TAG, "Update Bridged Device, ep: %d, cluster: %d, att: %d", endpoint_id, cluster_id, attribute_id); - zb_buf_get_out_delayed_ext((val->val.b ? zigbee_bridge_send_on : zigbee_bridge_send_off), - zigbee_device->dev_addr.zigbee_shortaddr, 0); + ESP_LOGD(TAG, "Update Bridged Device, ep: %d, cluster: %d, att: %d", endpoint_id, cluster_id, + attribute_id); + esp_zb_zcl_on_off_cmd_t cmd_req; + cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = zigbee_device->dev_addr.zigbee_shortaddr; + cmd_req.zcl_basic_cmd.dst_endpoint = zigbee_device->dev_addr.zigbee_endpointid; + cmd_req.zcl_basic_cmd.src_endpoint = zigbee_device->dev->endpoint_id; + cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; + cmd_req.on_off_cmd_id = val->val.b ? ZB_ZCL_CMD_ON_OFF_ON_ID : ZB_ZCL_CMD_ON_OFF_OFF_ID; + esp_zb_zcl_on_off_cmd_req(&cmd_req); } } } diff --git a/examples/zigbee_bridge/main/zigbee_bridge.h b/examples/zigbee_bridge/main/zigbee_bridge.h index cc032c994..0446cf380 100644 --- a/examples/zigbee_bridge/main/zigbee_bridge.h +++ b/examples/zigbee_bridge/main/zigbee_bridge.h @@ -7,25 +7,13 @@ */ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - -#include #include -#include -#include +#include +#include +#include -#include - -void zigbee_bridge_match_bridged_onoff_light(zb_bufid_t bufid); - -void zigbee_bridge_match_bridged_onoff_light_timeout(zb_bufid_t bufid); +void zigbee_bridge_find_bridged_on_off_light_cb(zb_uint8_t zdo_status, zb_uint16_t addr, zb_uint8_t endpoint); esp_err_t zigbee_bridge_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val); - -#ifdef __cplusplus -} -#endif diff --git a/examples/zigbee_bridge/partitions.csv b/examples/zigbee_bridge/partitions.csv index 3f2c8cd5a..61438d2ee 100644 --- a/examples/zigbee_bridge/partitions.csv +++ b/examples/zigbee_bridge/partitions.csv @@ -8,3 +8,4 @@ ota_0, app, ota_0, 0x20000, 0x1D0000, ota_1, app, ota_1, , 0x1D0000, fctry, data, nvs, , 0x6000, zb_storage, data, fat, , 0x20000 +zb_fct, data, fat, , 1K, diff --git a/examples/zigbee_bridge/sdkconfig.defaults b/examples/zigbee_bridge/sdkconfig.defaults index 05abd1277..cea934238 100644 --- a/examples/zigbee_bridge/sdkconfig.defaults +++ b/examples/zigbee_bridge/sdkconfig.defaults @@ -36,4 +36,4 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n # Zboss CONFIG_ZB_ENABLED=y CONFIG_ZB_ZCZR=y -CONFIG_ZB_HOST=y +CONFIG_ZB_RADIO_MACSPLIT_UART=y