[Zigbee] Problem with Zcl callback handler in zigbee and thread 4.2.0

Hi guys,

So lately, I decided to update the sdk from 4.1.0 to 4.2.0 and there are some problem that I can not solve myself. So I use the macro ZB_ZCL_REGISTER_DEVICE_CB to register a device call back in 4.1.0 and now keeping it in 4.2.0.

But I have this problem when I tried to send an on off cmd from the coordinator to the device(router role) everything is fine. When I tried to send the report (multi state cluster since I have many state of the button) from the router to the coordinator, it is also OK too. But If i just turn the device on by hand and try to turn it off by sending cmd off of zigbee, although the packet is successfully  receive(I use the endpoint handler), It does not call the cb function that I register before.

This problem is not existed in the last SDK so I do not know if there are any config need to be set to use the ZB_ZCL_REGISTER_DEVICE_CB correctly and compare to the light bulb example seem to have that the only diffent is that I declare the context after I call this marcro but I does now seem to make any difference. So can you tell me how I can fix this or can you give me some hint on how to use the ZB_AF_SET_ENDPOINT_HANDLER to replace that.

Thank you very much,

Best regards,

Tu

Parents Reply Children
  • Hi,

    I just found out that I can change the way the zcl callback is call for by modifying the corresponding file in Zboss so now the callback will be call whenever the command is arrive.

    Thank you very much for your help.

    Best regards,

    Tu

  • Hi again,

    Tu Hoang said:
    I just found out that I can change the way the zcl callback is call for by modifying the corresponding file in Zboss so now the callback will be call whenever the command is arrive.

    My colleague brought up a good point with regards to this. In case you are using the endpoint handler by changing the corresponding file Iwould like to point you towards the cli_agent_ep_handler_report() in the components/zigbee/cli/zigbee_cli_cmd_attr_report.c or cli_agent_ep_handler_attr() in components/zigbee/cli/zigbee_cli_cmd_attr.c for example of how to use endpoint handler (registered by ZB_AF_SET_ENDPOINT_HANDLER()). Changing "the corresponding file" is not great approach, to prevent unexpected behavior use endpoint handler.

    Kind regards,
    Andreas

  • Hi AHuag,

    Thank you for your dedication, I will take a look at the  components/zigbee/cli/zigbee_cli_cmd_attr_report.c  and components/zigbee/cli/zigbee_cli_cmd_attr.c to see if I can change the zcl callback to endpoint handler. But as far as I know if I use more than 1 endpoint for my application, I will have to set up a 4 handlers for it. Is it correct?

    Best regards,

    Tu

  • So I did tried to use endpoint handler, I can get the on/off cmd but can not parse the message by zb_zcl_parsed_hdr_t * p_cmd_info = ZB_BUF_GET_PARAM(bufid, zb_zcl_parsed_hdr_t); 

    When I tried to log the cmd, it just an increase number every time. Do you have any idea how this happen.

    Best regards,

    Tu

  • Hi,

    Try the following code snippet

     

    zb_uint8_t ep_handler(zb_bufid_t bufid)
    {
        zb_zcl_parsed_hdr_t *cmd_info = ZB_BUF_GET_PARAM(bufid, zb_zcl_parsed_hdr_t);
     
        if (cmd_info->cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF)
        {
            switch (cmd_info->cmd_id)
            {
                case ZB_ZCL_CMD_ON_OFF_OFF_ID:
                    NRF_LOG_INFO("OFF cmd received");
                    break;
                case ZB_ZCL_CMD_ON_OFF_ON_ID:
                    NRF_LOG_INFO("ON cmd received");
                    break;
                case ZB_ZCL_CMD_ON_OFF_TOGGLE_ID:
                    NRF_LOG_INFO("TOGGLE cmd received");
                    break;
                default:
                    NRF_LOG_ERROR("UNKNOWN cmd received");
                    break;
            }
        }
     
        return ZB_FALSE;
    }
     
    ...
     
    ZB_AF_SET_ENDPOINT_HANDLER(HA_DIMMABLE_LIGHT_ENDPOINT, ep_handler);

    One note of warning: To make sure that the received command is correct you should also check:

    • profile ID
    • command direction
    • if the command is manufacturer specific

    Let me know if this works or not!

    Kind regards,
    Andreas

Related