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

Zigbee application structure to write attribute and bind on remote Zigbee node

Hi , I am making a zigbee application to write attribute on remote node. Please share the application structure to implement writing functionality of attribute on remote node.

  • Hi,

    You can use command 'zcl attr write' in the Zigbee CLI example to write to an attribute on a remote node. Take a look into the source code of the example to see how the 'zcl attr write' command is implemented.

    Best regards,

    Marjeris

  • Sorry for late reply . I have seen cli example and used it to successfully write attribute to remote node. Cli example uses function pasted below to implement write attribute functionality. Please guide me about using that function from source code. Any help would be appreciated .

    Best regards,

    Ahmed

    /**@brief Write the attribute value to the remote node.
    *
    * @code
    * zcl attr write <h:dst_addr> <d:ep> <h:cluster> <h:profile> <h:attr_id> <h:attr_type> <h:attr_value>
    * @endcode
    *
    * Write the `attr_value` value of the attribute `attr_id` of the type
    * `attr_type` in the cluster `cluster`. The cluster belongs to the profile
    * `profile`, which resides on the endpoint `ep` of the remote node `dst_addr`.
    *
    * @note The `attr_value` value must be in hexadecimal format, unless it is a
    * string (`attr_type == 42`), then it must be a string.
    *
    */
    void cmd_zb_writeattr(nrf_cli_t const * p_cli, size_t argc, char **argv)
    {
    zb_ret_t zb_err_code;
    zb_int8_t row = get_free_row_attr_table();

    if (nrf_cli_help_requested(p_cli))
    {
    nrf_cli_help_print(p_cli, NULL, 0);
    nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, " h: is for hex, d: is for decimal, -c switches the server-to-client direction\r\n");
    nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, " writeattr <h:dst_addr> <d:ep> <h:cluster> [-c] ");
    nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "<h:profile> <h:attr ID> <h:attr type> ");
    nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "<h:attr value>\r\n");
    return;
    }

    bool is_direction_present = ((argc == 9) && !strcmp(argv[4], "-c"));

    if (argc != 8 && !is_direction_present)
    {
    print_error(p_cli, "Wrong number of arguments", ZB_FALSE);
    return;
    }

    if (row == -1)
    {
    print_error(p_cli, "Request pool empty - wait a bit", ZB_FALSE);
    return;
    }

    attr_query_t * p_row = &(m_attr_table[row]);

    p_row->remote_addr_mode = parse_address(*(++argv), &(p_row->remote_node), ADDR_ANY);
    if (p_row->remote_addr_mode == ADDR_INVALID)
    {
    print_error(p_cli, "Invalid address", ZB_FALSE);
    return;
    }

    UNUSED_RETURN_VALUE(sscan_uint8(*(++argv), &(p_row->remote_ep)));

    if (!parse_hex_u16(*(++argv), &(p_row->cluster_id)))
    {
    print_error(p_cli, "Invalid cluster id", ZB_FALSE);
    return;
    }

    if (is_direction_present)
    {
    p_row->direction = ZB_ZCL_FRAME_DIRECTION_TO_CLI;
    ++argv;
    }
    else
    {
    p_row->direction = ZB_ZCL_FRAME_DIRECTION_TO_SRV;
    }

    if (!parse_hex_u16(*(++argv), &(p_row->profile_id)))
    {
    print_error(p_cli, "Invalid profile id", ZB_FALSE);
    return;
    }

    if (!parse_hex_u16(*(++argv), &(p_row->attr_id)))
    {
    print_error(p_cli, "Invalid attribute id", ZB_FALSE);
    return;
    }

    if (!parse_hex_u8(*(++argv), &(p_row->attr_type)))
    {
    print_error(p_cli, "Invalid attribute type", ZB_FALSE);
    return;
    }

    uint8_t len = strlen(*(++argv));
    if (p_row->attr_type == ZB_ZCL_ATTR_TYPE_CHAR_STRING)
    {
    p_row->attr_value[0] = len;
    strncpy((zb_char_t*)(p_row->attr_value + 1), *argv, sizeof(p_row->attr_value) - 1);
    }
    else if (!parse_hex_str(*argv, len, p_row->attr_value, sizeof(p_row->attr_value), true))
    {
    print_error(p_cli, "Invalid attribute value", ZB_FALSE);
    return;
    }

    p_row->req_type = ATTR_WRITE_REQUEST;
    p_row->taken = ZB_TRUE;
    /* Put the CLI instance to be used later */
    p_row->p_cli = (nrf_cli_t*)p_cli;

    zb_err_code = zb_buf_get_out_delayed_ext(writeattr_send, row, 0);
    if (zb_err_code != RET_OK)
    {
    print_error(p_cli, "No frame left - wait a bit", ZB_FALSE);
    /* Invalidate row so that we can reuse it */
    invalidate_row(row);
    }
    }

Related