Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

Zigbee device Development


firmware@nuos.in
Posts: 19

I am writing zigbee code to sync time using Time cluster. My code works well with home assistant (i can read local time) but fails to read local time attribute (Value NULL) from tuya gateway. Why this is happening? My app timezone is 5:30 GMT.
Do tuya gateway not allow to give you date time value?

User avatar
huanghuan
Posts: 265

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

1.Hello, please tell me the virtual id of the tuya gateway. You can click on the upper right corner of the app interface to view the id.
2.At the same time, we need to confirm which endpoint, cluster and attribute are used when you read ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID. If possible, please attach wireless packet capture, thank you.

firmware@nuos.in
Posts: 19

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

Hi

Can you please tell me the network key for Wireshark to scan packets from Tuya gateway.

User avatar
huanghuan
Posts: 265

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

The Tuya gateway uses the default link key 5A 69 67 42 65 65 41 6C 6C 69 61 6E 63 65 30 39,You need to reconnect the device to the network and grab the wireless packet to get the nwk key

firmware@nuos.in
Posts: 19

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

zb_zcl_attribute_t attr_fields;
attr_fields.id = ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID;
attr_fields.data.type = ZB_ZCL_ATTR_TYPE_32BIT;
attr_fields.data.size = 4;

Code: Select all

zb_zcl_read_attr_cmd_t read_cmd = {
    .zcl_basic_cmd.dst_endpoint = 1,
    .zcl_basic_cmd.src_endpoint = 1,
    .zcl_basic_cmd.dst_addr_u.addr_short = 0x0000,
    .address_mode = ZB_APS_ADDR_MODE_16_ENDP_PRESENT,
    .clusterID = ZB_ZCL_CLUSTER_ID_TIME,
    .manuf_specific = 0,
    .direction = ZB_ZCL_CMD_DIRECTION_TO_CLI, // Client-to-Server direction
    .dis_defalut_resp = 1,
    .manuf_code = 0,
    .attr_number = 1
};
read_cmd.attr_field = &attr_fields;

esp_zb_zcl_read_attr_cmd_req(&read_cmd);

this is my piece of code for callback received!
if (variable->attribute.id == ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID) {
printf("On Attribute ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID Callback\n");
if (variable->attribute.data.value) {
time_t t = *(uint32_t *)variable->attribute.data.value + 946684800;
printf("Converted time: %s", ctime(&t));
} else {
printf("Invalid attribute value (NULL)\n");
}
}

what will be the issue??

firmware@nuos.in
Posts: 19

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

I am getting result "Invalid attribute value".

User avatar
huanghuan
Posts: 265

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

1.You can use the following function to get the time.

Code: Select all


VOID_T user_time_sync_request_send(VOID_T)
{
    TAL_ZG_SEND_DATA_T data;

tkl_system_memset(&data, 0, sizeof(TAL_ZG_SEND_DATA_T));

data.addr.mode = SEND_MODE_DEV;
data.addr.type.dev.dst_ep = TUYA_PRIMARY_ENDPOINT;
data.addr.type.dev.src_ep = TUYA_PRIMARY_ENDPOINT;
data.addr.type.dev.dst_addr = TUYA_GATEWAY_ADDRESS;
data.addr.type.dev.cluster_id = CLUSTER_TIME_CLUSTER_ID;

data.zcl_id = 0xF0;
data.qos = QOS_1;
data.frame_type = ZG_ZCL_FRAME_TYPE_GLOBAL;
data.direction = ZG_ZCL_DATA_CLIENT_TO_SERVER;
data.command_id = CMD_READ_ATTRIBUTES_COMMAND_ID;

data.data.zg.attr_sum = 1;
data.data.zg.attr[0].attr_id = ATTR_LOCAL_TIME_ATTRIBUTE_ID;

tal_time_sync_debug("gateway time sync.\r\n");
tal_zg_send_data(&data, NULL, 1000);
}

2.To get the result you need to define the following function, which will be used to callback the result after the above data is sent.

Code: Select all

VOID_T tal_time_sync_complete_callback(BOOL_T status, UINT_T time_sec)
{
    if(status && time_sec) {
        return;
    }
}

When the callback result is successful, you can obtain the time using

Code: Select all

tal_current_time_get

This timestamp from 2000 is not UTC, you add the difference 946656000

User avatar
huanghuan
Posts: 265

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

The above code is based on tuyaos tlsr8258 version 3.11.0

firmware@nuos.in
Posts: 19

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

My code works ok with home assistant, but same failed to work with tuya gateway. I also followed your code steps, issue is still same. I am getting null local time attribute when i read it.

User avatar
huanghuan
Posts: 265

Re: Getting NULL value of ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID attribute from Tuya Gateway

1.please tell me the virtual id of the tuya gateway. You can click on the upper right corner of the app interface to view the id.
2.please attach wireless packet capture, thank you.

Post Reply