4.1.5. Zigbee Cluster Library (ZCL)
In ESP Zigbee SDK v2.x, the Zigbee Cluster Library (ZCL) APIs are redesigned for flexibility and easier use. Besides the namespace changes, the functions, types, enums and fields of structures are renamed to clearer, more understandable names. The APIs related to specific clusters are moved to the corresponding cluster header file. Here is a description of the general changes of the ZCL APIs, for details of the new interfaces, see Zigbee Cluster Library (ZCL).
4.1.5.1. Data Model
The data model APIs are redesigned to make the hierarchy of the ZCL data model clearer.
v1.x |
v2.x |
|
|---|---|---|
Type |
|
|
Create |
|
|
Delete |
N/A |
|
Add Endpoint |
|
|
Get Endpoint |
|
|
Register |
|
v1.x |
v2.x |
|
|---|---|---|
Type |
|
|
Create |
|
|
Delete |
N/A |
|
Add Cluster |
|
|
Get Cluster |
|
|
Update Cluster |
|
N/A |
v1.x |
v2.x |
|
|---|---|---|
Type |
|
|
Create |
|
|
Delete |
N/A |
|
Get |
|
|
Add Attribute |
|
|
Get Attribute |
N/A |
|
Update Attribute |
|
N/A |
v1.x |
v2.x |
|
|---|---|---|
Type |
|
|
Create |
N/A |
|
Delete |
N/A |
|
Get |
|
|
Set Value |
|
4.1.5.2. ZCL Commands
The ZCL command APIs are renamed to follow the convention: ezb_zcl_{cluster}_{command}_cmd_req().
The command request structures now share the same structure: ezb_zcl_cluster_cmd_ctrl_t, in which you can
specify the confirm information to get the transmission result of the command, and the ezb_err_t is used as the return
value rather than the transaction sequence number. The profile_id field is removed from this structure, the profile id
is determined by the profile id of the source endpoint specified by src_ep.
An important behavior change is that the command APIs now require the data model to exist on the device. This includes
the correct role of the correct cluster in the source endpoint. For example, to send the OnOff On command, you need
to ensure the ``OnOff`` client cluster is added to the source endpoint before calling the command API.
If you want to send an arbitrary command without the cluster data model (typically for gateway usage), you can add a special gateway endpoint to the device. The check of the cluster data model would be skipped if the transmission request is from/to a gateway endpoint.
4.1.5.3. ZCL Messages
The ZCL messages are reported via core action callback, as in v1.x. The definition of the message structure
of each core action is defined in separate header files of each cluster. Generally, the message contains a common
info field which contains the rx information of the message, in field which contains the input data of the message,
and out field which contains the output data of the message (always response payload of the request).
4.1.5.4. ZCL Clusters
The v2.x implementation aims to conform to the ZCL specification as much as possible, so several behavior changes have been introduced. The list below highlights the changes for commonly used clusters. For more details, see the API references of corresponding cluster header files.
An important change for all clusters is that clusters on different endpoints are implemented as separate instances and would not affect each other.
4.1.5.4.1. On/Off
The
esp_zb_zcl_on_off_cmd_reqAPI has been split into three APIs:
4.1.5.4.2. Scenes
The scenes table is maintained separately for each Scenes cluster instance, and the size is configured by
ezb_zcl_scenes_cluster_server_config_s::scene_table_sizewhen the Scenes cluster is created using theezb_zcl_scenes_create_cluster_desc()API.
4.1.5.4.3. Time
The Time cluster server now requires a time interface to get/set the current UTC time, which can be registered by
ezb_zcl_time_server_interface_register(). The interface is used to synchronize the time attribute of the cluster with system RTC timer.The
ezb_zcl_time_server_synchronize_time()API is provided to discover and synchronize with other Time servers on the network. The server preference is determined based on the ranking of thetime statusattribute as defined in the ZCL specification.
4.1.5.4.4. Color Control
EZB_ZCL_CORE_COLOR_CONTROL_COLOR_MODE_CHANGE_CB_IDcore action is introduced to notify the user of the color mode change. It allows the user to provide the customized color value conversion logic during the color mode change.
4.1.5.4.5. Thermostat
The
ezb_zcl_thermostat_set_weekly_schedule_cmd_req()API allows adding multiple schedule entries (up to 10) in a single command.The
ezb_zcl_thermostat_get_weekly_schedule_cmd_req()API does not support multiple days mode.
4.1.5.4.6. OTA_Upgrade
OTA Upgrade cluster has been redesigned to simplify the handling and management of OTA files for the OTA Upgrade cluster server. The new implementation only performs the OTA file delivery (on the server side) and download (on the client side). The application shall parse, verify and apply the OTA file itself. See our OTA examples for more details.
The user can add/remove OTA files to an OTA Upgrade server using
ezb_zcl_ota_upgrade_add_ota_file()andezb_zcl_ota_upgrade_remove_ota_file(). The server will respond to the client's query request and start the transmission of the OTA file. The user only needs to monitor the server-side OTA progress via the core actionEZB_ZCL_CORE_OTA_UPGRADE_SERVER_PROGRESS_CB_ID.The entire OTA file is passed to the user through the core action
EZB_ZCL_CORE_OTA_UPGRADE_CLIENT_PROGRESS_CB_IDduring the OTA upgrade process. The user can parse, verify and apply the OTA file itself according to the OTA file format defined in the ZCL specification.esp_zb_zcl_ota_upgrade_server_variable_tandesp_zb_zcl_ota_upgrade_client_variable_tare removed; please use APIs to configure the OTA server and client variables respectively (e.g.ezb_zcl_ota_upgrade_set_download_block_size()andezb_zcl_ota_upgrade_set_hw_version()).The following core actions are removed:
ESP_ZB_CORE_OTA_UPGRADE_SRV_QUERY_IMAGE_CB_ID, please handle theEZB_ZCL_OTA_UPGRADE_PROGRESS_STARTevent ofEZB_ZCL_CORE_OTA_UPGRADE_SERVER_PROGRESS_CB_IDcore action.ESP_ZB_CORE_OTA_UPGRADE_SRV_STATUS_CB_ID, please handle theEZB_ZCL_OTA_UPGRADE_PROGRESS_FINISHevent ofEZB_ZCL_CORE_OTA_UPGRADE_SERVER_PROGRESS_CB_IDcore action.ESP_ZB_CORE_OTA_UPGRADE_VALUE_CB_ID, please handle theEZB_ZCL_OTA_UPGRADE_PROGRESS_RECEIVINGevent ofEZB_ZCL_CORE_OTA_UPGRADE_CLIENT_PROGRESS_CB_IDcore action.
4.1.5.4.7. Poll Control
The configuration attributes of Poll Control are no longer stored persistently by the stack. Instead, these attributes will report their value change via
EZB_ZCL_CORE_SET_ATTR_VALUE_CB_ID, in which the user can save the values and restore them across device reboots.
4.1.5.4.8. Custom Cluster
The implementation of custom cluster has been redesigned in a more flexible manner, which allows the user to fully customize its behavior by registering handlers by
ezb_zcl_custom_cluster_handlers_register(). As a result,CUSTOM_CLUSTER_REQ_CB_IDandCUSTOM_CLUSTER_RESP_CB_IDcore actions have been removed.
4.1.5.5. Home Automation (HA)
The Home Automation (HA) APIs are updated to Zigbee Home Automation Specification, Revision 29, Version 1.2. The default clusters included in the HA device endpoint are aligned to only mandatory clusters defined in the specification. For more details, see Introduction.
The APIs (esp_zb_{device_type}_ep_create()) that create the device(endpoint list) with single HA device endpoint
are removed. The APIs (esp_zb_{device_type}_clusters_create()) that create the HA device endpoint are replaced by
ezb_zha_create_{device_type} APIs under the new data model framework.