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
  • Hello Mazis,

    did you have to modify something in power config? Because I had to add

    #define ZB_ZCL_CLUSTER_ID_POWER_CONFIG_SERVER_ROLE_INIT ((zb_zcl_cluster_init_t)NULL)

    at the end of the zb_zcl_power_config,h

    Otherwise it won't compile.


    But I still can't read or report the battery voltage. Is there something special I have to set in main.c in the Zigbee Device Callback?

    Thanks

    Krystof

Reply
  • Hello Mazis,

    did you have to modify something in power config? Because I had to add

    #define ZB_ZCL_CLUSTER_ID_POWER_CONFIG_SERVER_ROLE_INIT ((zb_zcl_cluster_init_t)NULL)

    at the end of the zb_zcl_power_config,h

    Otherwise it won't compile.


    But I still can't read or report the battery voltage. Is there something special I have to set in main.c in the Zigbee Device Callback?

    Thanks

    Krystof

Children
  • Hello!

    I didn't changed the #define line you are saying... I have that line as follows:

    zb_void_t zb_zcl_power_config_init_server(void);
    zb_void_t zb_zcl_power_config_init_client(void);
    #define ZB_ZCL_CLUSTER_ID_POWER_CONFIG_SERVER_ROLE_INIT zb_zcl_power_config_init_server
    #define ZB_ZCL_CLUSTER_ID_POWER_CONFIG_CLIENT_ROLE_INIT zb_zcl_power_config_init_client

    About the battery report. If you look the Zigbee reference, (I think that) the only reportable attribute is the remaining battery percentage. I don't know which coordinator are you using but to enable attribute reporting in mine, I had to bind and cofigure reporting for that attribute. If you are using the CLI example, the documentation is pretty good, I would take a look at it. What I do in my code to get the report of the attribute is this:

        UNUSED_RETURN_VALUE(zb_zcl_set_attr_val(MY_DOOR_LOCK_ENDPOINT,
                                                ZB_ZCL_CLUSTER_ID_DOOR_LOCK,
                                                ZB_ZCL_CLUSTER_SERVER_ROLE,
                                                ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID,
                                                &batteryLevel,
                                                ZB_FALSE));

    I hope this helps!

  • Hello Mazis,

    Thanks for reply, I was trying to get the reporting to work for almost a week now. 

    I got myself second nrf52840 DK now, so I use the CLI example on that. 

    I can already see the power config in the device cluster list in CLI coordinator

    But I can't set the battery remaining value. It always gives me error 135 which is invalid Value

    I am trying to set value 0x64 which is 100 which should correspond to 50% of battery.

    6087.zb_ha_window_covering.h

    zb_zcl_power_config.h

    zb_zcl_window_covering.h

    Here are my files, could you maybe take a look? How do yours zb_zcl_power_config.h, zb_zcl_door_lock.h and zb_ha_door_lock.h files look like?

    Here is my implemenation in main.c:

        battery_percentage = 0x64;
        zcl_status = zb_zcl_set_attr_val(HA_WINDOW_COVERING_ENDPOINT,
                                         ZB_ZCL_CLUSTER_ID_POWER_CONFIG, 
                                         ZB_ZCL_CLUSTER_SERVER_ROLE, 
                                         ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID,
                                         &battery_percentage, 
                                         ZB_FALSE);
        if(zcl_status != ZB_ZCL_STATUS_SUCCESS)
        {
            NRF_LOG_INFO("Set battery remaining percentage value fail. zcl_status: %d,", zcl_status);
        }

    in zcl_device_cb so when I send a command to the device it reports me battery.

    battery_percentage here is type zb_uint8_t.

    Thank you!

    Best regards,

    Krystof Vydra

     

  • Hi Krystof!

    I am so sorry but I didn't find anything wrong in your code... All the sensible code is modified, and it looks correct to me. The 0x64 is valid, and the attribute type indeed, is zb_uint8_t.

    The only things that I think might be wrong are:

    - The number of ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM or ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM might be wrong. Take a look and change them if necessary.

    - I also had a issue declaring the cluster. I had to use the extended Macro to declare the attribute list of the power config. Are you using
    ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT?

    - When I wwas reviewing your code I found what might be a bug in my code. When you call zb_zcl_set_attr_val() and give it the ZB_ZCL_CLUSTER_ID_POWER_CONFIG as parameter, can you try to use the corresponding CLUSTER_ID for the window covering? Just like I am doing, although it seems wrong in my code.

    - I would also try setting any other attribute to see if the problem is the parameters you are giving to the function zb_zcl_set_attr_val(). I would also change the cluster.

    I hope this helps...
    Cheers!

Related