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

Parsing values from Coordinator to Router

Hello to all,
I have a question about parsing zigbee commands when they present a payload.
I have a Coordinator that implements the Window Controller Device of the HA profile which sends a value to set the tilt percentage:
I send the percentage value to a Window Covering Device through this define "ZB_ZCL_WINDOW_COVERING_SEND_GO_TO_TILT_PERCENTAGE_REQ".
The Window Covering Device correctly detects the message, what I can't do is read the percentage value I sent.
In the Window Covering device I use the define "ZB_ZCL_WINDOW_COVERING_GET_GO_TO_TILT_PERCENTAGE_REQ" to parsing but I never read the value I sent.

Do I have to do any other operations? Have I understood what I have to do?

Best regards,
Raffaela
Parents
  • Hi.

    If you shared your code it would be easier to have a look at this question.

    What status does ZB_ZCL_WINDOW_COVERING_SEND_GO_TO_TILT_PERCENTAGE_REQ return? Are you sure that it returns the correct status?

    /** @brief Parses Get Go to Tilt Percentage command and fills to data request
        structure. If request contains invalid data, -1 is returned as Percentage Tilt Value
        @param data_buf - pointer to zb_buf_t buffer containing command request data
        @param tilt_percentage_req - variable to save command request
        @param status - return ZB_ZCL_PARSE_STATUS_SUCCESS if request contains valid data,
        else ZB_ZCL_PARSE_STATUS_FAILURE
        @note data_buf buffer should contain command request payload without ZCL header.
    */


    Have you remembered this:
    @note data_buf buffer should contain command request payload without ZCL header.

    Best regards,
    Andreas

  • Hi Andreas,

    The code that I wrote is the following:

    static zb_void_t zcl_device_cb(zb_uint8_t param)
    {
        zb_uint8_t                       cluster_id;
        zb_uint8_t                       attr_id;
        zb_buf_t                       * p_buffer = (zb_buf_t *)ZB_BUF_FROM_REF(param);
    
        zb_zcl_device_callback_param_t * p_device_cb_param =
                         ZB_GET_BUF_PARAM(p_buffer, zb_zcl_device_callback_param_t);
    
        NRF_LOG_INFO("zcl_device_cb id %hd", p_device_cb_param->device_cb_id);
        zb_zcl_go_to_tilt_percentage_req_t* tilt_percentage_req;
        volatile zb_zcl_parse_status_t status;
        static volatile zb_uint16_t perc;
        /* Set default response value. */
        p_device_cb_param->status = RET_OK;
    
        switch (p_device_cb_param->device_cb_id)
        {
            case ZB_ZCL_WINDOW_COVERING_UP_OPEN_CB_ID:
                 bsp_board_led_on(BULB_LED);
                 break;
            
            case ZB_ZCL_WINDOW_COVERING_DOWN_CLOSE_CB_ID:
                 bsp_board_led_on(BULB_LED);
                 break;
    
            case ZB_ZCL_WINDOW_COVERING_STOP_CB_ID:
                 bsp_board_led_off(BULB_LED);
                 break;
    
            case ZB_ZCL_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE_CB_ID:
                 bsp_board_led_on(BULB_LED);
                 ZB_ZCL_WINDOW_COVERING_GET_GO_TO_TILT_PERCENTAGE_REQ(p_buffer, tilt_percentage_req, status);
                 perc=&(*tilt_percentage_req).percentage_tilt_value;
                 counter++;
                 break;
    
            default:
                p_device_cb_param->status = RET_ERROR;
                break;
        }
    
        NRF_LOG_INFO("zcl_device_cb status: %hd", p_device_cb_param->status);
    }

    I'm not sure that the data_buf that I'm passing to the "ZB_ZCL_WINDOW_COVERING_SEND_GO_TO_TILT_PERCENTAGE_REQ" is the buffer without header.

    Thank you for your time and best regards,

    Raffaela

  • Hi.

    Could you clarify what you try to do with this line?

                 perc=&(*tilt_percentage_req).percentage_tilt_value;

    *tilt_percentage_req returns a structure.
    (*tilt_percentage_req).percentage_tilt_value returns perentage_tile_value.
    &(*tilt_percentage_req).percentage_tilt_value returns the address of the percentage_tilt_value.

    Also, what is printed when you run this?
    What does the line:

    NRF_LOG_INFO("zcl_device_cb status: %hd", p_device_cb_param->status);

    print?

    Best regards,

    Andreas

  • Sorry, 

    These lines of code are not important for my questions, there are a mistake; the problem is the define that doesn't woks, o better, I haven't idea how to obtain the zcl payload to pass to the define. Can you help with this problem?

    Thank you, 

    Raffaela

  • Hi Raffaela.

    When using ZB_ZCL_WINDOW_COVERING_SEND_GO_TO_TILT_PERCENTAGE_REQ check status, it will tell if something is parsed correctly or not.
    For ZCL callback parse param as zb_zcl_device_callback_param_t, see ble_zigbee_dynamic_light_bulb_eddystone as an example.


    For callback ids see documentation (it should tell what if anything is returned with callback), as for ZB_ZCL_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE_CB_ID, returned value is zb_zcl_go_to_tilt_percentage_req_t structure (as "in" parameter).


    To get pointer to structure, from zb_zcl_device_callback_param_t we need to obtain cb_param (which is union and there is no type corresponding to window covering), so you need to use generic one: "zb_zcl_device_cmd_generic_param_t gnr")

    The macro "ZB_ZCL_DEVICE_CMD_PARAM_IN_GET" can be used to obtain pointer, we need to obtain "in" pointer, because as previously mentioned "returned value is zb_zcl_go_to_tilt_percentage_req_t structure (as "in" parameter)"

    Best regards,

    Andreas

  • Hi Andreas, 

    Thank you so much, finally I took the value of tilt percentage. 

    My new question is related to the writing of this value in the correct attribute, ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID. Like the others examples, I created a struct like this:

    typedef struct
    {
        zb_uint8_t  window_covering_type;
        zb_uint8_t  config_status;
        zb_uint8_t  current_position_lift_percentage;
        zb_uint8_t  current_position_tilt_percentage;
        zb_uint16_t installed_open_limit_lift;
        zb_uint16_t installed_closed_limit_lift;
        zb_uint16_t installed_open_limit_tilt;
        zb_uint16_t installed_closed_limit_tilt;
        zb_uint8_t  attr_mode;
    } window_cov_device_window_cov_attr_t;
    

    This struct is then inserted into the following define: ZB_ZCL_DECLARE_WINDOW_COVERING_CLUSTER_ATTRIB_LIST.

    After I made the init of this cluster and I did this:

    m_dev_ctx.window_covering_attr.current_position_tilt_percentage = 0x00;
    
    ZB_ZCL_SET_ATTRIBUTE(HA_WINDOW_COVERING_ENDPOINT, 
                            ZB_ZCL_CLUSTER_ID_WINDOW_COVERING,    
                            ZB_ZCL_CLUSTER_SERVER_ROLE,  
                            ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID,
                            m_dev_ctx.window_covering_attr.current_position_lift_percentage,                        
                            ZB_TRUE);

    When I set the new value by the coordinator, I want that the new value is written in this position:

    m_dev_ctx.window_covering_attr.current_position_tilt_percentage

    So I call the define that I used before but with the new value:

        ZB_ZCL_SET_ATTRIBUTE(HA_WINDOW_COVERING_ENDPOINT, 
                             ZB_ZCL_CLUSTER_ID_WINDOW_COVERING,    
                             ZB_ZCL_CLUSTER_SERVER_ROLE,  
                             ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID,
                             new_value,                        
                             ZB_TRUE);

    Am I doing anything wrong? Do I have to set some more parameters so that the value is entered?

    Thank you and best regards,

    Raffaela

  • Hi.

    It looks correct, just make sure that the variable "new_value" is a pointer.

    Best regards,

    Andreas

Reply Children
Related