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

How to use Power Config Cluster

Hello Nordic!

I want to control the battery level, and set alarms... I know that there is a cluster callled PowerConfig cluster and I have been reading it, but I acan't figure out how declare it.

I have the following code (it is written in Spanish, sorry):

typedef  struct contexto_alimentacion_s
{
    zb_uint8_t battery_voltage; // Atributo 3.3.2.2.3.1
    zb_uint8_t battery_size; // Atributo 3.3.2.2.4.2
    zb_uint8_t battery_quantity; // Atributo 3.3.2.2.4.4
    zb_uint8_t battery_rated_voltage; // Atributo 3.3.2.2.4.5
    zb_uint8_t battery_alarm_mask; // Atributo 3.3.2.2.4.6
    zb_uint8_t battery_voltage_min_threshold; // Atributo 3.3.2.2.4.7
} contexto_alimentacion_t;

static contexto_alimentacion_t contexto_alimentacion;

ZB_ZCL_DECLARE_POWER_CONFIG_ATTRIB_LIST(lista_atributos_alimentacion,
                                        &contexto_alimentacion.battery_voltage,
                                        &contexto_alimentacion.battery_size,
                                        &contexto_alimentacion.battery_quantity,
                                        &contexto_alimentacion.battery_rated_voltage,
                                        &contexto_alimentacion.battery_alarm_mask,
                                        &contexto_alimentacion.battery_voltage_min_threshold);

This is part of a bigger code which is using doorlock cluster too. Ithink that I have to use what is asked in this older post, am I right?

Anyway, can someone point me in the right direcction? Where can I find some examples of the Power Config cluster?

Thank you very much!

