Default handler doesn't relay set color command

Hi,

I have an nrf52833-dk and adapted the light_bulb example in order to handle two endpoints. The second endpoint is a copy from the first and the same as in the light_bulb example. When I send a level control command everything works as expected and the default handler relays the information to the zcl_device_cb function. However with the color command this does not happen. For debugging purposes I temporarily created a custom endpoint handler and looked at the command that is received by the device: 

This is the command that is not relayed to the zcl_device_cb function by the default handler. Is this standard behaviour?

Parents
  • Have you implemented the Color control cluster at the endpoint you are sending this packet to? 

    Light Bulb example doesn’t implement it by default.

    If ZCL command targets cluster that does not present at the endpoint, the ZCL device callback will not be called - Zigbee stack doesn’t process this frame further (similarly to receiving command that targets endpoint that is not present at the device). If you want to have Color cluster functionality at the given endpoint, you should add Color cluster to the endpoint, then the stack will process Color cluster command and inform application about any change in value of Color cluster’s attributes via ZCL device callback.

    If you want to receive callback for every ZCL command that is received at the endpoint, you should register an endpoint handler for given endpoint.

  • Yes I did implement the color control cluster. My Cluster declaration looks as follows:

    typedef struct {
        zb_zcl_basic_attrs_ext_t basic_attr;
        zb_zcl_identify_attrs_t identify_attr;
        zb_zcl_scenes_attrs_t scenes_attr;
        zb_zcl_groups_attrs_t groups_attr;
        zb_zcl_on_off_attrs_t on_off_attr;
        zb_zcl_level_control_attrs_t level_control_attr;
        zb_zcl_color_control_attrs_ext_t color_control_attr_ext;
        uint8_t level_control_options;
        uint8_t level_control_startup_level;
        uint8_t level_control_move_status;
    
    } bulb_device_ctx_t;
    
    /* Zigbee device application context storage. */
    static bulb_device_ctx_t dev_ctx;
    static bulb_device_ctx_t dev_ctx_2;
    
    
    ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(
            identify_attr_list,
            &dev_ctx.identify_attr.identify_time);
    
    ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(
            identify_attr_list_2,
            &dev_ctx_2.identify_attr.identify_time);
    
    ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(
            groups_attr_list,
            &dev_ctx.groups_attr.name_support);
    
    ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(
            groups_attr_list_2,
            &dev_ctx_2.groups_attr.name_support);
    
    ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST(
            scenes_attr_list,
            &dev_ctx.scenes_attr.scene_count,
            &dev_ctx.scenes_attr.current_scene,
            &dev_ctx.scenes_attr.current_group,
            &dev_ctx.scenes_attr.scene_valid,
            &dev_ctx.scenes_attr.name_support);
    
    ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST(
            scenes_attr_list_2,
            &dev_ctx_2.scenes_attr.scene_count,
            &dev_ctx_2.scenes_attr.current_scene,
            &dev_ctx_2.scenes_attr.current_group,
            &dev_ctx_2.scenes_attr.scene_valid,
            &dev_ctx_2.scenes_attr.name_support);
    
    ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST_EXT(
            basic_attr_list,
            &dev_ctx.basic_attr.zcl_version,
            &dev_ctx.basic_attr.app_version,
            &dev_ctx.basic_attr.stack_version,
            &dev_ctx.basic_attr.hw_version,
            dev_ctx.basic_attr.mf_name,
            dev_ctx.basic_attr.model_id,
            dev_ctx.basic_attr.date_code,
            &dev_ctx.basic_attr.power_source,
            dev_ctx.basic_attr.location_id,
            &dev_ctx.basic_attr.ph_env,
            dev_ctx.basic_attr.sw_ver);
    
    ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST_EXT(
            basic_attr_list_2,
            &dev_ctx_2.basic_attr.zcl_version,
            &dev_ctx_2.basic_attr.app_version,
            &dev_ctx_2.basic_attr.stack_version,
            &dev_ctx_2.basic_attr.hw_version,
            dev_ctx_2.basic_attr.mf_name,
            dev_ctx_2.basic_attr.model_id,
            dev_ctx_2.basic_attr.date_code,
            &dev_ctx_2.basic_attr.power_source,
            dev_ctx_2.basic_attr.location_id,
            &dev_ctx_2.basic_attr.ph_env,
            dev_ctx_2.basic_attr.sw_ver);
    
    /* On/Off cluster attributes additions data */
    ZB_ZCL_DECLARE_ON_OFF_ATTRIB_LIST(
            on_off_attr_list,
            &dev_ctx.on_off_attr.on_off);
    
    ZB_ZCL_DECLARE_ON_OFF_ATTRIB_LIST(
            on_off_attr_list_2,
            &dev_ctx_2.on_off_attr.on_off);
    
    ZB_ZCL_DECLARE_LEVEL_CONTROL_ATTRIB_LIST_EXT(
            level_control_attr_list,
            &dev_ctx.level_control_attr.current_level,
            &dev_ctx.level_control_attr.remaining_time,
            &dev_ctx.level_control_startup_level,
            &dev_ctx.level_control_options);
    
    ZB_ZCL_DECLARE_LEVEL_CONTROL_ATTRIB_LIST_EXT(
            level_control_attr_list_2,
            &dev_ctx_2.level_control_attr.current_level,
            &dev_ctx_2.level_control_attr.remaining_time,
            &dev_ctx_2.level_control_startup_level,
            &dev_ctx_2.level_control_options);
    
    ZB_ZCL_DECLARE_COLOR_CONTROL_ATTRIB_LIST_EXT(
            color_control_attr_list_ext,
            &dev_ctx.color_control_attr_ext.set_color_info.current_hue,
            &dev_ctx.color_control_attr_ext.set_color_info.current_saturation,
            &dev_ctx.color_control_attr_ext.set_color_info.remaining_time,
            &dev_ctx.color_control_attr_ext.set_color_info.current_X,
            &dev_ctx.color_control_attr_ext.set_color_info.current_Y,
            &dev_ctx.color_control_attr_ext.set_color_info.color_temperature,
            &dev_ctx.color_control_attr_ext.set_color_info.color_mode,
            &dev_ctx.color_control_attr_ext.set_color_info.options,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.number_primaries,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_1_X,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_1_Y,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_1_intensity,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_2_X,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_2_Y,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_2_intensity,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_3_X,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_3_Y,
            &dev_ctx.color_control_attr_ext.set_defined_primaries_info.primary_3_intensity,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_4_X,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_4_Y,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_4_intensity,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_5_X,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_5_Y,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_5_intensity,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_6_X,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_6_Y,
            &dev_ctx.color_control_attr_ext.set_additional_defined_primaries_info.primary_6_intensity,
            &dev_ctx.color_control_attr_ext.set_color_info.enhanced_current_hue,
            &dev_ctx.color_control_attr_ext.set_color_info.enhanced_color_mode,
            &dev_ctx.color_control_attr_ext.set_color_info.color_loop_active,
            &dev_ctx.color_control_attr_ext.set_color_info.color_loop_direction,
            &dev_ctx.color_control_attr_ext.set_color_info.color_loop_time,
            &dev_ctx.color_control_attr_ext.set_color_info.color_loop_start_enhanced_hue,
            &dev_ctx.color_control_attr_ext.set_color_info.color_loop_stored_enhanced_hue,
            &dev_ctx.color_control_attr_ext.set_color_info.color_capabilities,
            &dev_ctx.color_control_attr_ext.set_color_info.color_temp_physical_min_mireds,
            &dev_ctx.color_control_attr_ext.set_color_info.color_temp_physical_max_mireds,
            &dev_ctx.color_control_attr_ext.set_color_info.couple_color_temp_to_level_min_mireds,
            &dev_ctx.color_control_attr_ext.set_color_info.start_up_color_temp_mireds);
    
    ZB_ZCL_DECLARE_COLOR_CONTROL_ATTRIB_LIST_EXT(
            color_control_attr_list_ext_2,
            &dev_ctx_2.color_control_attr_ext.set_color_info.current_hue,
            &dev_ctx_2.color_control_attr_ext.set_color_info.current_saturation,
            &dev_ctx_2.color_control_attr_ext.set_color_info.remaining_time,
            &dev_ctx_2.color_control_attr_ext.set_color_info.current_X,
            &dev_ctx_2.color_control_attr_ext.set_color_info.current_Y,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_temperature,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_mode,
            &dev_ctx_2.color_control_attr_ext.set_color_info.options,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.number_primaries,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_1_X,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_1_Y,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_1_intensity,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_2_X,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_2_Y,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_2_intensity,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_3_X,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_3_Y,
            &dev_ctx_2.color_control_attr_ext.set_defined_primaries_info.primary_3_intensity,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_4_X,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_4_Y,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_4_intensity,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_5_X,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_5_Y,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_5_intensity,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_6_X,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_6_Y,
            &dev_ctx_2.color_control_attr_ext.set_additional_defined_primaries_info.primary_6_intensity,
            &dev_ctx_2.color_control_attr_ext.set_color_info.enhanced_current_hue,
            &dev_ctx_2.color_control_attr_ext.set_color_info.enhanced_color_mode,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_loop_active,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_loop_direction,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_loop_time,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_loop_start_enhanced_hue,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_loop_stored_enhanced_hue,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_capabilities,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_temp_physical_min_mireds,
            &dev_ctx_2.color_control_attr_ext.set_color_info.color_temp_physical_max_mireds,
            &dev_ctx_2.color_control_attr_ext.set_color_info.couple_color_temp_to_level_min_mireds,
            &dev_ctx_2.color_control_attr_ext.set_color_info.start_up_color_temp_mireds);
    ZB_DECLARE_DIMMABLE_LIGHT_CLUSTER_LIST(
            dimmable_light_clusters,
            basic_attr_list,
            identify_attr_list,
            groups_attr_list,
            scenes_attr_list,
            on_off_attr_list,
            level_control_attr_list,
            color_control_attr_list_ext);
    
    ZB_DECLARE_DIMMABLE_LIGHT_CLUSTER_LIST(
            dimmable_light_clusters_2,
            basic_attr_list_2,
            identify_attr_list_2,
            groups_attr_list_2,
            scenes_attr_list_2,
            on_off_attr_list_2,
            level_control_attr_list_2,
            color_control_attr_list_ext_2);
    
    ZB_DECLARE_DIMMABLE_LIGHT_EP(
            dimmable_light_ep,
            DIMMABLE_LIGHT_ENDPOINT,
            dimmable_light_clusters);
    
    ZB_DECLARE_DIMMABLE_LIGHT_EP(
            dimmable_light_ep_2,
            DIMMABLE_LIGHT_ENDPOINT_2,
            dimmable_light_clusters_2);
    
    ZBOSS_DECLARE_DEVICE_CTX_2_EP(
            dimmable_light_ctx,
            dimmable_light_ep,
            dimmable_light_ep_2);

    Then I initialize the color capabilities with 

        dev_ctx.color_control_attr_ext.set_color_info.color_capabilities = ZB_ZCL_COLOR_CONTROL_CAPABILITIES_X_Y;
        ZB_ZCL_SET_ATTRIBUTE(
                DIMMABLE_LIGHT_ENDPOINT,
                ZB_ZCL_CLUSTER_ID_COLOR_CONTROL,
                ZB_ZCL_CLUSTER_SERVER_ROLE,
                ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID,
                (zb_uint16_t *) &dev_ctx.color_control_attr_ext.set_color_info.color_capabilities,
                ZB_FALSE);
    
        dev_ctx_2.color_control_attr_ext.set_color_info.color_capabilities = ZB_ZCL_COLOR_CONTROL_CAPABILITIES_X_Y;
        ZB_ZCL_SET_ATTRIBUTE(
                DIMMABLE_LIGHT_ENDPOINT_2,
                ZB_ZCL_CLUSTER_ID_COLOR_CONTROL,
                ZB_ZCL_CLUSTER_SERVER_ROLE,
                ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID,
                (zb_uint16_t *) &dev_ctx_2.color_control_attr_ext.set_color_info.color_capabilities,
                ZB_FALSE);
    

    I did some further tests and I realized when I initialize the color capabilities of both endpoints then only the second enpoint relays the command to zcl_device_cb. When I initialize only the first endpoints color capabilities, then only the first endpoint relays the command to zcl_device_cb. But never both endpoints relay their color control command. What is the reason for this?

  • Hi,

    What are you using to send the color control command to the device? Are you sending it to both endpoints?

    Best regards,
    Marte

  • I am using zigbee2mqtt with a sonoff dongle. I am sending one color control command at a time to one endpoint at a time. The exact package that is received by the device can be seen in the original post. My guess is that something is not initialized correctly so the default handler ignores the package. However I think I only need to initialize the color_capabilities, is that correct?

    Also, the behaviour that the default handler only relays the package from either endpoint 1 or 2 depending if I initialized only one or both endpoints seems very strange to me.

