diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1139f3a..7f8f7da 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,19 @@ # Espressif Zigbee SDK Release Notes +## 19-Jul-2024 +1.4.1 version release of ESP-ZIGBEE-SDK is based on esp-idf v5.1.4 + +### Features +- Updated esp-zboss-lib to v1.4.1 +- Updated esp-zigbee-lib to v1.4.1 +- Supported NWK route record getting APIs +- Supported ZCL OTA image query request and response APIs +- Optimized APS maximum valid payload size for non-fragmented frames + +### Bug Fixes +- Fixed touchlink assert when the touchlink initiator scans mismatched targets and is required to leave + + ## 04-Jul-2024 1.4.0 version release of ESP-ZIGBEE-SDK is based on esp-idf v5.1.3 diff --git a/components/esp-zigbee-lib/idf_component.yml b/components/esp-zigbee-lib/idf_component.yml index a01a30b..9808f1c 100644 --- a/components/esp-zigbee-lib/idf_component.yml +++ b/components/esp-zigbee-lib/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.4.0" +version: "1.4.1" description: esp-zigbee library component url: https://github.com/espressif/esp-zigbee-sdk dependencies: diff --git a/components/esp-zigbee-lib/include/esp_zigbee_core.h b/components/esp-zigbee-lib/include/esp_zigbee_core.h index 0d0e0be..36e63ef 100644 --- a/components/esp-zigbee-lib/include/esp_zigbee_core.h +++ b/components/esp-zigbee-lib/include/esp_zigbee_core.h @@ -130,6 +130,7 @@ typedef enum esp_zb_core_action_callback_id_s { ESP_ZB_CORE_IAS_ACE_BYPASS_RESP_CB_ID = 0x002e, /*!< IAS ACE cluster Bypass command response, refer to esp_zb_zcl_ias_ace_bypass_response_message_t */ ESP_ZB_CORE_IAS_ACE_GET_ZONE_STATUS_RESP_CB_ID = 0x002f, /*!< IAS ACE cluster Get Zone Status command response, refer to esp_zb_zcl_ias_ace_get_zone_status_response_message_t */ ESP_ZB_CORE_WINDOW_COVERING_MOVEMENT_CB_ID = 0x0030, /*!< Window covering movement command, refer to esp_zb_zcl_window_covering_movement_message_t */ + ESP_ZB_CORE_OTA_UPGRADE_QUERY_IMAGE_RESP_CB_ID = 0x0031, /*!< OTA upgrade query image response message, refer to esp_zb_zcl_ota_upgrade_query_image_resp_message_t */ ESP_ZB_CORE_CMD_READ_ATTR_RESP_CB_ID = 0x1000, /*!< Read attribute response, refer to esp_zb_zcl_cmd_read_attr_resp_message_t */ ESP_ZB_CORE_CMD_WRITE_ATTR_RESP_CB_ID = 0x1001, /*!< Write attribute response, refer to esp_zb_zcl_cmd_write_attr_resp_message_t */ ESP_ZB_CORE_CMD_REPORT_CONFIG_RESP_CB_ID = 0x1002, /*!< Configure report response, refer to esp_zb_zcl_cmd_config_report_resp_message_t */ diff --git a/components/esp-zigbee-lib/include/esp_zigbee_ota.h b/components/esp-zigbee-lib/include/esp_zigbee_ota.h index 426ac08..33bad2c 100644 --- a/components/esp-zigbee-lib/include/esp_zigbee_ota.h +++ b/components/esp-zigbee-lib/include/esp_zigbee_ota.h @@ -55,9 +55,9 @@ typedef esp_err_t (*esp_zb_ota_next_data_callback_t)(esp_zb_ota_zcl_information_ * */ typedef struct esp_zb_zcl_ota_upgrade_client_variable_s { - uint16_t timer_query; /*!< The field indicates the time of querying OTA imagge for OTA upgrade client */ + uint16_t timer_query; /*!< The field indicates the time of querying OTA image for OTA upgrade client */ uint16_t hw_version; /*!< The hardware version */ - uint8_t max_data_size; /*!< The maxinum size of OTA data */ + uint8_t max_data_size; /*!< The maximum size of OTA data */ } esp_zb_zcl_ota_upgrade_client_variable_t; /** @@ -95,6 +95,37 @@ typedef struct esp_zb_ota_upgrade_server_notify_req_s { */ esp_err_t esp_zb_ota_upgrade_server_notify_req(esp_zb_ota_upgrade_server_notify_req_t *req); +/** + * @brief Send the OTA upgrade client query image request + * + * @param[in] server_addr The short address of the OTA upgrade server that the client expect to query + * @param[in] server_ep The endpoint identifier of the OTA upgrade server with OTA image + * @return + * - ESP_OK: On success + * - ESP_FAIL: On failed + */ +esp_err_t esp_zb_ota_upgrade_client_query_image_req(uint16_t server_ep, uint8_t server_addr); + +/** + * @brief Set the interval of query for OTA upgrade client + * + * @param[in] endpoint The endpoint identifier of OTA upgrade client resides + * @param[in] interval The interval in minute + * @return + * - ESP_OK: On success + * - ESP_FAIL: On failed + */ +esp_err_t esp_zb_ota_upgrade_client_query_interval_set(uint8_t endpoint, uint16_t interval); + +/** + * @brief Stop the image query of OTA upgrade client + * + * @return + * - ESP_OK: On success + * - ESP_FAIL: On failed + */ +esp_err_t esp_zb_ota_upgrade_client_query_image_stop(void); + #ifdef __cplusplus } #endif diff --git a/components/esp-zigbee-lib/include/nwk/esp_zigbee_nwk.h b/components/esp-zigbee-lib/include/nwk/esp_zigbee_nwk.h index b4b976d..b6aa486 100644 --- a/components/esp-zigbee-lib/include/nwk/esp_zigbee_nwk.h +++ b/components/esp-zigbee-lib/include/nwk/esp_zigbee_nwk.h @@ -24,6 +24,8 @@ typedef enum { #define ESP_ZB_NWK_INFO_ITERATOR_INIT 0 /*!< Initializer for esp_zb_neighbor_info_iterator_t. */ #define ESP_ZB_NWK_INFO_ITERATOR_EOT 0xFFFF /*!< Indicate the iterator reach the End of Table. */ +#define ESP_ZB_NWK_MAX_SOURCE_ROUTE 5 + /** * @brief Iterator used to iterate through the tables of network informations. * @@ -91,6 +93,18 @@ typedef struct esp_zb_nwk_route_info_s { uint8_t expiry; /*!< Expiration time. */ } esp_zb_nwk_route_info_t; +/** + * @brief Information of network route record table entry + * + */ +typedef struct esp_zb_nwk_route_record_info_s { + uint16_t dest_address; /*!< Destination network address of this route record. */ + uint8_t expiry; /*!< Expiration time. */ + uint8_t relay_count; /*!< The count of relay nodes from concentrator to the destination. */ + uint16_t path[ESP_ZB_NWK_MAX_SOURCE_ROUTE]; /*!< The set of network addresses that represent the route + * in order from the concentrator to the destination.*/ +} esp_zb_nwk_route_record_info_t; + /** * @brief Set the network update id * @@ -258,6 +272,7 @@ esp_zb_nwk_device_type_t esp_zb_get_network_device_role(void); * * @return - ESP_OK on success * - ESP_ERR_NOT_FOUND on finish iteration + * - ESP_ERR_INVALID_ARG if arguements are invalid * */ esp_err_t esp_zb_nwk_get_next_neighbor(esp_zb_nwk_info_iterator_t *iterator, esp_zb_nwk_neighbor_info_t *nbr_info); @@ -270,10 +285,24 @@ esp_err_t esp_zb_nwk_get_next_neighbor(esp_zb_nwk_info_iterator_t *iterator, esp * * @return - ESP_OK on success * - ESP_ERR_NOT_FOUND on finish iteration + * - ESP_ERR_INVALID_ARG if arguements are invalid * */ esp_err_t esp_zb_nwk_get_next_route(esp_zb_nwk_info_iterator_t *iterator, esp_zb_nwk_route_info_t *route_info); +/** + * @brief Iterate through the route record table (a.k.a source route table) and get the information in the entry + * + * @param[in] iterator iterator used to iterate through routing table, refer to esp_zb_nwk_info_iterator_t + * @param[out] route_record_info next route record entry information, @ref esp_zb_nwk_route_record_info_s + * + * @return - ESP_OK on success + * - ESP_ERR_NOT_FOUND on finish iteration + * - ESP_ERR_INVALID_ARG if arguements are invalid + * + */ +esp_err_t esp_zb_nwk_get_next_route_record(esp_zb_nwk_info_iterator_t *iterator, esp_zb_nwk_route_record_info_t *route_record_info); + #ifdef __cplusplus } #endif diff --git a/components/esp-zigbee-lib/include/zcl/esp_zigbee_zcl_command.h b/components/esp-zigbee-lib/include/zcl/esp_zigbee_zcl_command.h index cc3b6e9..3995739 100644 --- a/components/esp-zigbee-lib/include/zcl/esp_zigbee_zcl_command.h +++ b/components/esp-zigbee-lib/include/zcl/esp_zigbee_zcl_command.h @@ -1389,6 +1389,21 @@ typedef struct esp_zb_zcl_ota_upgrade_value_message_s { uint8_t *payload; /*!< The OTA payload */ } esp_zb_zcl_ota_upgrade_value_message_t; +/** + * @brief The Zigbee zcl ota upgrade client query image response message struct + * + */ +typedef struct esp_zb_zcl_ota_upgrade_query_image_resp_message_s { + esp_zb_device_cb_common_info_t info; /*!< The common information for Zigbee device callback */ + esp_zb_zcl_addr_t server_addr; /*!< Server address */ + uint8_t server_endpoint; /*!< Server endpoint */ + uint8_t query_status; /*!< Status, see esp_zb_zcl_status_t */ + uint16_t manufacturer_code; /*!< Manufacturer code */ + uint16_t image_type; /*!< Image type */ + uint32_t file_version; /*!< File version */ + uint32_t image_size; /*!< Image size */ +} esp_zb_zcl_ota_upgrade_query_image_resp_message_t; + /** * @brief The Zigbee zcl ota upgrade server status message struct * diff --git a/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.a b/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.a index f2bc169..d1ad302 100644 Binary files a/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.a and b/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.a differ diff --git a/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.debug.a b/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.debug.a index f98dcc6..93f6875 100644 Binary files a/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.debug.a and b/components/esp-zigbee-lib/lib/esp32/libesp_zb_api_zczr.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.a b/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.a index 9a91525..066c103 100644 Binary files a/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.a and b/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.a differ diff --git a/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.debug.a b/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.debug.a index 6c78803..a575ed4 100644 Binary files a/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.debug.a and b/components/esp-zigbee-lib/lib/esp32c3/libesp_zb_api_zczr.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.a b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.a index abbe515..153d136 100644 Binary files a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.a and b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.a differ diff --git a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.debug.a b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.debug.a index 0f2a3e2..1129577 100644 Binary files a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.debug.a and b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.a b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.a index f5d23bc..db63939 100644 Binary files a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.a and b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.a differ diff --git a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.debug.a b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.debug.a index ad07dfb..3b9c369 100644 Binary files a/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.debug.a and b/components/esp-zigbee-lib/lib/esp32c6/libesp_zb_api_zczr.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.a b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.a index 7ea13ab..d2c9610 100644 Binary files a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.a and b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.a differ diff --git a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.debug.a b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.debug.a index 76270bf..959f5a8 100644 Binary files a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.debug.a and b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_ed.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.a b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.a index 6596d55..4b22be6 100644 Binary files a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.a and b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.a differ diff --git a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.debug.a b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.debug.a index c6ff46c..3a3c66d 100644 Binary files a/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.debug.a and b/components/esp-zigbee-lib/lib/esp32h2/libesp_zb_api_zczr.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.a b/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.a index 5c0e77b..f97f9f7 100644 Binary files a/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.a and b/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.a differ diff --git a/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.debug.a b/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.debug.a index f98dcc6..93f6875 100644 Binary files a/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.debug.a and b/components/esp-zigbee-lib/lib/esp32s2/libesp_zb_api_zczr.debug.a differ diff --git a/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.a b/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.a index f2bc169..d1ad302 100644 Binary files a/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.a and b/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.a differ diff --git a/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.debug.a b/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.debug.a index f98dcc6..93f6875 100644 Binary files a/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.debug.a and b/components/esp-zigbee-lib/lib/esp32s3/libesp_zb_api_zczr.debug.a differ diff --git a/examples/constants.py b/examples/constants.py index 2ce15ce..2e2f560 100644 --- a/examples/constants.py +++ b/examples/constants.py @@ -3,7 +3,7 @@ class ZigbeeCIConstants: channel_min = 11 channel_max = 26 channel = 18 - ota_total_package = '159616' + ota_total_package = '552928' ota_version = '0x1010101' image_type = '0x1011' manufacturer_code = '1001' diff --git a/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c b/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c index 6a6fa86..f8679de 100644 --- a/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c +++ b/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c @@ -149,6 +149,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 { diff --git a/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c b/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c index 4d48b48..4d767d3 100644 --- a/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c +++ b/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c @@ -117,6 +117,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 { diff --git a/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c b/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c index 0561be9..5fd8d11 100644 --- a/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c +++ b/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c @@ -232,6 +232,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 { diff --git a/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c b/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c index 35e14f5..6119cb9 100644 --- a/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c +++ b/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c @@ -54,6 +54,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 { diff --git a/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c b/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c index 0df9496..56d2b96 100644 --- a/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c +++ b/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c @@ -144,6 +144,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 { diff --git a/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c b/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c index de301d2..3ac3521 100644 --- a/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c +++ b/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c @@ -106,6 +106,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 { diff --git a/examples/esp_zigbee_ota/ota_client/CMakeLists.txt b/examples/esp_zigbee_ota/ota_client/CMakeLists.txt index 39f20d4..8e3b371 100644 --- a/examples/esp_zigbee_ota/ota_client/CMakeLists.txt +++ b/examples/esp_zigbee_ota/ota_client/CMakeLists.txt @@ -2,5 +2,8 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) +set(EXTRA_COMPONENT_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/../../common/switch_driver + ) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(esp_ota_client) diff --git a/examples/esp_zigbee_ota/ota_client/README.md b/examples/esp_zigbee_ota/ota_client/README.md index d3f5bcc..1ef8c54 100644 --- a/examples/esp_zigbee_ota/ota_client/README.md +++ b/examples/esp_zigbee_ota/ota_client/README.md @@ -32,95 +32,96 @@ As you run the example, you will see the following log: ``` I (420) main_task: Calling app_main() -I (420) ESP_OTA_CLIENT: OTA example 1.0 is running +W (420) ESP_OTA_CLIENT: ESP Zigbee OTA example 1.0 is running I (450) phy: phy_version: 210,0, 11c334c, Sep 4 2023, 17:01:13 I (450) phy: libbtbb version: b821802, Sep 4 2023, 17:01:29 I (460) main_task: Returned from app_main() I (530) ESP_OTA_CLIENT: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL I (17500) ESP_OTA_CLIENT: -- OTA upgrade start I (17600) ESP_OTA_CLIENT: Joined network successfully (Extended PAN ID: 60:55:f9:ff:fe:f7:2e:16, PAN ID: 0x397c, Channel:13) -I (17740) ESP_OTA_CLIENT: -- OTA Client receives data: progress [8/159616] -I (17980) ESP_OTA_CLIENT: -- OTA Client receives data: progress [72/159616] -I (18200) ESP_OTA_CLIENT: -- OTA Client receives data: progress [136/159616] -I (18440) ESP_OTA_CLIENT: -- OTA Client receives data: progress [200/159616] -I (18660) ESP_OTA_CLIENT: -- OTA Client receives data: progress [264/159616] -I (18890) ESP_OTA_CLIENT: -- OTA Client receives data: progress [328/159616] -I (19120) ESP_OTA_CLIENT: -- OTA Client receives data: progress [392/159616] -I (19350) ESP_OTA_CLIENT: -- OTA Client receives data: progress [456/159616] -I (19580) ESP_OTA_CLIENT: -- OTA Client receives data: progress [520/159616] -I (19810) ESP_OTA_CLIENT: -- OTA Client receives data: progress [584/159616] -I (20040) ESP_OTA_CLIENT: -- OTA Client receives data: progress [648/159616] -I (20270) ESP_OTA_CLIENT: -- OTA Client receives data: progress [712/159616] -I (20500) ESP_OTA_CLIENT: -- OTA Client receives data: progress [776/159616] +I (17740) ESP_OTA_CLIENT: -- OTA Client receives data: progress [8/552328] +I (17980) ESP_OTA_CLIENT: -- OTA Client receives data: progress [72/552328] +I (18200) ESP_OTA_CLIENT: -- OTA Client receives data: progress [136/552328] +I (18440) ESP_OTA_CLIENT: -- OTA Client receives data: progress [200/552328] +I (18660) ESP_OTA_CLIENT: -- OTA Client receives data: progress [264/552328] +I (18890) ESP_OTA_CLIENT: -- OTA Client receives data: progress [328/552328] +I (19120) ESP_OTA_CLIENT: -- OTA Client receives data: progress [392/552328] +I (19350) ESP_OTA_CLIENT: -- OTA Client receives data: progress [456/552328] +I (19580) ESP_OTA_CLIENT: -- OTA Client receives data: progress [520/552328] +I (19810) ESP_OTA_CLIENT: -- OTA Client receives data: progress [584/552328] +I (20040) ESP_OTA_CLIENT: -- OTA Client receives data: progress [648/552328] +I (20270) ESP_OTA_CLIENT: -- OTA Client receives data: progress [712/552328] +I (20500) ESP_OTA_CLIENT: -- OTA Client receives data: progress [776/552328] ... -I (597100) ESP_OTA_CLIENT: -- OTA Client receives data: progress [158728/159616] -I (597330) ESP_OTA_CLIENT: -- OTA Client receives data: progress [158792/159616] -I (597560) ESP_OTA_CLIENT: -- OTA Client receives data: progress [158856/159616] -I (597790) ESP_OTA_CLIENT: -- OTA Client receives data: progress [158920/159616] -I (598030) ESP_OTA_CLIENT: -- OTA Client receives data: progress [158984/159616] -I (598260) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159048/159616] -I (598490) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159112/159616] -I (598720) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159176/159616] -I (598950) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159240/159616] -I (599180) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159304/159616] -I (599450) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159368/159616] -I (599690) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159432/159616] -I (599920) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159496/159616] -I (600140) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159560/159616] -I (600420) ESP_OTA_CLIENT: -- OTA Client receives data: progress [159616/159616] -I (600420) ESP_OTA_CLIENT: -- OTA upgrade check status: ESP_OK -I (600490) ESP_OTA_CLIENT: -- OTA upgrade apply -I (605560) ESP_OTA_CLIENT: -- OTA Finish -I (605560) ESP_OTA_CLIENT: -- OTA Information: version: 0x1010110, manufactor code: 0x1001, image type: 0x1011, total size: 159616 bytes, cost time: 588056 ms, -I (605560) esp_image: segment 0: paddr=000d0020 vaddr=42018020 size=08750h ( 34640) map -I (605610) esp_image: segment 1: paddr=000d8778 vaddr=40800000 size=078a0h ( 30880) -I (605650) esp_image: segment 2: paddr=000e0020 vaddr=42000020 size=141f8h ( 82424) map -I (605740) esp_image: segment 3: paddr=000f4220 vaddr=408078a0 size=01da4h ( 7588) -I (605750) esp_image: segment 4: paddr=000f5fcc vaddr=40809650 size=00f88h ( 3976) -I (605760) esp_image: segment 0: paddr=000d0020 vaddr=42018020 size=08750h ( 34640) map -I (605800) esp_image: segment 1: paddr=000d8778 vaddr=40800000 size=078a0h ( 30880) -I (605830) esp_image: segment 2: paddr=000e0020 vaddr=42000020 size=141f8h ( 82424) map -I (605930) esp_image: segment 3: paddr=000f4220 vaddr=408078a0 size=01da4h ( 7588) -I (605940) esp_image: segment 4: paddr=000f5fcc vaddr=40809650 size=00f88h ( 3976) -W (605950) ESP_OTA_CLIENT: Prepare to restart system -ESP-ROM:esp32h2-20221101 -Build:Nov 1 2022 +I (2006958) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552584/552928] +I (2007188) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552648/552928] +I (2007418) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552712/552928] +I (2007648) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552776/552928] +I (2007878) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552840/552928] +I (2008108) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552904/552928] +I (2008338) ESP_OTA_CLIENT: -- OTA Client receives data: progress [552928/552928] +I (2008338) ESP_OTA_CLIENT: -- OTA upgrade check status: ESP_OK +I (2008388) ESP_OTA_CLIENT: -- OTA upgrade apply +I (2013398) ESP_OTA_CLIENT: -- OTA Finish +I (2013398) ESP_OTA_CLIENT: -- OTA Information: version: 0x1010110, manufacturer code: 0x1001, image type: 0x1011, total size: 552928 bytes, cost time: 2002578 ms, +I (2013398) esp_image: segment 0: paddr=00110020 vaddr=42070020 size=10fb8h ( 69560) map +I (2013488) esp_image: segment 1: paddr=00120fe0 vaddr=40800000 size=07038h ( 28728) +I (2013518) esp_image: segment 2: paddr=00128020 vaddr=42000020 size=6866ch (427628) map +I (2013998) esp_image: segment 3: paddr=00190694 vaddr=40807038 size=06928h ( 26920) +I (2014028) esp_image: segment 0: paddr=00110020 vaddr=42070020 size=10fb8h ( 69560) map +I (2014108) esp_image: segment 1: paddr=00120fe0 vaddr=40800000 size=07038h ( 28728) +I (2014138) esp_image: segment 2: paddr=00128020 vaddr=42000020 size=6866ch (427628) map +I (2014618) esp_image: segment 3: paddr=00190694 vaddr=40807038 size=06928h ( 26920) +W (2014688) ESP_OTA_CLIENT: Prepare to restart system +ESP-ROM:esp32h2-20221101 +Build:Nov 1 2022 rst:0xc (SW_CPU),boot:0xc (SPI_FAST_FLASH_BOOT) Saved PC:0x400031b6 0x400031b6: software_reset_cpu in ROM + ... -I (245) cpu_start: Pro cpu start user code -I (245) cpu_start: cpu freq: 96000000 Hz -I (246) cpu_start: Application information: -I (248) cpu_start: Project name: hello_world -I (253) cpu_start: App version: c6_h2_rng_final_tests-2545-g54f -I (260) cpu_start: Compile time: Oct 12 2023 20:27:10 -I (266) cpu_start: ELF file SHA256: b5785ec0d... -Warning: checksum mismatch between flashed and built applications. Checksum of built application is 38ff6cede25780e96382904d67d767d2d901bf9cf04baad40b5990e4f28cb6b8 -I (272) cpu_start: ESP-IDF: v5.2-dev-3300-g54f0517724 -I (278) cpu_start: Min chip rev: v0.0 -I (283) cpu_start: Max chip rev: v0.99 -I (288) cpu_start: Chip rev: v0.1 -I (292) heap_init: Initializing. RAM available for dynamic allocation: -I (300) heap_init: At 4080B460 len 00041F20 (263 KiB): D/IRAM -I (306) heap_init: At 4084D380 len 00002B60 (10 KiB): STACK/DIRAM -I (314) spi_flash: detected chip: generic -I (317) spi_flash: flash io: dio -I (322) sleep: Configure to isolate all GPIO pins in sleep state -I (328) sleep: Enable automatic switching of GPIO sleep configuration -I (336) main_task: Started on CPU0 -I (336) main_task: Calling app_main() -Hello world! -This is esp32h2 chip with 1 CPU core(s), BLE, 802.15.4 (Zigbee/Thread), silicon revision v0.1, 2MB external flash -Minimum free heap size: 264784 bytes -Restarting in 10 seconds... -Restarting in 9 seconds... -Restarting in 8 seconds... -Restarting in 7 seconds... -Restarting in 6 seconds... -Restarting in 5 seconds... +I (388) boot: Loaded app from partition at offset 0x110000 +I (389) boot: Disabling RNG early entropy source... +I (400) cpu_start: Unicore app +I (401) cpu_start: Pro cpu up. +W (410) clk: esp_perip_clk_init() has not been implemented yet +I (417) cpu_start: Pro cpu start user code +I (417) cpu_start: cpu freq: 96000000 Hz +I (417) cpu_start: Application information: +I (420) cpu_start: Project name: esp_ota_client +I (425) cpu_start: App version: 6e967b2-dirty +I (431) cpu_start: Compile time: Jul 11 2024 14:22:26 +I (437) cpu_start: ELF file SHA256: 54626c3368d1c5e7... +Warning: checksum mismatch between flashed and built applications. Checksum of built application is bc0b636f48447b6879fea08e501d6bc2e97430c1bd8cfdd60eea62a52de6d9de +I (443) cpu_start: ESP-IDF: v5.1.3 +I (447) cpu_start: Min chip rev: v0.0 +I (452) cpu_start: Max chip rev: v0.99 +I (457) cpu_start: Chip rev: v0.1 +I (462) heap_init: Initializing. RAM available for dynamic allocation: +I (469) heap_init: At 408120E0 len 0003B2A0 (236 KiB): D/IRAM +I (475) heap_init: At 4084D380 len 00002B60 (10 KiB): STACK/DIRAM +I (483) spi_flash: detected chip: generic +I (487) spi_flash: flash io: dio +W (491) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. +I (504) sleep: Configure to isolate all GPIO pins in sleep state +I (511) sleep: Enable automatic switching of GPIO sleep configuration +I (518) app_start: Starting scheduler on CPU0 +I (523) main_task: Started on CPU0 +I (523) main_task: Calling app_main() +W (523) ESP_OTA_CLIENT: ESP Zigbee OTA example 2.0 is running +I (553) phy: phy_version: 230,2, 9aae6ea, Jan 15 2024, 11:17:12 +I (553) phy: libbtbb version: 944f18e, Jan 15 2024, 11:17:25 +I (563) main_task: Returned from app_main() +I (573) ESP_OTA_CLIENT: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL +I (573) ESP_OTA_CLIENT: Initialize Zigbee stack +I (2953) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:4 +I (2953) ESP_OTA_CLIENT: Deferred driver initialization successful +I (2963) ESP_OTA_CLIENT: Device started up in non factory-reset mode +I (2963) ESP_OTA_CLIENT: Device rebooted ``` +Note: The example also supports the user pressing the `boot` button to send the `QUERY_NEXT_IMAGE` command to query the image from the coordinator. + ## OTA Upgrade Functions * After receiving OTA image notify from server, client send the query image request and image block requests to server upon receiving the response from server. diff --git a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c index 8bac553..3442bd1 100644 --- a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c +++ b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 * @@ -12,7 +12,6 @@ * CONDITIONS OF ANY KIND, either express or implied. */ - #include "esp_check.h" #include "esp_log.h" #include "esp_ota_ops.h" @@ -26,6 +25,48 @@ static const char *TAG = "ESP_OTA_CLIENT"; static const esp_partition_t *s_ota_partition = NULL; static esp_ota_handle_t s_ota_handle = 0; +#define OTA_UPGRADE_QUERY_INTERVAL (1 * 60) // 1 minutes + +static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ON_CONTROL}}; + +static void zb_zdo_match_desc_handler(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) +{ + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { + esp_zb_ota_upgrade_client_query_interval_set(ESP_OTA_CLIENT_ENDPOINT, OTA_UPGRADE_QUERY_INTERVAL); + esp_zb_ota_upgrade_client_query_image_req(addr, endpoint); + ESP_LOGI(TAG, "Query OTA upgrade from server endpoint: %d after %d seconds", endpoint, OTA_UPGRADE_QUERY_INTERVAL); + } else { + ESP_LOGW(TAG, "No OTA Server found"); + } +} + +static void zb_buttons_handler(switch_func_pair_t *button_func_pair) +{ + assert(button_func_pair); + esp_zb_zdo_match_desc_req_param_t req; + uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_OTA_UPGRADE}; + + /* Match the OTA server of coordinator */ + req.addr_of_interest = 0x0000; + req.dst_nwk_addr = 0x0000; + req.num_in_clusters = 1; + req.num_out_clusters = 0; + req.profile_id = ESP_ZB_AF_HA_PROFILE_ID; + req.cluster_list = cluster_list; + esp_zb_lock_acquire(portMAX_DELAY); + if (esp_zb_bdb_dev_joined()) { + esp_zb_zdo_match_cluster(&req, zb_zdo_match_desc_handler, NULL); + } + esp_zb_lock_release(); +} + +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_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee commissioning"); @@ -37,16 +78,34 @@ 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; switch (sig_type) { + case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: + 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"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + } else { + ESP_LOGI(TAG, "Device rebooted"); + } + } else { + ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + } + break; case ESP_ZB_BDB_SIGNAL_STEERING: if (err_status == ESP_OK) { esp_zb_ieee_addr_t extended_pan_id; esp_zb_get_extended_pan_id(extended_pan_id); - ESP_LOGI(TAG, "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", - extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], - extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], - esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address()); + ESP_LOGI(TAG, + "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short " + "Address: 0x%04hx)", + extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], extended_pan_id[3], extended_pan_id[2], + extended_pan_id[1], extended_pan_id[0], esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address()); } else { ESP_LOGI(TAG, "Network steering was not successful (status: %s)", esp_err_to_name(err_status)); esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 5000); @@ -59,28 +118,29 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) } } -static esp_err_t zb_ota_upgrade_status_handler(esp_zb_zcl_ota_upgrade_value_message_t messsage) +static esp_err_t zb_ota_upgrade_status_handler(esp_zb_zcl_ota_upgrade_value_message_t message) { static uint32_t total_size = 0; static uint32_t offset = 0; static int64_t start_time = 0; esp_err_t ret = ESP_OK; - if (messsage.info.status == ESP_ZB_ZCL_STATUS_SUCCESS) { - switch (messsage.upgrade_status) { + + if (message.info.status == ESP_ZB_ZCL_STATUS_SUCCESS) { + switch (message.upgrade_status) { case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_START: ESP_LOGI(TAG, "-- OTA upgrade start"); start_time = esp_timer_get_time(); s_ota_partition = esp_ota_get_next_update_partition(NULL); assert(s_ota_partition); - ret = esp_ota_begin(s_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &s_ota_handle); + ret = esp_ota_begin(s_ota_partition, 0, &s_ota_handle); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to begin OTA partition, status: %s", esp_err_to_name(ret)); break; case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_RECEIVE: - total_size = messsage.ota_header.image_size; - offset += messsage.payload_size; + total_size = message.ota_header.image_size; + offset += message.payload_size; ESP_LOGI(TAG, "-- OTA Client receives data: progress [%ld/%ld]", offset, total_size); - if (messsage.payload_size && messsage.payload) { - ret = esp_ota_write(s_ota_handle, (const void *)messsage.payload, messsage.payload_size); + if (message.payload_size && message.payload) { + ret = esp_ota_write(s_ota_handle, (const void *)message.payload, message.payload_size); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to write OTA data to partition, status: %s", esp_err_to_name(ret)); } break; @@ -93,10 +153,9 @@ static esp_err_t zb_ota_upgrade_status_handler(esp_zb_zcl_ota_upgrade_value_mess break; case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_FINISH: ESP_LOGI(TAG, "-- OTA Finish"); - ESP_LOGI(TAG, - "-- OTA Information: version: 0x%lx, manufactor code: 0x%x, image type: 0x%x, total size: %ld bytes, cost time: %lld ms,", - messsage.ota_header.file_version, messsage.ota_header.manufacturer_code, messsage.ota_header.image_type, - messsage.ota_header.image_size, (esp_timer_get_time() - start_time) / 1000); + ESP_LOGI(TAG, "-- OTA Information: version: 0x%lx, manufacturer code: 0x%x, image type: 0x%x, total size: %ld bytes, cost time: %lld ms,", + message.ota_header.file_version, message.ota_header.manufacturer_code, message.ota_header.image_type, + message.ota_header.image_size, (esp_timer_get_time() - start_time) / 1000); ret = esp_ota_end(s_ota_handle); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to end OTA partition, status: %s", esp_err_to_name(ret)); ret = esp_ota_set_boot_partition(s_ota_partition); @@ -105,13 +164,29 @@ static esp_err_t zb_ota_upgrade_status_handler(esp_zb_zcl_ota_upgrade_value_mess esp_restart(); break; default: - ESP_LOGI(TAG, "OTA status: %d", messsage.upgrade_status); + ESP_LOGI(TAG, "OTA status: %d", message.upgrade_status); break; } } return ret; } +static esp_err_t zb_ota_upgrade_query_image_resp_handler(esp_zb_zcl_ota_upgrade_query_image_resp_message_t message) +{ + esp_err_t ret = ESP_OK; + if (message.info.status == ESP_ZB_ZCL_STATUS_SUCCESS) { + ESP_LOGI(TAG, "Queried OTA image from address: 0x%04hx, endpoint: %d", message.server_addr.u.short_addr, message.server_endpoint); + ESP_LOGI(TAG, "Image version: 0x%lx, manufacturer code: 0x%x, image size: %ld", message.file_version, message.manufacturer_code, + message.image_size); + } + if (ret == ESP_OK) { + ESP_LOGI(TAG, "Approving OTA image upgrade"); + } else { + ESP_LOGI(TAG, "Rejecting OTA image upgrade, status: %d", ret); + } + return ret; +} + static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) { esp_err_t ret = ESP_OK; @@ -119,6 +194,9 @@ static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, case ESP_ZB_CORE_OTA_UPGRADE_VALUE_CB_ID: ret = zb_ota_upgrade_status_handler(*(esp_zb_zcl_ota_upgrade_value_message_t *)message); break; + case ESP_ZB_CORE_OTA_UPGRADE_QUERY_IMAGE_RESP_CB_ID: + ret = zb_ota_upgrade_query_image_resp_handler(*(esp_zb_zcl_ota_upgrade_query_image_resp_message_t *)message); + break; default: ESP_LOGW(TAG, "Receive Zigbee action(0x%x) callback", callback_id); break; @@ -126,15 +204,9 @@ static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, return ret; } -static void esp_zb_task(void *pvParameters) +static esp_err_t zb_register_ota_upgrade_client_device(void) { - /* initialize Zigbee stack with Zigbee end-device config */ - esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); - esp_zb_init(&zb_nwk_cfg); - - esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_basic_cluster_create(NULL); - esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME); - esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER); + esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create(NULL); /** Create ota client cluster with attributes. * Manufacturer code, image type and file version should match with configured values for server. * If the client values do not match with configured values then it shall discard the command and @@ -146,37 +218,52 @@ static void esp_zb_task(void *pvParameters) .ota_upgrade_manufacturer = OTA_UPGRADE_MANUFACTURER, .ota_upgrade_image_type = OTA_UPGRADE_IMAGE_TYPE, }; - esp_zb_attribute_list_t *esp_zb_ota_client_cluster = esp_zb_ota_cluster_create(&ota_cluster_cfg); - /** add client parameters to ota client cluster */ + esp_zb_attribute_list_t *ota_cluster = esp_zb_ota_cluster_create(&ota_cluster_cfg); esp_zb_zcl_ota_upgrade_client_variable_t variable_config = { .timer_query = ESP_ZB_ZCL_OTA_UPGRADE_QUERY_TIMER_COUNT_DEF, .hw_version = OTA_UPGRADE_HW_VERSION, .max_data_size = OTA_UPGRADE_MAX_DATA_SIZE, }; - esp_zb_ota_cluster_add_attr(esp_zb_ota_client_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, (void *)&variable_config); - /* create cluster list with ota cluster */ - esp_zb_cluster_list_t *esp_zb_cluster_list = esp_zb_zcl_cluster_list_create(); - esp_zb_cluster_list_add_basic_cluster(esp_zb_cluster_list, esp_zb_basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - esp_zb_cluster_list_add_ota_cluster(esp_zb_cluster_list, esp_zb_ota_client_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE); - /* add created endpoint (cluster_list) to endpoint list */ - esp_zb_ep_list_t *esp_zb_ep_list = esp_zb_ep_list_create(); + uint16_t ota_upgrade_server_addr = 0xffff; + uint8_t ota_upgrade_server_ep = 0xff; + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create(); esp_zb_endpoint_config_t endpoint_config = { .endpoint = ESP_OTA_CLIENT_ENDPOINT, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_TEST_DEVICE_ID, - .app_device_version = 0 + .app_device_version = 0, }; - esp_zb_ep_list_add_ep(esp_zb_ep_list, esp_zb_cluster_list, endpoint_config); - esp_zb_device_register(esp_zb_ep_list); + /* Added attributes */ + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER)); + ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, (void *)&variable_config)); + ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID, (void *)&ota_upgrade_server_addr)); + ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID, (void *)&ota_upgrade_server_ep)); + /* Added clusters */ + ESP_ERROR_CHECK(esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)); + ESP_ERROR_CHECK(esp_zb_cluster_list_add_ota_cluster(cluster_list, ota_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE)); + /* Added endpoints */ + ESP_ERROR_CHECK(esp_zb_ep_list_add_ep(ep_list, cluster_list, endpoint_config)); + /* Register device */ + return esp_zb_device_register(ep_list); +} + +static void esp_zb_task(void *pvParameters) +{ + /* Initialize Zigbee stack with Zigbee end-device config */ + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); + esp_zb_init(&zb_nwk_cfg); 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(true)); + ESP_ERROR_CHECK(zb_register_ota_upgrade_client_device()); + ESP_ERROR_CHECK(esp_zb_start(false)); esp_zb_main_loop_iteration(); } void app_main(void) { - ESP_LOGI(TAG, "OTA example 1.0 is running"); + ESP_LOGW(TAG, "ESP Zigbee OTA example 1.0 is running"); esp_zb_platform_config_t config = { .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), diff --git a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.h b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.h index ad743ec..3a80e59 100644 --- a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.h +++ b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 * @@ -13,6 +13,7 @@ */ #include "esp_zigbee_core.h" +#include "switch_driver.h" /* Zigbee configuration */ #define INSTALLCODE_POLICY_ENABLE false /* Enable the install code policy for security */ diff --git a/examples/esp_zigbee_ota/ota_client/partitions.csv b/examples/esp_zigbee_ota/ota_client/partitions.csv index f825bf5..5f05367 100644 --- a/examples/esp_zigbee_ota/ota_client/partitions.csv +++ b/examples/esp_zigbee_ota/ota_client/partitions.csv @@ -3,7 +3,7 @@ nvs, data, nvs, 0x9000, 0x6000, otadata, data, ota, , 0x2000, phy_init, data, phy, , 0x1000, -factory, app, factory, , 660K, +factory, app, factory, , 900K, zb_storage, data, fat, , 16K, -ota_0, app, ota_0, , 660K, +ota_0, app, ota_0, , 900K, zb_fct, data, fat, , 1K, diff --git a/examples/esp_zigbee_ota/ota_server/CMakeLists.txt b/examples/esp_zigbee_ota/ota_server/CMakeLists.txt index 3eb5799..0977f85 100644 --- a/examples/esp_zigbee_ota/ota_server/CMakeLists.txt +++ b/examples/esp_zigbee_ota/ota_server/CMakeLists.txt @@ -2,5 +2,8 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) +set(EXTRA_COMPONENT_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/../../common/switch_driver + ) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(esp_ota_server) diff --git a/examples/esp_zigbee_ota/ota_server/README.md b/examples/esp_zigbee_ota/ota_server/README.md index 686b623..e7ebf0c 100644 --- a/examples/esp_zigbee_ota/ota_server/README.md +++ b/examples/esp_zigbee_ota/ota_server/README.md @@ -45,57 +45,53 @@ I (1570) ESP_OTA_SERVER: Network steering started I (15950) ESP_OTA_SERVER: ZDO signal: NWK Device Associated (0x12), status: ESP_OK I (16450) ESP_OTA_SERVER: ZDO signal: ZDO Device Update (0x30), status: ESP_OK I (16490) ESP_OTA_SERVER: New device commissioned or rejoined (short: 0x7042) -I (16490) ESP_OTA_SERVER: OTA Server notify +I (16490) ESP_OTA_SERVER: Notify OTA upgrade I (16590) ESP_OTA_SERVER: OTA upgrade server query image I (16590) ESP_OTA_SERVER: OTA client address: 0x7042 I (16590) ESP_OTA_SERVER: OTA version: 0x1010101, image type: 0x1011, manfacturer code: 1001, I (16600) ESP_OTA_SERVER: OTA table index: 0x0 I (16690) ESP_OTA_SERVER: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK I (16750) ESP_OTA_SERVER: ZDO signal: NWK Permit Join (0x36), status: ESP_OK -I (16850) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [8/159616] +I (16850) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [8/552328] I (16850) ESP_OTA_SERVER: OTA client address: 0x7042 I (16850) ESP_OTA_SERVER: OTA version: 0x1010110, image type: 0x1011, server status: 0 -I (17100) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [72/159616] -I (17320) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [136/159616] -I (17560) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [200/159616] -I (17780) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [264/159616] -I (18010) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [328/159616] -I (18240) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [392/159616] -I (18470) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [456/159616] -I (18700) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [520/159616] -I (18930) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [584/159616] -I (19160) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [648/159616] -I (19390) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [712/159616] -I (19620) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [776/159616] -I (19850) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [840/159616] -I (20100) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [904/159616] -I (20330) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [968/159616] -I (20560) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1032/159616] -I (20790) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1096/159616] -I (21020) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1160/159616] -I (21250) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1224/159616] +I (17100) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [72/552328] +I (17320) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [136/552328] +I (17560) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [200/552328] +I (17780) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [264/552328] +I (18010) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [328/552328] +I (18240) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [392/552328] +I (18470) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [456/552328] +I (18700) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [520/552328] +I (18930) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [584/552328] +I (19160) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [648/552328] +I (19390) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [712/552328] +I (19620) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [776/552328] +I (19850) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [840/552328] +I (20100) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [904/552328] +I (20330) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [968/552328] +I (20560) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1032/552328] +I (20790) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1096/552328] +I (21020) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1160/552328] +I (21250) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [1224/552328] ... -I (595990) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [158664/159616] -I (596220) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [158728/159616] -I (596450) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [158792/159616] -I (596680) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [158856/159616] -I (596910) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [158920/159616] -I (597150) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [158984/159616] -I (597380) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159048/159616] -I (597610) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159112/159616] -I (597840) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159176/159616] -I (598070) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159240/159616] -I (598300) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159304/159616] -I (598530) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159368/159616] -I (598810) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159432/159616] -I (599030) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159496/159616] -I (599260) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159560/159616] -I (599540) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [159616/159616] -I (599610) ESP_OTA_SERVER: OTA client address: 0x7042 -I (599610) ESP_OTA_SERVER: OTA version: 0x1010110, image type: 0x1011, server status: 2 -I (599610) ESP_OTA_SERVER: OTA upgrade time: 0x1234a +I (2005554) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552392/552928] +I (2005784) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552456/552928] +I (2006014) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552520/552928] +I (2006244) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552584/552928] +I (2006474) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552648/552928] +I (2006704) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552712/552928] +I (2006934) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552776/552928] +I (2007164) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552840/552928] +I (2007394) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552904/552928] +I (2007624) ESP_OTA_SERVER: -- OTA Server transmits data from 0x0 to 0x7042: progress [552928/552928] +I (2007664) ESP_OTA_SERVER: OTA client address: 0x7042 +I (2007664) ESP_OTA_SERVER: OTA version: 0x1010110, image type: 0x1011, server status: 2 +I (2007674) ESP_OTA_SERVER: OTA upgrade time: 0x1234a ``` +Note: The example also supports the user pressing the `boot` button to broadcast the `IMAGE_NOTIFY` command to the network. + ## OTA Upgrade Functions * After server starts, server send OTA image notify to client. Then client send the query image request to server. diff --git a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c index a5ea71a..869331a 100644 --- a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c +++ b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 * @@ -19,6 +19,10 @@ static const char *TAG = "ESP_OTA_SERVER"; +static uint32_t s_ota_image_offset = 0; + +static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ON_CONTROL}}; + static esp_err_t zb_ota_next_data_handler(esp_zb_ota_zcl_information_t message, uint16_t index, uint8_t size, uint8_t **data); static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) @@ -26,6 +30,48 @@ static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee commissioning"); } +/** + * @brief Send OTA image notify request + * @param[in] notify_on + * - true: Adds the OTA image file to the OTA image table and broadcasts it to the network + * - false: Only adds the OTA image file to the OTA image table + */ +static esp_err_t zb_ota_upgrade_srv_send_notify_image(bool notify_on) +{ + esp_zb_ota_upgrade_server_notify_req_t req = { + .endpoint = ESP_OTA_SERVER_ENDPOINT, + .index = OTA_UPGRADE_INDEX, + .notify_on = notify_on, + .ota_upgrade_time = OTA_UPGRADE_TIME, + .ota_file_header = + { + .manufacturer_code = OTA_UPGRADE_MANUFACTURER, + .image_type = OTA_UPGRADE_IMAGE_TYPE, + .file_version = OTA_UPGRADE_FILE_VERSION, + .image_size = ota_file_end - ota_file_start, + }, + .next_data_cb = zb_ota_next_data_handler, + }; + return esp_zb_ota_upgrade_server_notify_req(&req); +} + +static void zb_buttons_handler(switch_func_pair_t *button_func_pair) +{ + esp_zb_lock_acquire(portMAX_DELAY); + if (esp_zb_bdb_dev_joined()) { + zb_ota_upgrade_srv_send_notify_image(true); + ESP_LOGI(TAG, "Send OTA Server notify image request"); + } + esp_zb_lock_release(); +} + +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; +} + void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { uint32_t *p_sg_p = signal_struct->p_app_signal; @@ -40,11 +86,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) 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 { @@ -75,22 +123,11 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE: { dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t *)esp_zb_app_signal_get_params(p_sg_p); ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr); - esp_zb_ota_upgrade_server_notify_req_t req = { - .endpoint = ESP_OTA_SERVER_ENDPOINT, - .index = OTA_UPGRADE_INDEX, - .notify_on = true, - .ota_upgrade_time = OTA_UPGRADE_TIME, - .ota_file_header = - { - .manufacturer_code = OTA_UPGRADE_MANUFACTURER, - .image_type = OTA_UPGRADE_IMAGE_TYPE, - .file_version = OTA_UPGRADE_FILE_VERSION, - .image_size = ota_file_end - ota_file_start, - }, - .next_data_cb = zb_ota_next_data_handler, - }; - esp_zb_ota_upgrade_server_notify_req(&req); - ESP_LOGI(TAG, "OTA Server notify"); + /* Broadcast Image Notify Request when the OTA server is not in OTA process */ + if (s_ota_image_offset == 0) { + zb_ota_upgrade_srv_send_notify_image(true); + ESP_LOGI(TAG, "Notify OTA upgrade"); + } break; } case ESP_ZB_NWK_SIGNAL_PERMIT_JOIN_STATUS: @@ -109,7 +146,6 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) } } -static uint32_t s_ota_image_offset = 0; static esp_err_t zb_ota_next_data_handler(esp_zb_ota_zcl_information_t message, uint16_t index, uint8_t size, uint8_t **data) { switch (index) { @@ -122,6 +158,9 @@ static esp_err_t zb_ota_next_data_handler(esp_zb_ota_zcl_information_t message, return ESP_FAIL; break; } + if (s_ota_image_offset >= (ota_file_end - ota_file_start)) { + s_ota_image_offset = 0; + } ESP_LOGI(TAG, "-- OTA Server transmits data from 0x%x to 0x%x: progress [%ld/%d]", message.dst_short_addr, message.src_addr.u.short_addr, s_ota_image_offset, (ota_file_end - ota_file_start)); return (*data) ? ESP_OK : ESP_FAIL; @@ -154,6 +193,7 @@ static esp_err_t zb_ota_upgrade_server_query_image_handler(esp_zb_zcl_ota_upgrad } ESP_RETURN_ON_FALSE((message.image_type == OTA_UPGRADE_IMAGE_TYPE && message.manufacturer_code == OTA_UPGRADE_MANUFACTURER), ESP_ERR_NOT_FOUND, TAG, "OTA query image mismatch"); + s_ota_image_offset = 0; return ret; } @@ -174,39 +214,46 @@ static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, return ret; } -static void esp_zb_task(void *pvParameters) +static esp_err_t zb_register_ota_upgrade_server_device(void) { - /* initialize Zigbee stack */ - esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG(); - esp_zb_init(&zb_nwk_cfg); - - esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_basic_cluster_create(NULL); - esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME); - esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER); - /* create ota upgrade cluster with server parameters */ - esp_zb_attribute_list_t *esp_zb_ota_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_OTA_UPGRADE); + esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create(NULL); + esp_zb_attribute_list_t *ota_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_OTA_UPGRADE); + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create(); esp_zb_zcl_ota_upgrade_server_variable_t variable = { - .query_jitter = OTA_UPGRADE_QUERY_JITTER, /* query jitter indicates whether the client receiving Image Notify Command */ - .current_time = OTA_UPGRADE_CURRENT_TIME, /* current time of ota server */ - .file_count = OTA_UPGRADE_IMAGE_COUNT, /* The number of ota images */ + .query_jitter = OTA_UPGRADE_QUERY_JITTER, + .current_time = OTA_UPGRADE_CURRENT_TIME, + .file_count = OTA_UPGRADE_IMAGE_COUNT, }; - esp_zb_ota_cluster_add_attr(esp_zb_ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_DATA_ID, (void *)&variable); - /* create cluster lists with ota cluster */ - esp_zb_cluster_list_t *esp_zb_cluster_list = esp_zb_zcl_cluster_list_create(); - esp_zb_cluster_list_add_basic_cluster(esp_zb_cluster_list, esp_zb_basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - esp_zb_cluster_list_add_ota_cluster(esp_zb_cluster_list, esp_zb_ota_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - esp_zb_ep_list_t *esp_zb_ep_list = esp_zb_ep_list_create(); - /* add created endpoint (cluster_list) to endpoint list */ esp_zb_endpoint_config_t endpoint_config = { .endpoint = ESP_OTA_SERVER_ENDPOINT, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_TEST_DEVICE_ID, - .app_device_version = 0 + .app_device_version = 0, }; - esp_zb_ep_list_add_ep(esp_zb_ep_list, esp_zb_cluster_list, endpoint_config); - esp_zb_device_register(esp_zb_ep_list); + + /* Added attributes */ + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER)); + ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_DATA_ID, (void *)&variable)); + /* Added clusters */ + ESP_ERROR_CHECK(esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)); + ESP_ERROR_CHECK(esp_zb_cluster_list_add_ota_cluster(cluster_list, ota_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)); + /* Added endpoints */ + ESP_ERROR_CHECK(esp_zb_ep_list_add_ep(ep_list, cluster_list, endpoint_config)); + /* Register device */ + return esp_zb_device_register(ep_list); +} + +static void esp_zb_task(void *pvParameters) +{ + /* initialize Zigbee stack */ + 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_core_action_handler_register(zb_action_handler); + ESP_ERROR_CHECK(zb_register_ota_upgrade_server_device()); ESP_ERROR_CHECK(esp_zb_start(false)); esp_zb_main_loop_iteration(); } diff --git a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.h b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.h index f0019d4..8ba2014 100644 --- a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.h +++ b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 * @@ -13,6 +13,7 @@ */ #include "esp_zigbee_core.h" +#include "switch_driver.h" /* Zigbee configuration */ #define MAX_CHILDREN 10 /* The max amount of connected devices */ @@ -26,9 +27,9 @@ #define OTA_UPGRADE_TIME OTA_UPGRADE_CURRENT_TIME + OTA_UPGRADE_OFFSET_TIME /* Upgrade time indicates the time that the client shall upgrade to running new image, offset time value is of 5 seconds */ #define OTA_UPGRADE_QUERY_JITTER 0x64 /* Query jitter indicates whether the client receiving Image Notify Command */ #define OTA_UPGRADE_CURRENT_TIME 0x12345 /* Test current time of ota server, currently zcl time cluster is not supported */ -#define OTA_UPGRADE_IMAGE_COUNT 1 /* The number of OTA image for OTA server */ +#define OTA_UPGRADE_IMAGE_COUNT 1 /* The number of OTA images on OTA server */ #define OTA_UPGRADE_OFFSET_TIME 5 /* Offset time value in seconds, use as upgrade delay.*/ -#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */ /* ota_file.bin */ extern const uint8_t ota_file_start[] asm("_binary_ota_file_bin_start"); /* ota_file corresponds to filename and bin corresponds to filetype */ diff --git a/examples/esp_zigbee_ota/ota_server/main/ota_file.bin b/examples/esp_zigbee_ota/ota_server/main/ota_file.bin index 4a57346..1cb2c3c 100644 Binary files a/examples/esp_zigbee_ota/ota_server/main/ota_file.bin and b/examples/esp_zigbee_ota/ota_server/main/ota_file.bin differ diff --git a/examples/esp_zigbee_ota/ota_server/partitions.csv b/examples/esp_zigbee_ota/ota_server/partitions.csv index fdbf2c2..90c472b 100644 --- a/examples/esp_zigbee_ota/ota_server/partitions.csv +++ b/examples/esp_zigbee_ota/ota_server/partitions.csv @@ -2,6 +2,6 @@ # 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, 900K, -zb_storage, data, fat, 0xf1000, 16K, -zb_fct, data, fat, 0xf5000, 1K, \ No newline at end of file +factory, app, factory, 0x10000, 1400K, +zb_storage, data, fat, , 16K, +zb_fct, data, fat, , 1K, \ No newline at end of file diff --git a/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c b/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c index 41cb7c1..96f6d34 100644 --- a/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c +++ b/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c @@ -134,42 +134,44 @@ static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, return ret; } -static void esp_zb_task(void *pvParameters) +static esp_err_t zb_register_touchlink_light_device(void) { - /* Initialize Zigbee stack with Zigbee coordinator config */ - esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZR_CONFIG(); - esp_zb_init(&zb_nwk_cfg); - - esp_zb_set_channel_mask(ESP_ZB_TOUCHLINK_CHANNEL_MASK); - esp_zb_set_rx_on_when_idle(true); - esp_zb_zdo_touchlink_target_set_timeout(TOUCHLINK_TARGET_TIMEOUT); - + esp_zb_ep_list_t *ep_list = NULL; esp_zb_attribute_list_t *touchlink_cluster = esp_zb_touchlink_commissioning_cluster_create(); - esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG(); - /* Create a standard HA on-off light cluster list */ - esp_zb_cluster_list_t *cluster_list = esp_zb_on_off_light_clusters_create(&light_cfg); - esp_zb_attribute_list_t *basic_cluster = - esp_zb_cluster_list_get_cluster(cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME)); - ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER)); - - /* Add touchlink commissioning cluster */ - esp_zb_cluster_list_add_touchlink_commissioning_cluster(cluster_list, touchlink_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - - esp_zb_ep_list_t *esp_zb_ep_list = esp_zb_ep_list_create(); - /* Add created endpoint (cluster_list) to endpoint list */ + esp_zb_cluster_list_t *cluster_list = NULL; + esp_zb_attribute_list_t *basic_cluster = NULL; esp_zb_endpoint_config_t endpoint_config = { .endpoint = HA_ESP_LIGHT_ENDPOINT, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_ON_OFF_LIGHT_DEVICE_ID, - .app_device_version = 0 + .app_device_version = 0, }; - esp_zb_ep_list_add_ep(esp_zb_ep_list, cluster_list, endpoint_config); - - esp_zb_device_register(esp_zb_ep_list); - esp_zb_core_action_handler_register(zb_action_handler); + /* ZCL data model */ + ep_list = esp_zb_ep_list_create(); + cluster_list = esp_zb_on_off_light_clusters_create(&light_cfg); + touchlink_cluster = esp_zb_touchlink_commissioning_cluster_create(); + /* Add attributes */ + basic_cluster = esp_zb_cluster_list_get_cluster(cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER)); + /* Add cluster */ + ESP_ERROR_CHECK(esp_zb_cluster_list_add_touchlink_commissioning_cluster(cluster_list, touchlink_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)); + /*Add endpoint */ + ESP_ERROR_CHECK(esp_zb_ep_list_add_ep(ep_list, cluster_list, endpoint_config)); + return esp_zb_device_register(ep_list); +} +static void esp_zb_task(void *pvParameters) +{ + /* Initialize Zigbee stack with Zigbee coordinator config */ + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZR_CONFIG(); + esp_zb_init(&zb_nwk_cfg); + esp_zb_set_channel_mask(ESP_ZB_TOUCHLINK_CHANNEL_MASK); + esp_zb_set_rx_on_when_idle(true); + esp_zb_zdo_touchlink_target_set_timeout(TOUCHLINK_TARGET_TIMEOUT); + esp_zb_core_action_handler_register(zb_action_handler); + ESP_ERROR_CHECK(zb_register_touchlink_light_device()); ESP_ERROR_CHECK(esp_zb_start(false)); esp_zb_main_loop_iteration(); } diff --git a/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c b/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c index d99a5b1..19c399a 100644 --- a/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c +++ b/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c @@ -13,6 +13,7 @@ */ #include #include "esp_check.h" +#include "esp_err.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -47,18 +48,17 @@ typedef struct light_bulb_info_s typedef struct light_control_device_ctx_t { - light_bulb_info_t on_off_light;; /* persistent, remote device struct for recording and managing node info */ - esp_zb_ieee_addr_t pending_dev_addr; /* addr of device which is pending for discovery */ + light_bulb_info_t on_off_light; /* persistent, remote device struct for recording and managing node info */ + esp_zb_ieee_addr_t pending_dev_addr; /* addr of device which is pending for discovery */ } light_control_device_ctx_t; light_control_device_ctx_t g_device_ctx; /* light control device ifnfomation */ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) { - /* By checking the button function pair to call different cmd send */ - switch (button_func_pair->func) { - case SWITCH_ONOFF_TOGGLE_CONTROL: + if (esp_zb_bdb_dev_joined()) { /* Send on-off toggle command to remote device */ + assert(button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL); esp_zb_zcl_on_off_cmd_t cmd_req; 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; @@ -67,9 +67,12 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) esp_zb_zcl_on_off_cmd_req(&cmd_req); esp_zb_lock_release(); ESP_EARLY_LOGI(TAG, "send 'on_off toggle' command"); - break; - default: - break; + } else { + /* Control Touchlink initiator commissioning */ + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_TOUCHLINK_COMMISSIONING); + esp_zb_lock_release(); + ESP_LOGI(TAG, "Scanning as a Touchlink initiator..."); } } @@ -121,18 +124,12 @@ void find_light_bulb(uint16_t short_addr) memset(g_device_ctx.pending_dev_addr, 0, sizeof(esp_zb_ieee_addr_t)); } -/********************* Define functions **************************/ -static void esp_zb_start_touchlink_commissioning(void) -{ - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_TOUCHLINK_COMMISSIONING); - ESP_LOGI(TAG, "Scanning as a Touchlink initiator..."); -} - 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; + esp_zb_bdb_signal_touchlink_nwk_params_t *sig_params = NULL; switch (sig_type) { case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: @@ -145,7 +142,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) 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_zb_start_touchlink_commissioning(); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_TOUCHLINK_COMMISSIONING); + ESP_LOGI(TAG, "Scanning as a Touchlink initiator..."); } else { ESP_LOGI(TAG, "Device rebooted"); } @@ -155,7 +153,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) break; case ESP_ZB_BDB_SIGNAL_TOUCHLINK_NWK_STARTED: case ESP_ZB_BDB_SIGNAL_TOUCHLINK_NWK_JOINED_ROUTER: - esp_zb_bdb_signal_touchlink_nwk_params_t *sig_params = (esp_zb_bdb_signal_touchlink_nwk_params_t *)esp_zb_app_signal_get_params(p_sg_p); + sig_params = (esp_zb_bdb_signal_touchlink_nwk_params_t *)esp_zb_app_signal_get_params(p_sg_p); memcpy(g_device_ctx.pending_dev_addr, sig_params->device_ieee_addr, sizeof(esp_zb_ieee_addr_t)); ESP_LOGI(TAG, "Touchlink initiator receives the response for %s network", sig_type == ESP_ZB_BDB_SIGNAL_TOUCHLINK_NWK_STARTED ? "started" : "router joining"); @@ -177,8 +175,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) find_light_bulb(esp_zb_address_short_by_ieee(g_device_ctx.pending_dev_addr)); } } else { - /* Repeat touchlink until any bulb will be found */ - esp_zb_start_touchlink_commissioning(); + ESP_LOGW(TAG, "No Touchlink target devices found"); + ESP_LOGW(TAG, "Press the button to start Touchlink commissioning again"); } break; default: @@ -187,37 +185,44 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) } } -static void esp_zb_task(void *pvParameters) +static esp_err_t zb_register_touchlink_switch_device(void) { - esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); - esp_zb_init(&zb_nwk_cfg); - esp_zb_set_channel_mask(ESP_ZB_TOUCHLINK_CHANNEL_MASK); - esp_zb_zdo_touchlink_set_nwk_channel(ESP_ZB_TOUCHLINK_CHANNEL); - esp_zb_set_rx_on_when_idle(true); - - esp_zb_attribute_list_t *touchlink_cluster = esp_zb_touchlink_commissioning_cluster_create(); esp_zb_on_off_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_ON_OFF_SWITCH_CONFIG(); - /* Create a standard HA on-off switch cluster list */ - esp_zb_cluster_list_t *cluster_list = esp_zb_on_off_switch_clusters_create(&switch_cfg); - esp_zb_attribute_list_t *basic_cluster = - esp_zb_cluster_list_get_cluster(cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME)); - ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER)); - - /* Add touchlink commissioning cluster */ - esp_zb_cluster_list_add_touchlink_commissioning_cluster(cluster_list, touchlink_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE); - - esp_zb_ep_list_t *esp_zb_ep_list = esp_zb_ep_list_create(); - /* Add created endpoint (cluster_list) to endpoint list */ + esp_zb_cluster_list_t *cluster_list = NULL; + esp_zb_attribute_list_t *basic_cluster = NULL; + esp_zb_attribute_list_t *touchlink_cluster = NULL; + esp_zb_ep_list_t *ep_list = NULL; esp_zb_endpoint_config_t endpoint_config = { .endpoint = HA_ONOFF_SWITCH_ENDPOINT, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_ON_OFF_SWITCH_DEVICE_ID, - .app_device_version = 0 + .app_device_version = 0, }; - esp_zb_ep_list_add_ep(esp_zb_ep_list, cluster_list, endpoint_config); - esp_zb_device_register(esp_zb_ep_list); + /* ZCL data model */ + ep_list = esp_zb_ep_list_create(); + cluster_list = esp_zb_on_off_switch_clusters_create(&switch_cfg); + touchlink_cluster = esp_zb_touchlink_commissioning_cluster_create(); + /* Add attributes */ + basic_cluster = esp_zb_cluster_list_get_cluster(cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ESP_MANUFACTURER_NAME)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ESP_MODEL_IDENTIFIER)); + /* Add cluster */ + ESP_ERROR_CHECK(esp_zb_cluster_list_add_touchlink_commissioning_cluster(cluster_list, touchlink_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE)); + /* Add endpoint */ + ESP_ERROR_CHECK(esp_zb_ep_list_add_ep(ep_list, cluster_list, endpoint_config)); + return esp_zb_device_register(ep_list); +} + +static void esp_zb_task(void *pvParameters) +{ + /* Initialize Zigbee stack with Zigbee end device config */ + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); + esp_zb_init(&zb_nwk_cfg); + esp_zb_set_channel_mask(ESP_ZB_TOUCHLINK_CHANNEL_MASK); + esp_zb_zdo_touchlink_set_nwk_channel(ESP_ZB_TOUCHLINK_CHANNEL); + esp_zb_set_rx_on_when_idle(true); + ESP_ERROR_CHECK(zb_register_touchlink_switch_device()); ESP_ERROR_CHECK(esp_zb_start(false)); esp_zb_main_loop_iteration(); } diff --git a/examples/pytest_esp_zigbee_open_examples.py b/examples/pytest_esp_zigbee_open_examples.py index 4bbaf26..159af06 100644 --- a/examples/pytest_esp_zigbee_open_examples.py +++ b/examples/pytest_esp_zigbee_open_examples.py @@ -19,7 +19,7 @@ SWITCH_CURRENT_DIR_SERVER = str(pathlib.Path(__file__).parent) + '/esp_zigbee_touchlink/touchlink_switch' LIGHT_CURRENT_DIR_CLIENT = str(pathlib.Path(__file__).parent) + '/esp_zigbee_touchlink/touchlink_light' -touchlink_pytest_build_dir = SWITCH_CURRENT_DIR_SERVER + '|' + LIGHT_CURRENT_DIR_CLIENT +touchlink_pytest_build_dir = LIGHT_CURRENT_DIR_CLIENT + '|' + SWITCH_CURRENT_DIR_SERVER HA_CURRENT_DIR_SERVER = str(pathlib.Path(__file__).parent) + '/esp_zigbee_cli' GATEWAY_CURRENT_DIR_CLIENT = str(pathlib.Path(__file__).parent) + '/esp_zigbee_gateway' @@ -297,11 +297,11 @@ def test_zb_sleep(dut, count, app_path, erase_all): @pytest.mark.parametrize('count, app_path, erase_all', [(2, touchlink_pytest_build_dir, 'y'), ], indirect=True, ) @pytest.mark.usefixtures('teardown_fixture') def test_zb_touch_link(dut, count, app_path, erase_all): - switch = dut[0] - light = dut[1] - switch.expect('Scanning as a Touchlink initiator...') - time.sleep(5) + light = dut[0] + switch = dut[1] light.expect('Touchlink target is ready, awaiting commissioning') + time.sleep(5) + switch.expect('Scanning as a Touchlink initiator...') extended_pan_id_light, pan_id_light, channel_light, short_address_light = get_formed_network_parameters(light) extended_pan_id_switch, pan_id_switch, channel_switch, short_address_switch = get_formed_network_parameters(switch) assert extended_pan_id_light == extended_pan_id_switch