Parents
  • Finally I made the integration of the Power Config cluster within the Door Lock endpoint. I had to modify a few files, so here is the code (it may help somebody else). Marte, please, if you find some potential errors or improvements, just tell me:

    First of all I used the ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT to declare the attribute list of the Power Config cluster, the other attribute declarations didn't work for me.

    typedef  struct contexto_alimentacion_s
    {
        zb_uint8_t battery_voltage; // Atributo 3.3.2.2.3.1
        zb_uint8_t battery_size; // Atributo 3.3.2.2.4.2
        zb_uint8_t battery_quantity; // Atributo 3.3.2.2.4.4
        zb_uint8_t battery_rated_voltage; // Atributo 3.3.2.2.4.5
        zb_uint8_t battery_alarm_mask; // Atributo 3.3.2.2.4.6
        zb_uint8_t battery_voltage_min_threshold; // Atributo 3.3.2.2.4.7
        zb_uint8_t battery_percentage_remaining; // Atributo 3.3.2.2.3.1
        zb_uint8_t battery_voltage_threshold_1; // Atributo 3.3.2.2.4.8
        zb_uint8_t battery_voltage_threshold_2; // Atributo 3.3.2.2.4.8
        zb_uint8_t battery_voltage_threshold_3; // Atributo 3.3.2.2.4.8
        zb_uint8_t battery_percentage_min_threshold; // Atributo 3.3.2.2.4.9
        zb_uint8_t battery_percentage_threshold_1; // Atributo 3.3.2.2.4.10
        zb_uint8_t battery_percentage_threshold_2; // Atributo 3.3.2.2.4.10
        zb_uint8_t battery_percentage_threshold_3; // Atributo 3.3.2.2.4.10
        zb_uint32_t battery_alarm_state; // Atributo 3.3.2.2.4.11
    } contexto_alimentacion_t;
    
    static contexto_alimentacion_t contexto_alimentacion;
    
    ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(lista_atributos_alimentacion,
                                                        &contexto_alimentacion.battery_voltage,
                                                        &contexto_alimentacion.battery_size,
                                                        &contexto_alimentacion.battery_quantity,
                                                        &contexto_alimentacion.battery_rated_voltage,
                                                        &contexto_alimentacion.battery_alarm_mask,
                                                        &contexto_alimentacion.battery_voltage_min_threshold,
                                                        &contexto_alimentacion.battery_percentage_remaining,
                                                        &contexto_alimentacion.battery_voltage_threshold_1,
                                                        &contexto_alimentacion.battery_voltage_threshold_2,
                                                        &contexto_alimentacion.battery_voltage_threshold_3,
                                                        &contexto_alimentacion.battery_percentage_min_threshold,
                                                        &contexto_alimentacion.battery_percentage_threshold_1,
                                                        &contexto_alimentacion.battery_percentage_threshold_2,
                                                        &contexto_alimentacion.battery_percentage_threshold_3,
                                                        &contexto_alimentacion.battery_alarm_state);

    To declare the cluster within the Door Lock endpoint, I modified the Macro ZB_HA_DECLARE_DOOR_LOCK_CLUSTER_LIST and create my own as follows:

    #define ZB_HA_DECLARE_MY_DOOR_LOCK_CLUSTER_LIST(                      \
          cluster_list_name,                                              \
          door_lock_attr_list,                                            \
          basic_attr_list,                                                \
          identify_attr_list,                                             \
          groups_attr_list,                                               \
          scenes_attr_list,                                               \
          power_config_attr_list)                                         \
          zb_zcl_cluster_desc_t cluster_list_name[] =                     \
          {                                                               \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_IDENTIFY,                                 \
              ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t),       \
              (identify_attr_list),                                       \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_BASIC,                                    \
              ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t),          \
              (basic_attr_list),                                          \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_DOOR_LOCK,                                \
              ZB_ZCL_ARRAY_SIZE(door_lock_attr_list, zb_zcl_attr_t),      \
              (door_lock_attr_list),                                      \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_SCENES,                                   \
              ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t),         \
              (scenes_attr_list),                                         \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_GROUPS,                                   \
              ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t),         \
              (groups_attr_list),                                         \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_POWER_CONFIG,                             \
              ZB_ZCL_ARRAY_SIZE(power_config_attr_list, zb_zcl_attr_t),   \
              (power_config_attr_list),                                   \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            )                                                             \
          } 

    I also had to modify the ZB_ZCL_DECLARE_DOOR_LOCK_SIMPLE_DESC Macro:

    #define ZB_ZCL_DECLARE_DOOR_LOCK_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \
          ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num);                  \
          ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num)  simple_desc_##ep_name = \
          {                                                                     \
            ep_id,                                                              \
            ZB_AF_HA_PROFILE_ID,                                                \
            ZB_HA_DOOR_LOCK_DEVICE_ID,                                          \
            ZB_HA_DEVICE_VER_DOOR_LOCK,                                         \
            0,                                                                  \
            in_clust_num,                                                       \
            out_clust_num,                                                      \
            {                                                                   \
              ZB_ZCL_CLUSTER_ID_BASIC,                                          \
              ZB_ZCL_CLUSTER_ID_IDENTIFY,                                       \
              ZB_ZCL_CLUSTER_ID_DOOR_LOCK,                                      \
              ZB_ZCL_CLUSTER_ID_SCENES,                                         \
              ZB_ZCL_CLUSTER_ID_GROUPS,                                         \
              ZB_ZCL_CLUSTER_ID_POWER_CONFIG                                    \
            }                                                                   \
          }
    

    Another important change to be made is to update the ZB_HA_DOOR_LOCK_IN_CLUSTER_NUM parameter. Because we are adding a new cluster, we have to increase the number of clusters according to the new clusters added.

