diff --git a/examples/zigbee/.build-test-rules.yml b/examples/zigbee/.build-test-rules.yml index ecffa999bd51..eb8c7d7bccdb 100644 --- a/examples/zigbee/.build-test-rules.yml +++ b/examples/zigbee/.build-test-rules.yml @@ -8,20 +8,15 @@ examples/zigbee/esp_zigbee_gateway: enable: - - if: SOC_WIFI_SUPPORTED == 1 and IDF_TARGET != "esp32c2" - reason: not supported esp32c2 - <<: *zigbee_dependencies - -examples/zigbee/esp_zigbee_rcp: - enable: - - if: SOC_IEEE802154_SUPPORTED == 1 + - if: SOC_WIFI_SUPPORTED == 1 and IDF_TARGET not in ["esp32c2", "esp32c61"] + reason: not supported esp32c2 and esp32c61 <<: *zigbee_dependencies examples/zigbee/light_sample: enable: - if: SOC_IEEE802154_SUPPORTED == 1 disable_test: - - if: IDF_TARGET == "esp32c6" + - if: IDF_TARGET != "esp32h2" temporary: true reason: only test on esp32h2 <<: *zigbee_dependencies diff --git a/examples/zigbee/common/zcl_utility/include/zcl_utility.h b/examples/zigbee/common/zcl_utility/include/zcl_utility.h new file mode 100644 index 000000000000..760bf7e10b50 --- /dev/null +++ b/examples/zigbee/common/zcl_utility/include/zcl_utility.h @@ -0,0 +1,51 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: LicenseRef-Included + * + * Zigbee Common + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +#include "esp_err.h" +#include "esp_check.h" +#include "esp_zigbee_core.h" + +/*! Maximum length of ManufacturerName string field */ +#define ESP_ZB_ZCL_CLUSTER_ID_BASIC_MANUFACTURER_NAME_MAX_LEN 32 + +/*! Maximum length of ModelIdentifier string field */ +#define ESP_ZB_ZCL_CLUSTER_ID_BASIC_MODEL_IDENTIFIER_MAX_LEN 32 + +/** optional basic manufacturer information */ +typedef struct zcl_basic_manufacturer_info_s { + char *manufacturer_name; + char *model_identifier; +} zcl_basic_manufacturer_info_t; + +/** + * @brief Adds manufacturer information to the ZCL basic cluster of endpoint + * + * @param[in] ep_list The pointer to the endpoint list with @p endpoint_id + * @param[in] endpoint_id The endpoint identifier indicating where the ZCL basic cluster resides + * @param[in] info The pointer to the basic manufacturer information + * @return + * - ESP_OK: On success + * - ESP_ERR_INVALID_ARG: Invalid argument + */ +esp_err_t esp_zcl_utility_add_ep_basic_manufacturer_info(esp_zb_ep_list_t *ep_list, uint8_t endpoint_id, zcl_basic_manufacturer_info_t *info); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/examples/zigbee/common/zcl_utility/src/zcl_utility.c b/examples/zigbee/common/zcl_utility/src/zcl_utility.c new file mode 100644 index 000000000000..c88d6cd8bc8f --- /dev/null +++ b/examples/zigbee/common/zcl_utility/src/zcl_utility.c @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: LicenseRef-Included + * + * Zigbee Common + * + * 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. + */ +#include "esp_check.h" +#include "stdio.h" +#include "string.h" +#include "zcl_utility.h" +#include + +static const char *TAG = "ZCL_UTILITY"; + +esp_err_t esp_zcl_utility_add_ep_basic_manufacturer_info(esp_zb_ep_list_t *ep_list, uint8_t endpoint_id, zcl_basic_manufacturer_info_t *info) +{ + esp_err_t ret = ESP_OK; + esp_zb_cluster_list_t *cluster_list = NULL; + esp_zb_attribute_list_t *basic_cluster = NULL; + + cluster_list = esp_zb_ep_list_get_ep(ep_list, endpoint_id); + ESP_RETURN_ON_FALSE(cluster_list, ESP_ERR_INVALID_ARG, TAG, "Failed to find endpoint id: %d in list: %p", endpoint_id, ep_list); + basic_cluster = esp_zb_cluster_list_get_cluster(cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + ESP_RETURN_ON_FALSE(basic_cluster, ESP_ERR_INVALID_ARG, TAG, "Failed to find basic cluster in endpoint: %d", endpoint_id); + ESP_RETURN_ON_FALSE((info && info->manufacturer_name), ESP_ERR_INVALID_ARG, TAG, "Invalid manufacturer name"); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, info->manufacturer_name)); + ESP_RETURN_ON_FALSE((info && info->model_identifier), ESP_ERR_INVALID_ARG, TAG, "Invalid model identifier"); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, info->model_identifier)); + return ret; +} diff --git a/examples/zigbee/esp_zigbee_gateway/README.md b/examples/zigbee/esp_zigbee_gateway/README.md index 1a6fadfe8f31..0db31c18cc1e 100644 --- a/examples/zigbee/esp_zigbee_gateway/README.md +++ b/examples/zigbee/esp_zigbee_gateway/README.md @@ -13,7 +13,7 @@ The ESP Zigbee SDK provides more examples and tools for productization: By default, two SoCs are required to run this example: * An ESP32 series Wi-Fi SoC (ESP32, ESP32-C, ESP32-S, etc) loaded with this esp_zigbee_gateway example. -* An ESP32-H2 802.15.4 SoC loaded with [esp_zigbee_rcp](../esp_zigbee_rcp) example +* An ESP32-H2 802.15.4 SoC loaded with [ot_rcp](../../openthread/ot_rcp/) example Connect the two SoCs via UART, below is an example setup with ESP32-DevKitC and ESP32-H2-DevKitC: ![Zigbee_gateway](../../openthread/ot_br/image/thread-border-router-esp32-esp32h2.jpg) @@ -28,6 +28,10 @@ ESP32 pin | ESP32-H2 pin The example could also run on a single SoC which supports both Wi-Fi and Zigbee (e.g., ESP32-C6), but since there is only one RF path in ESP32-C6, which means Wi-Fi and Zigbee can't receive simultaneously, it has a significant impact on performance. Hence the two SoCs solution is recommended. +## Configure the RCP + +The `OPENTHREAD_NCP_VENDOR_HOOK` of `ot_rcp` should be selected via menuconfig when the [ot_rcp](../../openthread/ot_rcp/) example is built. Then use `idf.py -p PORT erase-flash` to flash the RCP firmware to ESP32-H2-DevKitC. + ## Configure the project Before project configuration and build, make sure to set the correct chip target using `idf.py set-target `. @@ -50,19 +54,80 @@ As you run the example, you will see the following log: esp_zigbee_gateway: ``` -I (660) ESP_ZB_GATEWAY: status: -1 -I (670) ESP_ZB_GATEWAY: Zigbee stack initialized -I (680) ESP_ZB_GATEWAY: Zigbee rcp device booted -I (1280) ESP_ZB_GATEWAY: Start network formation -I (3060) ESP_ZB_GATEWAY: Formed network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0x8651, Channel:13, Short Address: 0x0000) -I (4060) ESP_ZB_GATEWAY: status: 0 -I (4400) ESP_ZB_GATEWAY: Network steering started +I (499) main_task: Calling app_main() +I (519) ESP_RADIO_SPINEL: spinel UART interface initialization completed +I (519) ESP_RADIO_SPINEL: Spinel UART interface has been successfully enabled +I (519) ZB_ESP_SPINEL: Spinel UART interface enable successfully +I (529) main_task: Returned from app_main() +I(529) OPENTHREAD:[I] P-RadioSpinel-: RCP reset: RESET_POWER_ON +I(539) OPENTHREAD:[I] P-RadioSpinel-: Software reset RCP successfully +I (569) ZB_ESP_SPINEL: Radio spinel workflow register successfully +I (769) ESP_ZB_GATEWAY: Production configuration is ready +W (769) ESP_ZB_GATEWAY: Production configuration is not present +I (769) example_connect: Start example_connect. +I (779) pp: pp rom version: e7ae62f +I (779) net80211: net80211 rom version: e7ae62f +I (799) wifi:wifi driver task: 3fca80d8, prio:23, stack:6656, core=0 +I (799) wifi:wifi firmware version: 3ce09e5 +I (799) wifi:wifi certification version: v7.0 +I (799) wifi:config NVS flash: enabled +I (799) wifi:config nano formatting: disabled +I (809) wifi:Init data frame dynamic rx buffer num: 32 +I (809) wifi:Init static rx mgmt buffer num: 5 +I (819) wifi:Init management short buffer num: 32 +I (819) wifi:Init dynamic tx buffer num: 32 +I (819) wifi:Init static tx FG buffer num: 2 +I (829) wifi:Init static rx buffer size: 1600 +I (829) wifi:Init static rx buffer num: 10 +I (839) wifi:Init dynamic rx buffer num: 32 +I (839) wifi_init: rx ba win: 6 +I (839) wifi_init: tcpip mbox: 32 +I (849) wifi_init: udp mbox: 6 +I (849) wifi_init: tcp mbox: 6 +I (849) wifi_init: tcp tx win: 5760 +I (859) wifi_init: tcp rx win: 5760 +I (859) wifi_init: tcp mss: 1440 +I (869) wifi_init: WiFi IRAM OP enabled +I (869) wifi_init: WiFi RX IRAM OP enabled +I (879) phy_init: phy_version 670,b7bc9b9,Apr 30 2024,10:54:13 +W (879) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration +I (989) wifi:mode : sta (f4:12:fa:41:a7:f4) +I (989) wifi:enable tsf +I (999) example_connect: Connecting to esp-office-2.4G... +I (999) example_connect: Waiting for IP(s) +I (3409) wifi:new:<13,0>, old:<1,0>, ap:<255,255>, sta:<13,0>, prof:1 +I (3649) wifi:state: init -> auth (b0) +I (3719) wifi:state: auth -> assoc (0) +I (3759) wifi:state: assoc -> run (10) +I (3769) wifi:connected with esp-office-2.4G, aid = 1, channel 13, BW20, bssid = 9c:3a:9a:04:18:92 +I (3769) wifi:security: WPA2-PSK, phy: bgn, rssi: -42 +I (3769) wifi:pm start, type: 1 + +I (3779) wifi:dp: 1, bi: 102400, li: 3, scale listen interval from 307200 us to 307200 us +I (3789) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 25000, mt_pti: 0, mt_time: 10000 +I (3819) wifi:AP's beacon interval = 102400 us, DTIM period = 1 +I (3849) wifi:idx:0 (ifx:0, 9c:3a:9a:04:18:92), tid:0, ssn:0, winSize:64 +I (4799) esp_netif_handlers: example_netif_sta ip: 192.168.200.133, mask: 255.255.252.0, gw: 192.168.200.1 +I (4799) example_connect: Got IPv4 event: Interface "example_netif_sta" address: 192.168.200.133 +I (5509) example_connect: Got IPv6 event: Interface "example_netif_sta" address: fe80:0000:0000:0000:f612:faff:fe41:a7f4, type: ESP_IP6_ADDR_IS_LINK_LOCAL +I (5509) example_common: Connected to example_netif_sta +I (5519) example_common: - IPv4 address: 192.168.200.133, +I (5519) example_common: - IPv6 address: fe80:0000:0000:0000:f612:faff:fe41:a7f4, type: ESP_IP6_ADDR_IS_LINK_LOCAL +I (5529) wifi:Set ps type: 0, coexist: 0 + +I (5539) ESP_ZB_GATEWAY: Initialize Zigbee stack +I (5549) ESP_ZB_GATEWAY: Device started up in factory-reset mode +I (5549) ESP_ZB_GATEWAY: Start network formation +W (5729) ESP_ZB_GATEWAY: Network(0xb8e9) closed, devices joining not allowed. +I (5729) ESP_ZB_GATEWAY: Formed network successfully (Extended PAN ID: 60:55:f9:ff:fe:f7:73:e8, PAN ID: 0xb8e9, Channel:13, Short Address: 0x0000) +I (6339) ESP_ZB_GATEWAY: Network(0xb8e9) is open for 180 seconds +I (6339) ESP_ZB_GATEWAY: Network steering started ``` ## Gateway Functions - * After Zigbee gateway starts up, it will read MAC ieee address and Zigbee stack version number from the Zigbee rcp and start working together with Zigbee rcp via UART communication to form a Zigbee network - * More Gateway functionalities supporting Wi-Fi interaction will come later + * When the device starts up, it will attempt to connect to a Wi-Fi network and then interface with the OT-RCP via UART to form a Zigbee network. + * For more Gateway functionalities, please refer to [matter zigbee bridge](https://github.com/espressif/esp-matter/tree/main/examples/bridge_apps/zigbee_bridge/) and [Rainmaker Zigbee Gateway](https://github.com/espressif/esp-rainmaker/tree/master/examples/zigbee_gateway) examples. ## Troubleshooting diff --git a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c index b5fedf4587a2..a0eb05f9500d 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c +++ b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: CC0-1.0 + * SPDX-License-Identifier: LicenseRef-Included * * Zigbee Gateway Example * @@ -17,20 +17,17 @@ #include "freertos/task.h" #include "driver/usb_serial_jtag.h" #include "esp_coexist.h" +#include "esp_check.h" #include "esp_log.h" #include "esp_netif.h" +#include "esp_vfs_dev.h" +#include "esp_vfs_usb_serial_jtag.h" #include "esp_vfs_eventfd.h" #include "esp_wifi.h" #include "nvs_flash.h" #include "protocol_examples_common.h" #include "esp_zigbee_gateway.h" - -#include "driver/uart_vfs.h" -#include "driver/usb_serial_jtag_vfs.h" - -#if (!defined ZB_MACSPLIT_HOST && defined ZB_MACSPLIT_DEVICE) -#error Only Zigbee gateway host device should be defined -#endif +#include "zb_config_platform.h" static const char *TAG = "ESP_ZB_GATEWAY"; @@ -61,7 +58,7 @@ esp_err_t esp_zb_gateway_console_init(void) static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { - ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); + ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee bdb commissioning"); } void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) @@ -70,18 +67,19 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) esp_err_t err_status = signal_struct->esp_err_status; esp_zb_app_signal_type_t sig_type = *p_sg_p; esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; - esp_zb_zdo_signal_macsplit_dev_boot_params_t *rcp_version = NULL; switch (sig_type) { case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: - ESP_LOGI(TAG, "Zigbee stack initialized"); +#if CONFIG_EXAMPLE_CONNECT_WIFI +#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE + esp_coex_wifi_i154_enable(); +#endif /* CONFIG_ESP_COEX_SW_COEXIST_ENABLE */ + ESP_RETURN_ON_FALSE(example_connect() == ESP_OK, , TAG, "Failed to connect to Wi-Fi"); + ESP_RETURN_ON_FALSE(esp_wifi_set_ps(WIFI_PS_MIN_MODEM) == ESP_OK, , TAG, "Failed to set Wi-Fi minimum modem power save type"); +#endif /* CONFIG_EXAMPLE_CONNECT_WIFI */ + ESP_LOGI(TAG, "Initialize Zigbee stack"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); break; - case ESP_ZB_MACSPLIT_DEVICE_BOOT: - ESP_LOGI(TAG, "Zigbee rcp device booted"); - rcp_version = (esp_zb_zdo_signal_macsplit_dev_boot_params_t *)esp_zb_app_signal_get_params(p_sg_p); - ESP_LOGI(TAG, "Running RCP Version: %s", rcp_version->version_str); - break; case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { @@ -90,6 +88,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); } else { + esp_zb_bdb_open_network(180); ESP_LOGI(TAG, "Device rebooted"); } } else { @@ -128,6 +127,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) } } break; + case ESP_ZB_ZDO_SIGNAL_PRODUCTION_CONFIG_READY: + ESP_LOGI(TAG, "Production configuration is %s", err_status == ESP_OK ? "ready" : "not present"); + esp_zb_set_node_descriptor_manufacturer_code(ESP_MANUFACTURER_CODE); + break; default: ESP_LOGI(TAG, "ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); @@ -141,8 +144,25 @@ static void esp_zb_task(void *pvParameters) esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG(); esp_zb_init(&zb_nwk_cfg); esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); + esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create(); + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_endpoint_config_t endpoint_config = { + .endpoint = ESP_ZB_GATEWAY_ENDPOINT, + .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, + .app_device_id = ESP_ZB_HA_REMOTE_CONTROL_DEVICE_ID, + .app_device_version = 0, + }; + + esp_zb_attribute_list_t *basic_cluser = esp_zb_basic_cluster_create(NULL); + esp_zb_basic_cluster_add_attr(basic_cluser, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME); + esp_zb_basic_cluster_add_attr(basic_cluser, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER); + esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluser, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_ep_list_add_gateway_ep(ep_list, cluster_list, endpoint_config); + esp_zb_device_register(ep_list); ESP_ERROR_CHECK(esp_zb_start(false)); - esp_zb_main_loop_iteration(); + esp_zb_stack_main_loop(); + vTaskDelete(NULL); } void app_main(void) @@ -159,14 +179,5 @@ void app_main(void) #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG ESP_ERROR_CHECK(esp_zb_gateway_console_init()); #endif -#if CONFIG_EXAMPLE_CONNECT_WIFI - ESP_ERROR_CHECK(example_connect()); -#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE - ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM)); - esp_coex_wifi_i154_enable(); -#else - ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); -#endif -#endif - xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); + xTaskCreate(esp_zb_task, "Zigbee_main", 8192, NULL, 5, NULL); } diff --git a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h index 2bc61f0e2bd5..03a880bb59c2 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h +++ b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: CC0-1.0 + * SPDX-License-Identifier: LicenseRef-Included * * Zigbee Gateway Example * @@ -19,6 +19,17 @@ #define MAX_CHILDREN 10 /* the max amount of connected devices */ #define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ #define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */ +#define ESP_ZB_GATEWAY_ENDPOINT 1 /* Gateway endpoint identifier */ +#define APP_PROD_CFG_CURRENT_VERSION 0x0001 /* Production configuration version */ + +/* Basic manufacturer information */ +#define ESP_MANUFACTURER_CODE 0x131B /* Customized manufacturer code */ +#define ESP_MANUFACTURER_NAME "\x09""ESPRESSIF" /* Customized manufacturer name */ +#define ESP_MODEL_IDENTIFIER "\x07"CONFIG_IDF_TARGET /* Customized model identifier */ + +/* RCP connection pins */ +#define HOST_RX_PIN_TO_RCP_TX 4 +#define HOST_TX_PIN_TO_RCP_RX 5 #define ESP_ZB_ZC_CONFIG() \ { \ @@ -32,17 +43,17 @@ #if CONFIG_ZB_RADIO_NATIVE #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ { \ - .radio_mode = RADIO_MODE_NATIVE, \ + .radio_mode = ZB_RADIO_MODE_NATIVE, \ } #else #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ { \ - .radio_mode = RADIO_MODE_UART_RCP, \ + .radio_mode = ZB_RADIO_MODE_UART_RCP, \ .radio_uart_config = { \ .port = 1, \ .uart_config = \ { \ - .baud_rate = 115200, \ + .baud_rate = 460800, \ .data_bits = UART_DATA_8_BITS, \ .parity = UART_PARITY_DISABLE, \ .stop_bits = UART_STOP_BITS_1, \ @@ -50,13 +61,13 @@ .rx_flow_ctrl_thresh = 0, \ .source_clk = UART_SCLK_DEFAULT, \ }, \ - .rx_pin = 4, \ - .tx_pin = 5, \ + .rx_pin = HOST_RX_PIN_TO_RCP_TX, \ + .tx_pin = HOST_TX_PIN_TO_RCP_RX, \ }, \ } #endif #define ESP_ZB_DEFAULT_HOST_CONFIG() \ { \ - .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, \ } diff --git a/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml b/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml index 5346a089ab53..d3a34266983c 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml +++ b/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "1.0.9" - espressif/esp-zigbee-lib: "1.0.9" + espressif/esp-zboss-lib: "~1.6.0" + espressif/esp-zigbee-lib: "~1.6.0" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee/esp_zigbee_rcp/CMakeLists.txt b/examples/zigbee/esp_zigbee_rcp/CMakeLists.txt deleted file mode 100644 index 6cf79c44b312..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# For more information about build system see -# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html -# The following five lines of boilerplate have to be in your project's -# CMakeLists in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.16) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp_zigbee_rcp) diff --git a/examples/zigbee/esp_zigbee_rcp/README.md b/examples/zigbee/esp_zigbee_rcp/README.md deleted file mode 100644 index a930b7fc814f..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/README.md +++ /dev/null @@ -1,34 +0,0 @@ -| Supported Targets | ESP32-C6 | ESP32-H2 | -| ----------------- | -------- | -------- | - -# Rcp Example - -This test code shows how to configure Zigbee rcp (radio co-processor) device. Rcp doesn't function alone, it needs to work together with Zigbee gateway (see [esp_zigbee_gateway example](../esp_zigbee_gateway)) - -## Hardware Required - -* One development board with ESP32-H2 SoC acting as Zigbee rcp (loaded with esp_zigbee_rcp example) -* A USB cable for power supply and programming -* Choose ESP32 or ESP32-S3 as Zigbee gateway. The connection and setup refer to the Zigbee gateway example for setup details (see [esp_zigbee_gateway example](../esp_zigbee_gateway)) -* TX, RX pin can be also configured by user in esp_zigbee_rcp.h - -## Configure the project - -Before project configuration and build, make sure to set the correct chip target using `idf.py --preview set-target TARGET` command. - -## Erase the NVRAM - -Before flash it to the board, it is recommended to erase NVRAM if user doesn't want to keep the previous examples or other projects stored info using `idf.py -p PORT erase-flash` - -## Build and Flash - -Build the project, flash it to the board by running `idf.py -p build flash` - -## Rcp Functions - - * After rcp starts up, it will send its own MAC ieee address and Zigbee stack version number to the Zigbee gateway and start working together with Zigbee gateway via UART communication - * For more log info please see Zigbee gateway side - -## Troubleshooting - -For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon diff --git a/examples/zigbee/esp_zigbee_rcp/main/CMakeLists.txt b/examples/zigbee/esp_zigbee_rcp/main/CMakeLists.txt deleted file mode 100644 index fe9c25c12f16..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/main/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "esp_zigbee_rcp.c" - INCLUDE_DIRS ".") diff --git a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c b/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c deleted file mode 100644 index 2c419ab68db6..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: CC0-1.0 - * - * Zigbee RCP Example - * - * 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. - */ - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_log.h" -#include "nvs_flash.h" -#include "zb_scheduler.h" -#include "esp_zigbee_rcp.h" - -#if (defined ZB_MACSPLIT_HOST && !defined ZB_MACSPLIT_DEVICE) -#error Only Zigbee rcp device should be defined -#endif -static const char *TAG = "ESP_ZB_RCP"; - -void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) -{ - uint32_t *p_sg_p = signal_struct->p_app_signal; - esp_err_t err_status = signal_struct->esp_err_status; - esp_zb_app_signal_type_t sig_type = *p_sg_p; - if (err_status == ESP_OK) { - } else if (sig_type == ESP_ZB_ZDO_SIGNAL_PRODUCTION_CONFIG_READY) { - ESP_LOGI(TAG, "Production config is not present or invalid"); - } else { - ESP_LOGI(TAG, "Device started FAILED status %d", err_status); - } -} - -static void esp_zb_task(void *pvParameters) -{ - esp_zb_rcp_init(); - esp_zb_rcp_main_loop_iteration(); -} - -void app_main(void) -{ - esp_zb_platform_config_t config = { - .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), - .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), - }; - ESP_ERROR_CHECK(nvs_flash_init()); - /* load Zigbee rcp platform config to initialization */ - esp_zb_macsplit_set_version(RCP_COMPILE_DEFINE); - ESP_ERROR_CHECK(esp_zb_platform_config(&config)); - xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); -} diff --git a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h b/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h deleted file mode 100644 index c8f59a51a311..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: CC0-1.0 - * - * Zigbee RCP Example - * - * 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. - */ -#include "esp_zigbee_core.h" - -#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ - { \ - .radio_mode = RADIO_MODE_NATIVE, \ - } - -#define ESP_ZB_DEFAULT_HOST_CONFIG() \ - { \ - .host_connection_mode = HOST_CONNECTION_MODE_RCP_UART, \ - .host_uart_config = { \ - .port = 0, \ - .uart_config = \ - { \ - .baud_rate = 115200, \ - .data_bits = UART_DATA_8_BITS, \ - .parity = UART_PARITY_DISABLE, \ - .stop_bits = UART_STOP_BITS_1, \ - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \ - .rx_flow_ctrl_thresh = 0, \ - .source_clk = UART_SCLK_DEFAULT, \ - }, \ - .rx_pin = UART_PIN_NO_CHANGE, \ - .tx_pin = UART_PIN_NO_CHANGE, \ - }, \ - } diff --git a/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml b/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml deleted file mode 100644 index c186c3c8cad5..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml +++ /dev/null @@ -1,7 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/esp-zboss-lib: "1.0.9" - espressif/esp-zigbee-lib: "1.0.9" - ## Required IDF version - idf: - version: ">=5.0.0" diff --git a/examples/zigbee/esp_zigbee_rcp/partitions.csv b/examples/zigbee/esp_zigbee_rcp/partitions.csv deleted file mode 100644 index e72a9f10a232..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/partitions.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 548K, -zb_storage, data, fat, 0x9a000, 16K, diff --git a/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults b/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults deleted file mode 100644 index b337975d5c93..000000000000 --- a/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults +++ /dev/null @@ -1,17 +0,0 @@ -# -# Partition Table -# -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x8000 -CONFIG_PARTITION_TABLE_MD5=y -# end of Partition Table - -# -# ZBOSS Source -# -CONFIG_ZB_ENABLED=y -CONFIG_ZB_RCP=y -# end of ZBOSS Source -# end of Component config diff --git a/examples/zigbee/light_sample/HA_on_off_light/README.md b/examples/zigbee/light_sample/HA_on_off_light/README.md index a22052d60866..cdd245c6b2d6 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/README.md +++ b/examples/zigbee/light_sample/HA_on_off_light/README.md @@ -34,24 +34,28 @@ Build the project, flash it to the board, and start the monitor tool to view the As you run the example, you will see the following log: ``` -I (394) main_task: Calling app_main() -I (404) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 -I (404) phy_init: phy_version 220,2dbbbe7,Sep 25 2023,20:39:25 -I (464) phy: libbtbb version: 90c587c, Sep 25 2023, 20:39:57 -I (474) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL -I (474) ESP_ZB_COLOR_DIMM_LIGHT: Zigbee stack initialized -I (484) ESP_ZB_COLOR_DIMM_LIGHT: Start network steering -I (484) main_task: Returned from app_main() -I (9614) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: NWK Permit Join (0x36), status: ESP_OK -I (9834) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: NWK Permit Join (0x36), status: ESP_OK -I (9834) ESP_ZB_COLOR_DIMM_LIGHT: Joined network successfully (Extended PAN ID: 60:55:f9:00:00:f6:07:b4, PAN ID: 0x2a74, Channel:13) -I (32944) ESP_ZB_COLOR_DIMM_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) -I (32944) ESP_ZB_COLOR_DIMM_LIGHT: Light sets to On -I (33984) ESP_ZB_COLOR_DIMM_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) -I (33984) ESP_ZB_COLOR_DIMM_LIGHT: Light sets to Off -I (35304) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: NLME Status Indication (0x32), status: ESP_OK -I (35534) ESP_ZB_COLOR_DIMM_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) -I (35534) ESP_ZB_COLOR_DIMM_LIGHT: Light sets to On +I (403) app_start: Starting scheduler on CPU0 +I (408) main_task: Started on CPU0 +I (408) main_task: Calling app_main() +I (428) phy: phy_version: 230,2, 9aae6ea, Jan 15 2024, 11:17:12 +I (428) phy: libbtbb version: 944f18e, Jan 15 2024, 11:17:25 +I (438) main_task: Returned from app_main() +I (548) ESP_ZB_ON_OFF_LIGHT: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL +I (548) ESP_ZB_ON_OFF_LIGHT: Initialize Zigbee stack +W (548) rmt: channel resolution loss, real=10666666 +I (558) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 +I (548) ESP_ZB_ON_OFF_LIGHT: Deferred driver initialization successful +I (568) ESP_ZB_ON_OFF_LIGHT: Device started up in factory-reset mode +I (578) ESP_ZB_ON_OFF_LIGHT: Start network steering +I (3558) ESP_ZB_ON_OFF_LIGHT: Joined network successfully (Extended PAN ID: 74:4d:bd:ff:fe:63:f7:30, PAN ID: 0x13af, Channel:13, Short Address: 0x7c16) +I (10238) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) +I (10238) ESP_ZB_ON_OFF_LIGHT: Light sets to On +I (10798) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) +I (10798) ESP_ZB_ON_OFF_LIGHT: Light sets to Off +I (11228) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) +I (11228) ESP_ZB_ON_OFF_LIGHT: Light sets to On +I (11618) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1) +I (11618) ESP_ZB_ON_OFF_LIGHT: Light sets to Off ``` ## Light Control Functions diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/CMakeLists.txt b/examples/zigbee/light_sample/HA_on_off_light/main/CMakeLists.txt index 61bef7bbbef9..15343efb83ce 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/CMakeLists.txt +++ b/examples/zigbee/light_sample/HA_on_off_light/main/CMakeLists.txt @@ -1,6 +1,4 @@ idf_component_register( - SRCS - "esp_zb_light.c" - "light_driver.c" - INCLUDE_DIRS "." + SRC_DIRS "." "../../../common/zcl_utility/src" + INCLUDE_DIRS "." "../../../common/zcl_utility/include" ) diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c index a77ac5dc94f6..4f3256c5578c 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c +++ b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: CC0-1.0 + * SPDX-License-Identifier: LicenseRef-Included * * Zigbee HA_on_off_light Example * @@ -11,7 +11,6 @@ * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. */ - #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_check.h" @@ -26,9 +25,15 @@ static const char *TAG = "ESP_ZB_ON_OFF_LIGHT"; /********************* Define functions **************************/ +static esp_err_t deferred_driver_init(void) +{ + light_driver_init(LIGHT_DEFAULT_OFF); + return ESP_OK; +} + static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { - ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); + ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee commissioning"); } void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) @@ -38,12 +43,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) esp_zb_app_signal_type_t sig_type = *p_sg_p; switch (sig_type) { case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: - ESP_LOGI(TAG, "Zigbee stack initialized"); + ESP_LOGI(TAG, "Initialize Zigbee stack"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); break; case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { + ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); @@ -119,11 +125,17 @@ static void esp_zb_task(void *pvParameters) esp_zb_init(&zb_nwk_cfg); esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG(); esp_zb_ep_list_t *esp_zb_on_off_light_ep = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg); + zcl_basic_manufacturer_info_t info = { + .manufacturer_name = ESP_MANUFACTURER_NAME, + .model_identifier = ESP_MODEL_IDENTIFIER, + }; + + esp_zcl_utility_add_ep_basic_manufacturer_info(esp_zb_on_off_light_ep, HA_ESP_LIGHT_ENDPOINT, &info); esp_zb_device_register(esp_zb_on_off_light_ep); esp_zb_core_action_handler_register(zb_action_handler); esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); ESP_ERROR_CHECK(esp_zb_start(false)); - esp_zb_main_loop_iteration(); + esp_zb_stack_main_loop(); } void app_main(void) @@ -134,6 +146,5 @@ void app_main(void) }; ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_zb_platform_config(&config)); - light_driver_init(LIGHT_DEFAULT_OFF); xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); } diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h index 5def811a87fb..3f4a751c6729 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h +++ b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: CC0-1.0 + * SPDX-License-Identifier: LicenseRef-Included * * Zigbee HA_on_off_light Example * @@ -14,13 +14,18 @@ #include "esp_zigbee_core.h" #include "light_driver.h" +#include "zcl_utility.h" /* Zigbee configuration */ -#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ -#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN -#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */ -#define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */ -#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ +#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN /* aging timeout of device */ +#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */ +#define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ + +/* Basic manufacturer information */ +#define ESP_MANUFACTURER_NAME "\x09""ESPRESSIF" /* Customized manufacturer name */ +#define ESP_MODEL_IDENTIFIER "\x07"CONFIG_IDF_TARGET /* Customized model identifier */ #define ESP_ZB_ZED_CONFIG() \ { \ @@ -34,10 +39,10 @@ #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ { \ - .radio_mode = RADIO_MODE_NATIVE, \ + .radio_mode = ZB_RADIO_MODE_NATIVE, \ } #define ESP_ZB_DEFAULT_HOST_CONFIG() \ { \ - .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, \ } diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml b/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml index 8578e73e678c..198da019c3d5 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml +++ b/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "1.0.9" - espressif/esp-zigbee-lib: "1.0.9" + espressif/esp-zboss-lib: "~1.6.0" + espressif/esp-zigbee-lib: "~1.6.0" espressif/led_strip: "~2.0.0" ## Required IDF version idf: diff --git a/examples/zigbee/light_sample/HA_on_off_switch/README.md b/examples/zigbee/light_sample/HA_on_off_switch/README.md index b02dc682ecec..a1b87dfb0856 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/README.md +++ b/examples/zigbee/light_sample/HA_on_off_switch/README.md @@ -34,31 +34,34 @@ Build the project, flash it to the board, and start the monitor tool to view the As you run the example, you will see the following log: ``` -I (388) main_task: Calling app_main() -I (398) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2 -I (398) phy_init: phy_version 220,2dbbbe7,Sep 25 2023,20:39:25 -I (478) phy: libbtbb version: 90c587c, Sep 25 2023, 20:39:57 -I (488) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL -I (488) ESP_ZB_ON_OFF_SWITCH: Zigbee stack initialized -I (488) ESP_ZB_ON_OFF_SWITCH: Start network formation -I (498) main_task: Returned from app_main() -I (998) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Permit Join (0x36), status: ESP_OK -I (998) ESP_ZB_ON_OFF_SWITCH: Formed network successfully (Extended PAN ID: 60:55:f9:00:00:f6:07:b4, PAN ID: 0x2a74, Channel:13) -I (1468) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Permit Join (0x36), status: ESP_OK -I (1468) ESP_ZB_ON_OFF_SWITCH: Network steering started -I (14228) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Device Associated (0x12), status: ESP_OK -I (14728) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Update (0x30), status: ESP_OK -I (14788) ESP_ZB_ON_OFF_SWITCH: New device commissioned or rejoined (short: 0xe399) -I (14858) ESP_ZB_ON_OFF_SWITCH: Found light -I (14858) ESP_ZB_ON_OFF_SWITCH: Try to bind On/Off -I (14858) ESP_ZB_ON_OFF_SWITCH: Bound successfully! -I (14858) ESP_ZB_ON_OFF_SWITCH: The light originating from address(0xe399) on endpoint(10) -I (15338) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK -I (15408) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Permit Join (0x36), status: ESP_OK -I (35838) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NLME Status Indication (0x32), status: ESP_OK -I (38548) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command -I (39598) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command -I (41148) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command +I (441) main_task: Started on CPU0 +I (441) main_task: Calling app_main() +I (461) phy: phy_version: 230,2, 9aae6ea, Jan 15 2024, 11:17:12 +I (461) phy: libbtbb version: 944f18e, Jan 15 2024, 11:17:25 +I (471) main_task: Returned from app_main() +I (601) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL +I (601) ESP_ZB_ON_OFF_SWITCH: Initialize Zigbee stack +I (611) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2 +I (611) ESP_ZB_ON_OFF_SWITCH: Deferred driver initialization successful +I (621) ESP_ZB_ON_OFF_SWITCH: Device started up in factory-reset mode +I (621) ESP_ZB_ON_OFF_SWITCH: Start network formation +W (781) ESP_ZB_ON_OFF_SWITCH: Network(0x13af) closed, devices joining not allowed. +I (781) ESP_ZB_ON_OFF_SWITCH: Formed network successfully (Extended PAN ID: 74:4d:bd:ff:fe:63:f7:30, PAN ID: 0x13af, Channel:13, Short Address: 0x0000) +I (1391) ESP_ZB_ON_OFF_SWITCH: Network(0x13af) is open for 180 seconds +I (1391) ESP_ZB_ON_OFF_SWITCH: Network steering started +I (9561) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Device Associated (0x12), status: ESP_OK +I (9561) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Update (0x30), status: ESP_OK +I (9601) ESP_ZB_ON_OFF_SWITCH: New device commissioned or rejoined (short: 0x7c16) +I (9671) ESP_ZB_ON_OFF_SWITCH: Found light +I (9671) ESP_ZB_ON_OFF_SWITCH: Try to bind On/Off +I (9681) ESP_ZB_ON_OFF_SWITCH: Bound successfully! +I (9681) ESP_ZB_ON_OFF_SWITCH: The light originating from address(0x7c16) on endpoint(10) +I (9751) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK +I (9781) ESP_ZB_ON_OFF_SWITCH: Network(0x13af) is open for 180 seconds +I (16451) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command +I (17011) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command +I (17441) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command +I (17831) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command ``` ## Light Control Functions diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/CMakeLists.txt b/examples/zigbee/light_sample/HA_on_off_switch/main/CMakeLists.txt index b996c0f78a5e..15343efb83ce 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/CMakeLists.txt +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/CMakeLists.txt @@ -1,6 +1,4 @@ idf_component_register( - SRCS - "esp_zb_switch.c" - "switch_driver.c" - INCLUDE_DIRS "." + SRC_DIRS "." "../../../common/zcl_utility/src" + INCLUDE_DIRS "." "../../../common/zcl_utility/include" ) diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c index 2750377202b4..64459f04b310 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: CC0-1.0 + * SPDX-License-Identifier: LicenseRef-Included * * Zigbee HA_on_off_switch Example * @@ -15,6 +15,8 @@ #include "string.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "esp_err.h" +#include "esp_check.h" #include "esp_log.h" #include "nvs_flash.h" #include "ha/esp_zigbee_ha_standard.h" @@ -35,7 +37,7 @@ static switch_func_pair_t button_func_pair[] = { static const char *TAG = "ESP_ZB_ON_OFF_SWITCH"; -static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) +static void zb_buttons_handler(switch_func_pair_t *button_func_pair) { if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { /* implemented light switch toggle functionality */ @@ -43,14 +45,23 @@ static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) cmd_req.zcl_basic_cmd.src_endpoint = HA_ONOFF_SWITCH_ENDPOINT; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; - ESP_EARLY_LOGI(TAG, "Send 'on_off toggle' command"); + esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_on_off_cmd_req(&cmd_req); + esp_zb_lock_release(); + ESP_EARLY_LOGI(TAG, "Send 'on_off toggle' command"); } } +static esp_err_t deferred_driver_init(void) +{ + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, + "Failed to initialize switch driver"); + return ESP_OK; +} + static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { - ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); + ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee bdb commissioning"); } static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx) @@ -94,17 +105,19 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; switch (sig_type) { case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: - ESP_LOGI(TAG, "Zigbee stack initialized"); + ESP_LOGI(TAG, "Initialize Zigbee stack"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); break; case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { + ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); } else { + esp_zb_bdb_open_network(180); ESP_LOGI(TAG, "Device rebooted"); } } else { @@ -161,10 +174,16 @@ static void esp_zb_task(void *pvParameters) esp_zb_init(&zb_nwk_cfg); esp_zb_on_off_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_ON_OFF_SWITCH_CONFIG(); esp_zb_ep_list_t *esp_zb_on_off_switch_ep = esp_zb_on_off_switch_ep_create(HA_ONOFF_SWITCH_ENDPOINT, &switch_cfg); + zcl_basic_manufacturer_info_t info = { + .manufacturer_name = ESP_MANUFACTURER_NAME, + .model_identifier = ESP_MODEL_IDENTIFIER, + }; + + esp_zcl_utility_add_ep_basic_manufacturer_info(esp_zb_on_off_switch_ep, HA_ONOFF_SWITCH_ENDPOINT, &info); esp_zb_device_register(esp_zb_on_off_switch_ep); esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); ESP_ERROR_CHECK(esp_zb_start(false)); - esp_zb_main_loop_iteration(); + esp_zb_stack_main_loop(); } void app_main(void) @@ -175,6 +194,6 @@ void app_main(void) }; ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_zb_platform_config(&config)); - switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_zb_buttons_handler); + xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); } diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h index d4d95a0a0e43..32a6dc9edf08 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: CC0-1.0 + * SPDX-License-Identifier: LicenseRef-Included * * Zigbee HA_on_off_switch Example * @@ -13,12 +13,17 @@ */ #include "esp_zigbee_core.h" #include "switch_driver.h" +#include "zcl_utility.h" /* Zigbee configuration */ -#define MAX_CHILDREN 10 /* the max amount of connected devices */ -#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ -#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */ -#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */ +#define MAX_CHILDREN 10 /* the max amount of connected devices */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ +#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */ + +/* Basic manufacturer information */ +#define ESP_MANUFACTURER_NAME "\x09""ESPRESSIF" /* Customized manufacturer name */ +#define ESP_MODEL_IDENTIFIER "\x07"CONFIG_IDF_TARGET /* Customized model identifier */ #define ESP_ZB_ZC_CONFIG() \ { \ @@ -31,10 +36,10 @@ #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ { \ - .radio_mode = RADIO_MODE_NATIVE, \ + .radio_mode = ZB_RADIO_MODE_NATIVE, \ } #define ESP_ZB_DEFAULT_HOST_CONFIG() \ { \ - .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, \ } diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml b/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml index c186c3c8cad5..ad32c63b48e5 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "1.0.9" - espressif/esp-zigbee-lib: "1.0.9" + espressif/esp-zboss-lib: "~1.6.0" + espressif/esp-zigbee-lib: "~1.6.0" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/switch_driver.c b/examples/zigbee/light_sample/HA_on_off_switch/main/switch_driver.c index 2acf388944e0..8c03708cc854 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/switch_driver.c +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/switch_driver.c @@ -67,7 +67,7 @@ static void IRAM_ATTR gpio_isr_handler(void *arg) } /** - * @brief Enable GPIO (switchs refer to) isr + * @brief Enable GPIO (switches refer to) isr * * @param enabled enable isr if true. */ @@ -159,7 +159,7 @@ static bool switch_driver_gpio_init(switch_func_pair_t *button_func_pair, uint8_ return false; } /* start gpio task */ - xTaskCreate(switch_driver_button_detected, "button_detected", 2048, NULL, 10, NULL); + xTaskCreate(switch_driver_button_detected, "button_detected", 4096, NULL, 10, NULL); /* install gpio isr service */ gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); for (int i = 0; i < button_num; ++i) {