espressif / esp-zigbee-sdk

Espressif Zigbee SDK
Apache License 2.0
173 stars 29 forks source link

Time cluster (TZ-1194) #446

Closed akira215 closed 1 month ago

akira215 commented 1 month ago

Question

In esp_zigbee_type.h the mandatories attributes for esp_zb_time_cluster_cfg_s are: uint16_t time; and uint16_t time_status;. However, the ZCL spec rev 8 instructs that Time attribute is UTC type which should be 32 bits in length, and TimeStatus attribute is map8 (which should obviously be 8bits length).

Am I missing something or is there any mistake in the struct declaration ?

Additional context.

I've checked the attribute type of both of these 2 using esp_zb_zcl_get_attribute, and it return the correct ones (i.e. ESP_ZB_ZCL_ATTR_TYPE_UTC_TIME for Time and ESP_ZB_ZCL_ATTR_TYPE_8BITMAP for TimeStatus . That mean that the implementation is correct, but it can lead to initialization issue when creating the cluster from scratch.

xieqinan commented 1 month ago

Hi @akira215 ,

Thank you for testing. It is indeed an error in the declaration of the esp_zb_time_cluster_cfg_s structure in the esp-zigbee-sdk. We will address this issue in the next release. In the meantime, you can use the following code as a workaround.

esp_zb_attribute_list_t *esp_zb_app_time_cluster_create(void)
{
    uint32_t lu32_time_default;
    uint8_t  lu8_time_status_default;

    esp_zb_attribute_list_t *esp_zb_time_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_TIME);
    esp_zb_time_cluster_add_attr(esp_zb_time_cluster, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, &lu32_time_default);
    esp_zb_time_cluster_add_attr(esp_zb_time_cluster, ESP_ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, &lu8_time_status_default);
    return esp_zb_time_cluster;
}
akira215 commented 1 month ago

Thanks for the update, and for the incoming fix !