Reply
  • Finally I made the integration of the Power Config cluster within the Door Lock endpoint. I had to modify a few files, so here is the code (it may help somebody else). Marte, please, if you find some potential errors or improvements, just tell me:

    First of all I used the ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT to declare the attribute list of the Power Config cluster, the other attribute declarations didn't work for me.

    typedef  struct contexto_alimentacion_s
    {
        zb_uint8_t battery_voltage; // Atributo 3.3.2.2.3.1
        zb_uint8_t battery_size; // Atributo 3.3.2.2.4.2
        zb_uint8_t battery_quantity; // Atributo 3.3.2.2.4.4
        zb_uint8_t battery_rated_voltage; // Atributo 3.3.2.2.4.5
        zb_uint8_t battery_alarm_mask; // Atributo 3.3.2.2.4.6
        zb_uint8_t battery_voltage_min_threshold; // Atributo 3.3.2.2.4.7
        zb_uint8_t battery_percentage_remaining; // Atributo 3.3.2.2.3.1
        zb_uint8_t battery_voltage_threshold_1; // Atributo 3.3.2.2.4.8
        zb_uint8_t battery_voltage_threshold_2; // Atributo 3.3.2.2.4.8
        zb_uint8_t battery_voltage_threshold_3; // Atributo 3.3.2.2.4.8
        zb_uint8_t battery_percentage_min_threshold; // Atributo 3.3.2.2.4.9
        zb_uint8_t battery_percentage_threshold_1; // Atributo 3.3.2.2.4.10
        zb_uint8_t battery_percentage_threshold_2; // Atributo 3.3.2.2.4.10
        zb_uint8_t battery_percentage_threshold_3; // Atributo 3.3.2.2.4.10
        zb_uint32_t battery_alarm_state; // Atributo 3.3.2.2.4.11
    } contexto_alimentacion_t;
    
    static contexto_alimentacion_t contexto_alimentacion;
    
    ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(lista_atributos_alimentacion,
                                                        &contexto_alimentacion.battery_voltage,
                                                        &contexto_alimentacion.battery_size,
                                                        &contexto_alimentacion.battery_quantity,
                                                        &contexto_alimentacion.battery_rated_voltage,
                                                        &contexto_alimentacion.battery_alarm_mask,
                                                        &contexto_alimentacion.battery_voltage_min_threshold,
                                                        &contexto_alimentacion.battery_percentage_remaining,
                                                        &contexto_alimentacion.battery_voltage_threshold_1,
                                                        &contexto_alimentacion.battery_voltage_threshold_2,
                                                        &contexto_alimentacion.battery_voltage_threshold_3,
                                                        &contexto_alimentacion.battery_percentage_min_threshold,
                                                        &contexto_alimentacion.battery_percentage_threshold_1,
                                                        &contexto_alimentacion.battery_percentage_threshold_2,
                                                        &contexto_alimentacion.battery_percentage_threshold_3,
                                                        &contexto_alimentacion.battery_alarm_state);

    To declare the cluster within the Door Lock endpoint, I modified the Macro ZB_HA_DECLARE_DOOR_LOCK_CLUSTER_LIST and create my own as follows:

    #define ZB_HA_DECLARE_MY_DOOR_LOCK_CLUSTER_LIST(                      \
          cluster_list_name,                                              \
          door_lock_attr_list,                                            \
          basic_attr_list,                                                \
          identify_attr_list,                                             \
          groups_attr_list,                                               \
          scenes_attr_list,                                               \
          power_config_attr_list)                                         \
          zb_zcl_cluster_desc_t cluster_list_name[] =                     \
          {                                                               \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_IDENTIFY,                                 \
              ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t),       \
              (identify_attr_list),                                       \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_BASIC,                                    \
              ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t),          \
              (basic_attr_list),                                          \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_DOOR_LOCK,                                \
              ZB_ZCL_ARRAY_SIZE(door_lock_attr_list, zb_zcl_attr_t),      \
              (door_lock_attr_list),                                      \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_SCENES,                                   \
              ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t),         \
              (scenes_attr_list),                                         \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_GROUPS,                                   \
              ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t),         \
              (groups_attr_list),                                         \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            ),                                                            \
            ZB_ZCL_CLUSTER_DESC(                                          \
              ZB_ZCL_CLUSTER_ID_POWER_CONFIG,                             \
              ZB_ZCL_ARRAY_SIZE(power_config_attr_list, zb_zcl_attr_t),   \
              (power_config_attr_list),                                   \
              ZB_ZCL_CLUSTER_SERVER_ROLE,                                 \
              ZB_ZCL_MANUF_CODE_INVALID                                   \
            )                                                             \
          } 

    I also had to modify the ZB_ZCL_DECLARE_DOOR_LOCK_SIMPLE_DESC Macro:

    #define ZB_ZCL_DECLARE_DOOR_LOCK_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \
          ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num);                  \
          ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num)  simple_desc_##ep_name = \
          {                                                                     \
            ep_id,                                                              \
            ZB_AF_HA_PROFILE_ID,                                                \
            ZB_HA_DOOR_LOCK_DEVICE_ID,                                          \
            ZB_HA_DEVICE_VER_DOOR_LOCK,                                         \
            0,                                                                  \
            in_clust_num,                                                       \
            out_clust_num,                                                      \
            {                                                                   \
              ZB_ZCL_CLUSTER_ID_BASIC,                                          \
              ZB_ZCL_CLUSTER_ID_IDENTIFY,                                       \
              ZB_ZCL_CLUSTER_ID_DOOR_LOCK,                                      \
              ZB_ZCL_CLUSTER_ID_SCENES,                                         \
              ZB_ZCL_CLUSTER_ID_GROUPS,                                         \
              ZB_ZCL_CLUSTER_ID_POWER_CONFIG                                    \
            }                                                                   \
          }
    

    Another important change to be made is to update the ZB_HA_DOOR_LOCK_IN_CLUSTER_NUM parameter. Because we are adding a new cluster, we have to increase the number of clusters according to the new clusters added.

Children
Related