Reply
  • I am using zigbee2mqtt with a sonoff dongle. I am sending one color control command at a time to one endpoint at a time. The exact package that is received by the device can be seen in the original post. My guess is that something is not initialized correctly so the default handler ignores the package. However I think I only need to initialize the color_capabilities, is that correct?

    Also, the behaviour that the default handler only relays the package from either endpoint 1 or 2 depending if I initialized only one or both endpoints seems very strange to me.

Children
  • Hi,

    It looks like you are doing it correct based on the code you have shared here. The handler should work for both endpoints when they are both initialized.

    Can you share your project so I can reproduce the problem on my side?

    Best regards,
    Marte

  • Here is the example project. It creates two endpoints with the numbers 1 and 2. The "move to color" command is only relayed to the second endpoint in this example. The initialisation of the color control capabilities are found on line 761-777 in main.c. I am running this example with the nRF52833-DK.

    light_bulb_2_endpoints.zip

  • Hi,

    Thank you for sharing the project.

    I did some testing and for Level Control, zcl_device_cb is ony called when sending commands with On/Off. So you must send "Step (with On/Off)"  (command ID 0x06) instead of the regular "Step" (command ID 0x02) command. 

    As for Color Control, the command and zcl_device_cb worked as expected for both endpoints. I used Zigbee shell to test it and sent the Move to Color command with the following:

    zcl cmd 0xff10 1 0x0300 0x07 -l 0000aaaa0200

    This is what the payload of the packet looked like:

    As you can see from the log, zcl_device_cb was called for both endpoints:

    If the payload of the command was incorrect or the color values were outside the valid range, it did not enter zcl_device_cb. This might be what the issue is in your case, since I did not make any changes to your code.
    If you get a sniffer log, you should be able to see if the payload is correct or not. If it is incorrect, the device will send a Default Response packet with the status field showing the problem, similar to this:

    Best regards,
    Marte

  • Thanks to your help I was able to debug it further. When I send a single "move to color" command at either endpoint, everything works as expected. So I have the same behaviour as you. However if I send two commands in a very short amount of time, then only the second command will be relayed to zcl_device_cb. Important note: the color for the first endpoint is different from the command before.

    The commands that are being sent:

    The first and the second "move to color" command in detail:

    The first and second response:

    Moreover I did implement a test handler for both endpoints with:

    ZB_AF_SET_ENDPOINT_HANDLER(DIMMABLE_LIGHT_ENDPOINT, test_handler);
    ZB_AF_SET_ENDPOINT_HANDLER(DIMMABLE_LIGHT_ENDPOINT_2, test_handler);

    and 

    zb_uint8_t test_handler(zb_uint8_t param) {
        LOG_INF("test handler reached");
        zb_bufid_t zcl_cmd_buf = param;
        volatile zb_zcl_parsed_hdr_t *cmd_info = ZB_BUF_GET_PARAM(zcl_cmd_buf, zb_zcl_parsed_hdr_t);
        LOG_INF("destination endpoint: %d", cmd_info->addr_data.common_data.dst_endpoint);
        return 0;
    };

    Now I can see that when I send two endpoints in a short sequence my test_handler gets called two times, one for each endpoint. However, only the second command also gets relayed to the default handler as well. The package that does not get relayed can be seen in the original post.

  • Hi,

    I have asked the development team about this, and I will update you when I hear back from them.

    Best regards,
    Marte

Related