This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading command payload in zigbee callback

Hello all! 

I have been modifying the door_lock_nus example to add the set pin command (0x05 from zcl reference). So I have modified the zigbee callback to read the new command, and I am doing it right with:

switch (cmd_info -> cmd_id)
{
    case ZB_ZCL_CMD_DOOR_LOCK_SET_PIN_CODE:
    ...
    break;
}

The procces is as follows:

1.- Start the coordinator and establish connection between the boards.

2.- Bind the devices and send lock/unlock commands.

3.- Try to send the set pin code command by sending: zcl cmd f4ce3693d838e02b 1 0101 -p 0104 05 0x000000001234

4.- The device enters the ZB_ZCL_CMD_DOOR_LOCK_SET_PIN_CODE case but I'm stuck in getting thee payload.

My problem is that the set pin code command has a payload and I can't figure out how to read it. Do I need to use "ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES"? What's the way to go?

Parents Reply Children
  • Hello!

    I don't know if I am right because I am very new into Zigbee, but I think I am using an endpoint handler. The code I'm using is this:

    zb_zcl_parsed_hdr_t *cmd_info = ZB_BUF_GET_PARAM(bufid, zb_zcl_parsed_hdr_t);
    
    switch (cmd_info -> cmd_id)
        {
            case ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR:
                ...
                break;
    
            case ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR:
                ...
                break;
    
            case ZB_ZCL_CMD_DOOR_LOCK_SET_PIN_CODE:
                ...
                break;
    
            default:
                ...
                break;
        }

    To set the commands handler I am using this code:

    ZB_AF_SET_ENDPOINT_HANDLER(ZB_ZCL_CLUSTER_ID_DOOR_LOCK, ep_cb);

    Hope it helps.

    Cheers!

  • Hi,

    I'm sorry for the late reply, but I finally heard back from the Zigbee team:

    The code for checking the command is in the right direction. The command payload can be obtained by reading the buffer passed into the callback by its id (bufid), just like in the case of obtaining the command type.

    In the code listed below you can find the most straightforward way to obtain the command payload. (param is bufid in this code)

    switch (cmd_info->cmd_id) {
        case ZB_ZCL_CMD_DOOR_LOCK_SET_PIN_CODE: {
            zb_uint8_t cmd_len = zb_buf_len(param);
            zb_uint8_t *pin_payload = (zb_uint8_t*) zb_buf_begin(param);
     
            LOG_INF("Command set pin has len of %u", cmd_len);
     
            for (int i = 0; i < cmd_len; i++)
            {
                LOG_INF("Payload[%u] %u", i, pin_payload[i]); 
            }
            break;
        }
        default:
            LOG_INF("Received unknown command!");
            break;
        }

    If you are using CLI Agent tool, then correct syntax for sending a command with a payload would be: zcl cmd f4ce3693d838e02b 1 0101 -p 0104 05 -l 0x000000001234.
    Without "-l", the command will not contain any payload. 

    Best regards,

    Marte

  • Thank you Marte!

    I will give the code a try in a few days. So if it works fine, I would mark your answer as verified.

  • Just one last questuin Marte, I was using the CLI agent tool for the early stages of the development but now I switched to the final coordinator. The final coordinator is not a NRF52840DK board and I am experimenting some issues with the interview.

    My question is if the code you posted could be used in a ZCL callback? Do I have to modify something?

    Thanks!

  • Hi,

    You should be able to use the code I posted in a coordinator that does not use CLI as well.

    Best regards,

    Marte

Related