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

ZigBee add Battery measure and report functionality

Hi,

So I am working on a school project with NRF52840 (DK) developing a ZigBee compatible Window Blinds controller (battery powered).

And for that I am using the Window Covering (zb_ha_window_covering.h) HA profile. BUT this profile doesn't include any battery or voltage reporting.

So I am asking HOW and What is the best way to include battery reporting into this code.

I have tried adding the Power Config cluster to zb_ha_window_covering profile, but it gives me an error when compiling. I have no Idea what am I missing out.

here is the main.c:



#include "sdk_config.h"
#include "zboss_api.h"
#include "zboss_api_addons.h"
#include "zb_mem_config_med.h"
#include "zb_ha_dimmable_light.h"

#include "zb_ha_window_covering.h"
#include "zb_zcl_power_config.h"

#include "zb_error_handler.h"
#include "zb_nrf52_internal.h"
#include "zigbee_helpers.h"

#include "bsp.h"
#include "boards.h"
#include "app_timer.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"



#define MAX_CHILDREN                      10                                    /**< The maximum amount of connected devices. Setting this value to 0 disables association to this device.  */
#define IEEE_CHANNEL_MASK                 (1l << ZIGBEE_CHANNEL)                /**< Scan only one, predefined channel to find the coordinator. */
#define HA_WINDOW_COVERING_ENDPOINT        10                                    /**< Device endpoint, used to receive light controlling commands. */
#define ERASE_PERSISTENT_CONFIG           ZB_FALSE                              /**< Do not erase NVRAM to save the network parameters after device reboot or power-off. */


/* Basic cluster attributes initial values. */
#define BULB_INIT_BASIC_APP_VERSION       01                                    /**< Version of the application software (1 byte). */
#define BULB_INIT_BASIC_STACK_VERSION     10                                    /**< Version of the implementation of the Zigbee stack (1 byte). */
#define BULB_INIT_BASIC_HW_VERSION        11                                    /**< Version of the hardware of the device (1 byte). */
#define BULB_INIT_BASIC_MANUF_NAME        "Nordic"                              /**< Manufacturer name (32 bytes). */
#define BULB_INIT_BASIC_MODEL_ID          "Window_Covering_v0.1"                  /**< Model number assigned by manufacturer (32-bytes long string). */
#define BULB_INIT_BASIC_DATE_CODE         "20180416"                            /**< First 8 bytes specify the date of manufacturer of the device in ISO 8601 format (YYYYMMDD). The rest (8 bytes) are manufacturer specific. */
#define BULB_INIT_BASIC_POWER_SOURCE      ZB_ZCL_BASIC_POWER_SOURCE_DC_SOURCE   /**< Type of power sources available for the device. For possible values see section 3.2.2.2.8 of ZCL specification. */
#define BULB_INIT_BASIC_LOCATION_DESC     "Office desk"                         /**< Describes the physical location of the device (16 bytes). May be modified during commisioning process. */
#define BULB_INIT_BASIC_PH_ENV            ZB_ZCL_BASIC_ENV_UNSPECIFIED          /**< Describes the type of physical environment. For possible values see section 3.2.2.2.10 of ZCL specification. */


#define IDENTIFY_MODE_BSP_EVT             BSP_EVENT_KEY_3                       /**< Button event used to enter the Bulb into the Identify mode. */
#define ZIGBEE_NETWORK_STATE_LED          BSP_BOARD_LED_2                       /**< LED indicating that light switch successfully joind Zigbee network. */

#define BULB_LED                          BSP_BOARD_LED_3                       /**< LED immitaing dimmable light bulb. */






#define ZB_HA_DECLARE_WINDOW_COVERING_EP(ep_name, ep_id, cluster_list) \
  ZB_ZCL_DECLARE_WINDOW_COVERING_SIMPLE_DESC(ep_name, ep_id,                      \
    ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM, ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM); \
  ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name,            \
                                     ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT);    \
  ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID,                \
            0,                    \
            NULL,                                \
            ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list,         \
            (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name,                             \
            ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT, reporting_info## device_ctx_name,    \
            0, NULL) /* No CVC ctx */




/******************* Declare attributes ************************/
/* Basic cluster attributes data */



typedef struct
{
    zb_uint8_t voltage;
    zb_uint8_t size;
    zb_uint8_t quantity;
    zb_uint8_t rated_voltage;
    zb_uint8_t alarm_mask;
    zb_uint8_t voltage_min_threshold;
    zb_uint8_t remaining;
    zb_uint8_t threshold1;
    zb_uint8_t threshold2;
    zb_uint8_t threshold3;
    zb_uint8_t min_threshold;
    zb_uint8_t percent_treshold1;
    zb_uint8_t percent_threshold2;
    zb_uint8_t percent_threshold3;
    zb_uint8_t alarm_state;

}zb_zcl_power_config_attrs_t;



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 mode;
}device_window_covering;



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;
    device_window_covering window_covering_attr;
    zb_zcl_power_config_attrs_t power_config_attr;
}window_covering_device_ctx;

static window_covering_device_ctx m_dev_ctx;



ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST_EXT(basic_attr_list,
                                     &m_dev_ctx.basic_attr.zcl_version,
                                     &m_dev_ctx.basic_attr.app_version,
                                     &m_dev_ctx.basic_attr.stack_version,
                                     &m_dev_ctx.basic_attr.hw_version,
                                     m_dev_ctx.basic_attr.mf_name,
                                     m_dev_ctx.basic_attr.model_id,
                                     m_dev_ctx.basic_attr.date_code,
                                     &m_dev_ctx.basic_attr.power_source,
                                     m_dev_ctx.basic_attr.location_id,
                                     &m_dev_ctx.basic_attr.ph_env,
                                     m_dev_ctx.basic_attr.sw_ver);


ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(identify_attr_list, &m_dev_ctx.identify_attr.identify_time);


ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(groups_attr_list, &m_dev_ctx.groups_attr.name_support);


ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST(scenes_attr_list,
                                  &m_dev_ctx.scenes_attr.scene_count,
                                  &m_dev_ctx.scenes_attr.current_scene,
                                  &m_dev_ctx.scenes_attr.current_group,
                                  &m_dev_ctx.scenes_attr.scene_valid,
                                  &m_dev_ctx.scenes_attr.name_support);




ZB_ZCL_DECLARE_WINDOW_COVERING_CLUSTER_ATTRIB_LIST(window_covering_attr_list,
                                                    &m_dev_ctx.window_covering_attr.window_covering_type,
                                                    &m_dev_ctx.window_covering_attr.config_status,
                                                    &m_dev_ctx.window_covering_attr.current_position_lift_percentage,
                                                    &m_dev_ctx.window_covering_attr.current_position_tilt_percentage,
                                                    &m_dev_ctx.window_covering_attr.installed_open_limit_lift,
                                                    &m_dev_ctx.window_covering_attr.installed_closed_limit_lift,
                                                    &m_dev_ctx.window_covering_attr.installed_open_limit_tilt,
                                                    &m_dev_ctx.window_covering_attr.installed_closed_limit_tilt,
                                                    &m_dev_ctx.window_covering_attr.mode);


ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(power_config_attr_list, &m_dev_ctx.power_config_attr.voltage, &m_dev_ctx.power_config_attr.size, &m_dev_ctx.power_config_attr.quantity, &m_dev_ctx.power_config_attr.rated_voltage, &m_dev_ctx.power_config_attr.alarm_mask, &m_dev_ctx.power_config_attr.voltage_min_threshold, &m_dev_ctx.power_config_attr.remaining, &m_dev_ctx.power_config_attr.threshold1, &m_dev_ctx.power_config_attr.threshold2, &m_dev_ctx.power_config_attr.threshold3, &m_dev_ctx.power_config_attr.min_threshold, &m_dev_ctx.power_config_attr.percent_treshold1, &m_dev_ctx.power_config_attr.percent_threshold2, &m_dev_ctx.power_config_attr.percent_threshold3, &m_dev_ctx.power_config_attr.alarm_state);



/********************* Declare device **************************/
ZB_HA_DECLARE_WINDOW_COVERING_CLUSTER_LIST(window_covering_clusters,
                                           basic_attr_list,
                                           identify_attr_list,
                                           groups_attr_list,
                                           scenes_attr_list,
                                           window_covering_attr_list,
                                           power_config_attr_list
                                           );


//ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_IDENTIFY,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);



ZB_HA_DECLARE_WINDOW_COVERING_EP(window_covering_ep, HA_WINDOW_COVERING_ENDPOINT, window_covering_clusters);

ZB_HA_DECLARE_WINDOW_COVERING_CTX(window_covering_ctx, window_covering_ep);




/*********************************************************************/


static void window_covering_clusters_attr_init(void)
{


    m_dev_ctx.basic_attr.zcl_version   = ZB_ZCL_VERSION;
    m_dev_ctx.basic_attr.app_version   = BULB_INIT_BASIC_APP_VERSION;
    m_dev_ctx.basic_attr.stack_version = BULB_INIT_BASIC_STACK_VERSION;
    m_dev_ctx.basic_attr.hw_version    = BULB_INIT_BASIC_HW_VERSION;


    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.mf_name,
                          BULB_INIT_BASIC_MANUF_NAME,
                          ZB_ZCL_STRING_CONST_SIZE(BULB_INIT_BASIC_MANUF_NAME));

    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.model_id,
                          BULB_INIT_BASIC_MODEL_ID,
                          ZB_ZCL_STRING_CONST_SIZE(BULB_INIT_BASIC_MODEL_ID));

    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.date_code,
                          BULB_INIT_BASIC_DATE_CODE,
                          ZB_ZCL_STRING_CONST_SIZE(BULB_INIT_BASIC_DATE_CODE));

    m_dev_ctx.basic_attr.power_source = BULB_INIT_BASIC_POWER_SOURCE;

    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.location_id,
                          BULB_INIT_BASIC_LOCATION_DESC,
                          ZB_ZCL_STRING_CONST_SIZE(BULB_INIT_BASIC_LOCATION_DESC));

    m_dev_ctx.basic_attr.ph_env = BULB_INIT_BASIC_PH_ENV;

    m_dev_ctx.identify_attr.identify_time = ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE;



    m_dev_ctx.groups_attr.name_support = 0;

    m_dev_ctx.window_covering_attr.window_covering_type = ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_TILT_BLIND_TILT_ONLY;
    m_dev_ctx.window_covering_attr.config_status = ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_OPERATIONAL;
    m_dev_ctx.window_covering_attr.current_position_lift_percentage = ZB_ZCL_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_DEFAULT_VALUE;
    m_dev_ctx.window_covering_attr.current_position_tilt_percentage = ZB_ZCL_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_DEFAULT_VALUE;
    m_dev_ctx.window_covering_attr.installed_open_limit_lift = ZB_ZCL_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_LIFT_DEFAULT_VALUE;
    m_dev_ctx.window_covering_attr.installed_closed_limit_lift = ZB_ZCL_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_LIFT_DEFAULT_VALUE;
    m_dev_ctx.window_covering_attr.installed_open_limit_tilt = ZB_ZCL_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_TILT_DEFAULT_VALUE;
    m_dev_ctx.window_covering_attr.installed_closed_limit_tilt = ZB_ZCL_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_TILT_DEFAULT_VALUE;
    m_dev_ctx.window_covering_attr.mode = ZB_ZCL_WINDOW_COVERING_MODE_DEFAULT_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_LIFT_ID, 
                         (zb_uint8_t *)&m_dev_ctx.window_covering_attr.current_position_lift_percentage,                                       
                         ZB_FALSE); 

}





















/**@brief Function for initializing the application timer.
 */
static void timer_init(void)
{
    uint32_t error_code = app_timer_init();
    APP_ERROR_CHECK(error_code);
}

/**@brief Function for initializing the nrf log module.
 */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}




/**@brief Function which tries to sleep down the MCU 
 *
 * Function which sleeps the MCU on the non-sleepy End Devices to optimize the power saving.
 * The weak definition inside the OSIF layer provides some minimal working template
 */
zb_void_t zb_osif_go_idle(zb_void_t)
{
    //TODO: implement your own logic if needed
    zb_osif_wait_for_event();
}


void zboss_signal_handler(zb_bufid_t bufid)
{
    /* Update network status LED */
    //zigbee_led_status_update(bufid, ZIGBEE_NETWORK_STATE_LED);

    /* No application-specific behavior is required. Call default signal handler. */
    ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid));

    if (bufid)
    {
        zb_buf_free(bufid);
    }
}



/*zb_uint8_t zcl_specific_cluster_cmd_handler(zb_uint8_t param)
{
  zb_zcl_parsed_hdr_t cmd_info;
  zb_uint8_t lqi = ZB_MAC_LQI_UNDEFINED;
  zb_int8_t rssi = ZB_MAC_RSSI_UNDEFINED;
  TRACE_MSG(TRACE_APP1, "> zcl_specific_cluster_cmd_handler", (FMT__0));
  ZB_ZCL_COPY_PARSED_HEADER(param, &cmd_info);
  g_dst_addr = ZB_ZCL_PARSED_HDR_SHORT_DATA(&cmd_info).source.u.short_addr;
  ZB_ZCL_DEBUG_DUMP_HEADER(&cmd_info);
  TRACE_MSG(TRACE_APP3, "payload size: %i", (FMT__D, zb_buf_len(param)));
  zb_zdo_get_diag_data(g_dst_addr, &lqi, &rssi);
  TRACE_MSG(TRACE_APP3, "lqi %hd rssi %d", (FMT__H_H, lqi, rssi));
  if (cmd_info.cmd_direction == ZB_ZCL_FRAME_DIRECTION_TO_CLI)
  {
    TRACE_MSG(
        TRACE_ERROR,
        "Unsupported \"from server\" command direction",
        (FMT__0));
  }
  TRACE_MSG(TRACE_APP1, "< zcl_specific_cluster_cmd_handler", (FMT__0));
  return ZB_FALSE;
}
*/


zb_void_t zcl_device_cb(zb_bufid_t bufid)
{
    zb_uint8_t                       cluster_id;
    zb_uint8_t                       attr_id;
    zb_zcl_device_callback_param_t * p_device_cb_param = ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);

    NRF_LOG_INFO("zcl_device_cb id %hd", p_device_cb_param->device_cb_id);
    
    p_device_cb_param->status = RET_OK;

    
    switch (p_device_cb_param->device_cb_id)
    {
      
      
      case ZB_ZCL_WINDOW_COVERING_UP_OPEN_CB_ID:
          NRF_LOG_INFO("OPEN UP");
          //funkce otevri
          break;

      case ZB_ZCL_WINDOW_COVERING_DOWN_CLOSE_CB_ID:
          NRF_LOG_INFO("CLOSE DOWN");
          //funkce zavri
          break;
      
      case ZB_ZCL_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE_CB_ID:
          NRF_LOG_INFO("GO TO TILT PERCENTAGE");
          //funkce naklop
          break;

      default:
            p_device_cb_param->status = RET_ERROR;
            break;
    
    
    }



}



/**@brief Function for application main entry.
 */
int main(void)
{
    zb_ret_t       zb_err_code;
    zb_ieee_addr_t ieee_addr;

    /* Initialize timer, logging system and GPIOs. */
    timer_init();
    log_init();
    

    /* Set Zigbee stack logging level and traffic dump subsystem. */
    ZB_SET_TRACE_LEVEL(ZIGBEE_TRACE_LEVEL);
    ZB_SET_TRACE_MASK(ZIGBEE_TRACE_MASK);
    ZB_SET_TRAF_DUMP_OFF();

    /* Initialize Zigbee stack. */
    ZB_INIT("window_covering");

    /* Set device address to the value read from FICR registers. */
    zb_osif_get_ieee_eui64(ieee_addr);
    zb_set_long_address(ieee_addr);

    /* Set static long IEEE address. */
    zb_set_network_router_role(IEEE_CHANNEL_MASK);
    zb_set_max_children(MAX_CHILDREN);
    zigbee_erase_persistent_storage(ERASE_PERSISTENT_CONFIG);
    zb_set_keepalive_timeout(ZB_MILLISECONDS_TO_BEACON_INTERVAL(3000));

    /* Initialize application context structure. */
    UNUSED_RETURN_VALUE(ZB_MEMSET(&m_dev_ctx, 0, sizeof(m_dev_ctx)));

    /* Register callback for handling ZCL commands. */
    ZB_ZCL_REGISTER_DEVICE_CB(zcl_device_cb);

    /* Register dimmer switch device context (endpoints). */
    //ZB_AF_REGISTER_DEVICE_CTX(&dimmable_light_ctx);
    ZB_AF_REGISTER_DEVICE_CTX(&window_covering_ctx);

    window_covering_clusters_attr_init();

    //ZB_AF_SET_ENDPOINT_HANDLER(HA_WINDOW_COVERING_ENDPOINT, zcl_specific_cluster_cmd_handler);


    //bulb_clusters_attr_init();
    //level_control_set_value(m_dev_ctx.level_control_attr.current_level);



    /** Start Zigbee Stack. */
    zb_err_code = zboss_start_no_autostart();
    ZB_ERROR_CHECK(zb_err_code);

    while(1)
    {
        zboss_main_loop_iteration();
        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());


    }
}


/**
 * @}
 */

Here is also the modified zb_ha_window_covering.h file:

/* ZBOSS Zigbee 3.0
 *
 * Copyright (c) 2012-2018 DSR Corporation, Denver CO, USA.
 * http://www.dsr-zboss.com
 * http://www.dsr-corporation.com
 * All rights reserved.
 *
 *
 * Use in source and binary forms, redistribution in binary form only, with
 * or without modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 2. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 3. This software, with or without modification, must only be used with a Nordic
 *    Semiconductor ASA integrated circuit.
 *
 * 4. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PURPOSE: Window Covering device definition
*/

#if ! defined ZB_HA_WINDOW_COVERING_H
#define ZB_HA_WINDOW_COVERING_H

#if defined ZB_HA_DEFINE_DEVICE_WINDOW_COVERING || defined DOXYGEN

/******************* Specific definitions for window covering device **************************/

/** @cond DOXYGEN_HA_SECTION */

/**
 *  @defgroup ha_window_covering Window Covering
 *  @ingroup ZB_HA_DEVICES
    @{
    @details
    Window Covering device has 5 clusters (see spec 7.6.3): \n
        - @ref ZB_ZCL_IDENTIFY \n
        - @ref ZB_ZCL_BASIC \n
        - @ref ZB_ZCL_WINDOW_COVERING \n
        - @ref ZB_ZCL_SCENES \n
        - @ref ZB_ZCL_GROUPS

    Window Covering device sample

    @par Example
    Declaring clusters
    @snippet doxygen_snippets.dox COMMON_DECLARATION_snippet_ha_window_covering_sample_c
    Registering device list
    @snippet doxygen_snippets.dox REGISTER_snippet_ha_window_covering_sample_c
    Example of command handler
    @snippet doxygen_snippets.dox VARIABLE_snippet_ha_window_covering_sample_c
    @snippet doxygen_snippets.dox HANDLER_snippet_ha_window_covering_sample_c
    @par

    The complete set of Window Covering device samples can be found in /application/HA_samples/window_covering
*/
#define ZB_HA_DEVICE_VER_WINDOW_COVERING 0  /*!< Window covering device version */

/** @cond internals_doc */
#define ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM 5 /*!< Window covering IN (server) clusters number */
#define ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM 0 /*!< Window covering OUT (client) clusters number */

#define ZB_HA_WINDOW_COVERING_CLUSTER_NUM (ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM + \
  ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM)

/*! Number of attribute for reporting on window covering device */
#define ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT         \
  (ZB_ZCL_WINDOW_COVERING_REPORT_ATTR_COUNT)

/** @endcond */

/*!
  @brief Declare cluster list for window covering device
  @param cluster_list_name - cluster list variable name
  @param basic_attr_list - attribute list for Basic cluster
  @param identify_attr_list - attribute list for Identify cluster
  @param groups_attr_list - attribute list for Groups cluster
  @param scenes_attr_list - attribute list for Scenes cluster
  @param window_covering_attr_list - attribute list for Window covering cluster
 */
#define ZB_HA_DECLARE_WINDOW_COVERING_CLUSTER_LIST(                     \
  cluster_list_name,                                                    \
  basic_attr_list,                                                      \
  identify_attr_list,                                                   \
  groups_attr_list,                                                     \
  scenes_attr_list,                                                     \
  window_covering_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_WINDOW_COVERING,                                \
      ZB_ZCL_ARRAY_SIZE(window_covering_attr_list, zb_zcl_attr_t),      \
      (window_covering_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                                         \
    )                                                                   \
  }


/*!
  @brief Declare simple descriptor for window covering device
  @param ep_name - endpoint variable name
  @param ep_id - endpoint ID
  @param in_clust_num - number of supported input clusters
  @param out_clust_num - number of supported output clusters
*/
#define ZB_ZCL_DECLARE_WINDOW_COVERING_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_WINDOW_COVERING_DEVICE_ID,                                                            \
    ZB_HA_DEVICE_VER_WINDOW_COVERING,                                                           \
    0,                                                                                          \
    in_clust_num,                                                                               \
    out_clust_num,                                                                              \
    {                                                                                           \
      ZB_ZCL_CLUSTER_ID_BASIC,                                                                  \
      ZB_ZCL_CLUSTER_ID_IDENTIFY,                                                               \
      ZB_ZCL_CLUSTER_ID_WINDOW_COVERING,                                                        \
      ZB_ZCL_CLUSTER_ID_SCENES,                                                                 \
      ZB_ZCL_CLUSTER_ID_GROUPS,                                                                 \
      ZB_ZCL_CLUSTER_ID_POWER_CONFIG                                                            \
    }                                                                                           \
  }

/*!
  @brief Declare endpoint for window covering device
  @param ep_name - endpoint variable name
  @param ep_id - endpoint ID
  @param cluster_list - endpoint cluster list
 */
#define ZB_HA_DECLARE_WINDOW_COVERING_EP(ep_name, ep_id, cluster_list)            \
  ZB_ZCL_DECLARE_WINDOW_COVERING_SIMPLE_DESC(ep_name, ep_id,                      \
    ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM, ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM); \
  ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name,            \
                                     ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT);    \
  ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID,                \
            0,                    \
            NULL,                                \
    ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list,         \
    (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name,                             \
    ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT, reporting_info## device_ctx_name,    \
    0, NULL) /* No CVC ctx */


/*!
  @brief Declare application's device context for Window Covering device
  @param device_ctx - device context variable
  @param ep_name - endpoint variable name
*/
#define ZB_HA_DECLARE_WINDOW_COVERING_CTX(device_ctx, ep_name)          \
  ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name)

/*! @} */

/** @endcond */ /* DOXYGEN_HA_SECTION */

#endif /* ZB_HA_DEFINE_DEVICE_WINDOW_COVERING */

#endif /* ! defined ZB_HA_WINDOW_COVERING_H */

I get these errors: 

Building ‘motion_blinds’ from solution ‘zigbee_light_bulb_pca10056’ in configuration ‘Debug’
  Compiling ‘zigbee_helpers.c’
    zboss_api.h
    zigbee_helpers.h
    zigbee_helpers.c
    offset of packed bit-field 'expiry' has changed in GCC 4.4
    zboss_api.h
    zigbee_helpers.h
    zigbee_helpers.c
    offset of packed bit-field 'age' has changed in GCC 4.4
    offset of packed bit-field 'transmit_failure_cnt' has changed in GCC 4.4
  Compiling ‘main.c’
    zboss_api.h
    main.c
    offset of packed bit-field 'expiry' has changed in GCC 4.4
    zboss_api.h
    main.c
    offset of packed bit-field 'age' has changed in GCC 4.4
    offset of packed bit-field 'transmit_failure_cnt' has changed in GCC 4.4
    zboss_api.h
    main.c
    'ZB_ZCL_CLUSTER_ID_POWER_CONFIG_SERVER_ROLE_INIT' undeclared here (not in a function); did you mean 'ZB_ZCL_CLUSTER_ID_SHADE_CONFIG_SERVER_ROLE_INIT'?
    in definition of macro 'ZB_ZCL_CLUSTER_DESC'
    in expansion of macro 'ZB_HA_DECLARE_WINDOW_COVERING_CLUSTER_LIST'
    'ZB_ZCL_CLUSTER_ID_POWER_CONFIG_CLIENT_ROLE_INIT' undeclared here (not in a function); did you mean 'ZB_ZCL_CLUSTER_ID_SHADE_CONFIG_CLIENT_ROLE_INIT'?
    in definition of macro 'ZB_ZCL_CLUSTER_DESC'
    in expansion of macro 'ZB_HA_DECLARE_WINDOW_COVERING_CLUSTER_LIST'
    zb_ha.h
    zboss_api.h
    main.c
    excess elements in array initializer
    in expansion of macro 'ZB_ZCL_DECLARE_WINDOW_COVERING_SIMPLE_DESC'
    in expansion of macro 'ZB_HA_DECLARE_WINDOW_COVERING_EP'
    (near initialization for 'simple_desc_window_covering_ep.app_cluster_list')
    in expansion of macro 'ZB_ZCL_DECLARE_WINDOW_COVERING_SIMPLE_DESC'
    in expansion of macro 'ZB_HA_DECLARE_WINDOW_COVERING_EP'
Build failed

on these lines (zb_ha_window_covering.h):

As a coordinator I am using Zigbee2mqtt with Ti CC2531 dongle.

The code worked well before I started implementing the battery voltage reporting functionality.

Also, the code is built on light example, just the Window Covering HA profile instead of the HA Dimmable Light 

Thanks very much in advance!

Krystof Vydra

Parents
  • Hello Krystof,

    It looks like you have declared zb_zcl_power_config_attrs_t somewhere, is that correct? If so, how did you declare it?

    is zb_scl_power_config.h included from your main.c? You don't need to include it directly from there. I used the file zboss_api_zcl_addons.h, and included:

    #include "zcl/zb_scl_power_config_addons.h"

    from there.

    My zb_zcl_power_config_addons.h looks like this:

    zb_zcl_power_config_addons.h

    And my ZB_HA_DECLARE_DIMMABLE_LIGHT_CLUSTER_LIST (I have not implemented the window shader cluster before, but you seem to have that going already, so I just modified the light_bulb example):

    /*!
      @brief Declare cluster list for Dimmable Light device
      @param cluster_list_name - cluster list variable name
      @param basic_attr_list - attribute list for Basic cluster
      @param identify_attr_list - attribute list for Identify cluster
      @param groups_attr_list - attribute list for Groups cluster
      @param scenes_attr_list - attribute list for Scenes cluster
      @param on_off_attr_list - attribute list for On/Off cluster
      @param level_control_attr_list - attribute list for Level Control cluster
      @param power_config_attr_list - attribute list for Power Config cluster
     */
    #define ZB_HA_DECLARE_DIMMABLE_LIGHT_CLUSTER_LIST(               \
      cluster_list_name,                                             \
      basic_attr_list,                                               \
      identify_attr_list,                                            \
      groups_attr_list,                                              \
      scenes_attr_list,                                              \
      on_off_attr_list,                                              \
      level_control_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_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_ON_OFF,                                  \
          ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t),        \
          (on_off_attr_list),                                        \
          ZB_ZCL_CLUSTER_SERVER_ROLE,                                \
          ZB_ZCL_MANUF_CODE_INVALID                                  \
        ),                                                           \
        ZB_ZCL_CLUSTER_DESC(                                         \
          ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL,                           \
          ZB_ZCL_ARRAY_SIZE(level_control_attr_list, zb_zcl_attr_t), \
          (level_control_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                                  \
        )                                                            \
      }
    

    And my attribute list declarations looked like this in the end (main.c)

    /* Main application customizable context. Stores all settings and static values. */
    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_ext_t        on_off_attr;
        zb_zcl_level_control_attrs_t     level_control_attr;
        zb_zcl_power_config_attrs_t      power_config_attr;
    } bulb_device_ctx_t;
    
    
    APP_PWM_INSTANCE(BULB_PWM_NAME, BULB_PWM_TIMER);
    static bulb_device_ctx_t m_dev_ctx;
    
    ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(identify_attr_list, &m_dev_ctx.identify_attr.identify_time);
    
    
    ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(groups_attr_list, &m_dev_ctx.groups_attr.name_support);
    
    ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST(scenes_attr_list,
                                      &m_dev_ctx.scenes_attr.scene_count,
                                      &m_dev_ctx.scenes_attr.current_scene,
                                      &m_dev_ctx.scenes_attr.current_group,
                                      &m_dev_ctx.scenes_attr.scene_valid,
                                      &m_dev_ctx.scenes_attr.name_support);
    
    ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST_EXT(basic_attr_list,
                                         &m_dev_ctx.basic_attr.zcl_version,
                                         &m_dev_ctx.basic_attr.app_version,
                                         &m_dev_ctx.basic_attr.stack_version,
                                         &m_dev_ctx.basic_attr.hw_version,
                                         m_dev_ctx.basic_attr.mf_name,
                                         m_dev_ctx.basic_attr.model_id,
                                         m_dev_ctx.basic_attr.date_code,
                                         &m_dev_ctx.basic_attr.power_source,
                                         m_dev_ctx.basic_attr.location_id,
                                         &m_dev_ctx.basic_attr.ph_env,
                                         m_dev_ctx.basic_attr.sw_ver);
    
    /* On/Off cluster attributes additions data */
    ZB_ZCL_DECLARE_ON_OFF_ATTRIB_LIST_EXT(on_off_attr_list,
                                          &m_dev_ctx.on_off_attr.on_off,
                                          &m_dev_ctx.on_off_attr.global_scene_ctrl,
                                          &m_dev_ctx.on_off_attr.on_time,
                                          &m_dev_ctx.on_off_attr.off_wait_time);
    
    ZB_ZCL_DECLARE_LEVEL_CONTROL_ATTRIB_LIST(level_control_attr_list,
                                             &m_dev_ctx.level_control_attr.current_level,
                                             &m_dev_ctx.level_control_attr.remaining_time);
    
        //#define ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(attr_list,                      
        //    voltage, size, quantity, rated_voltage, alarm_mask, voltage_min_threshold,              
        //    remaining, threshold1, threshold2, threshold3, min_threshold, percent_threshold1,       
        //    percent_threshold2, percent_threshold3, alarm_state)     
    
    ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(power_config_attr_list,
                                                        &m_dev_ctx.power_config_attr.battery_voltage,
                                                        &m_dev_ctx.power_config_attr.battery_size,
                                                        &m_dev_ctx.power_config_attr.battery_quantity,
                                                        &m_dev_ctx.power_config_attr.battery_rated_voltage,
                                                        &m_dev_ctx.power_config_attr.battery_alarm_mask,
                                                        &m_dev_ctx.power_config_attr.battery_voltage_min_threshold,
                                                        &m_dev_ctx.power_config_attr.battery_percentage_remaining,
                                                        &m_dev_ctx.power_config_attr.battery_voltage_threshold1,
                                                        &m_dev_ctx.power_config_attr.battery_voltage_threshold2,
                                                        &m_dev_ctx.power_config_attr.battery_voltage_threshold3,
                                                        &m_dev_ctx.power_config_attr.battery_percentage_min_threshold,
                                                        &m_dev_ctx.power_config_attr.battery_percentage_threshold1,
                                                        &m_dev_ctx.power_config_attr.battery_percentage_threshold2,
                                                        &m_dev_ctx.power_config_attr.battery_percentage_threshold3,
                                                        &m_dev_ctx.power_config_attr.battery_alarm_state);
                                                        
    
    ZB_HA_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,
                                              power_config_attr_list);
    
    ZB_HA_DECLARE_LIGHT_EP(dimmable_light_ep,
                           HA_DIMMABLE_LIGHT_ENDPOINT,
                           dimmable_light_clusters);
    
    ZB_HA_DECLARE_DIMMABLE_LIGHT_CTX(dimmable_light_ctx,
                                     dimmable_light_ep);
    

    See if you can spot any differences. If not, can you please upload your project, so that I can try to reproduce the issue you are seeing?

    Best regards,

    Edvin

  • Hello Edvin,

    I have included the zb_zcl_power_config.h in main.c and the zb_zcl_power_config_attrs_t declared in my main.c like this:

    typedef struct
    {
        zb_uint8_t voltage;   
        zb_uint8_t size;
        zb_uint8_t quantity;
        zb_uint8_t rated_voltage;
        zb_uint8_t alarm_mask;
        zb_uint8_t voltage_min_threshold;
        zb_uint8_t remaining;   
        zb_uint8_t threshold1;
        zb_uint8_t threshold2;
        zb_uint8_t threshold3;
        zb_uint8_t min_threshold;
        zb_uint8_t percent_treshold1;
        zb_uint8_t percent_threshold2;
        zb_uint8_t percent_threshold3;
        zb_uint8_t alarm_state;   
    
    }zb_zcl_power_config_attrs_t;
    
    
    
    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 mode;
    }device_window_covering;
    
    
    
    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;
        device_window_covering window_covering_attr;
        zb_zcl_power_config_attrs_t power_config_attr;
    }window_covering_device_ctx;

    So I guess I don't need to add the zb_zcl_power_config_addons.h right?

    In addition, I changed these things in zb_ha_window_covering.h:

    #define ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM from 5 to 6 (since I added the Power Config cluster)

    and #define ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT to:

    #define ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT         \
      (ZB_ZCL_WINDOW_COVERING_REPORT_ATTR_COUNT + ZB_ZCL_POWER_CONFIG_REPORT_ATTR_COUNT)

    to include also the power_config reporting attributes

    Since you didn't mention these, are they not mandatory?

    I can't spot any differences in the code. I have the ZB_HA_DECLARE_DIMMABLE_LIGHT_CLUSTER_LIST completely same as yours. Also the Attribute list declaration is the same. 

    Still no luck.

    I tried adding 

     UNUSED_RETURN_VALUE(zb_zcl_set_attr_val(HA_WINDOW_COVERING_ENDPOINT, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, ZB_ZCL_CLUSTER_SERVER_ROLE, ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, (zb_uint8_t *)&m_dev_ctx.power_config_attr.remaining, ZB_FALSE));

    in the zcl_device_cb:

    zb_void_t zcl_device_cb(zb_bufid_t bufid)
    {
        zb_uint8_t                       cluster_id;
        zb_uint8_t                       attr_id;
        zb_zcl_device_callback_param_t * p_device_cb_param = ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
    
        NRF_LOG_INFO("zcl_device_cb id %hd", p_device_cb_param->device_cb_id);
        
        p_device_cb_param->status = RET_OK;
    
        
        switch (p_device_cb_param->device_cb_id)
        {
          
          
          case ZB_ZCL_WINDOW_COVERING_UP_OPEN_CB_ID:
              NRF_LOG_INFO("OPEN UP");
              //function open
              break;
    
          case ZB_ZCL_WINDOW_COVERING_DOWN_CLOSE_CB_ID:
              NRF_LOG_INFO("CLOSE DOWN");
              m_dev_ctx.power_config_attr.remaining = m_dev_ctx.power_config_attr.remaining + 1;
              UNUSED_RETURN_VALUE(zb_zcl_set_attr_val(HA_WINDOW_COVERING_ENDPOINT, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, ZB_ZCL_CLUSTER_SERVER_ROLE, ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, (zb_uint8_t *)&m_dev_ctx.power_config_attr.remaining, ZB_FALSE));
              //fuction close
              break;
          
          case ZB_ZCL_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE_CB_ID:
              NRF_LOG_INFO("GO TO TILT PERCENTAGE");
              //function go to tilt
              break;
    
          default:
                p_device_cb_param->status = RET_ERROR;
                break;
        
        
        }
    
    
    
    }

    in a hope that if I send a command to the device (e.g. close the curtains) it replies me with battery remaining percent attribute. But that is not happening. 

    I think that my coordinator (Zigbee2MQTT) is setted up properly. It shows that it received messages from the device while it was joining network: 

    Zigbee2MQTT:debug 2021-03-05 14:01:00: Device '0xf4ce36250feaeb0e' announced itself
    Zigbee2MQTT:info  2021-03-05 14:01:00: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0xf4ce36250feaeb0e","ieee_address":"0xf4ce36250feaeb0e"},"type":"device_announce"}'
    Zigbee2MQTT:info  2021-03-05 14:01:00: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"announce","meta":{"friendly_name":"0xf4ce36250feaeb0e"},"type":"device_announced"}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"modelId":"Window_Covering_v0.1"}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"modelId":"Window_Covering_v0.1"}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"manufacturerName":"Nordic"}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"manufacturerName":"Nordic"}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"powerSource":4}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"powerSource":4}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"zclVersion":2}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"zclVersion":2}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"appVersion":1}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"appVersion":1}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"stackVersion":10}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"stackVersion":10}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"hwVersion":11}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"hwVersion":11}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"dateCode":"20180416"}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"dateCode":"20180416"}'
    Zigbee2MQTT:debug 2021-03-05 14:01:01: Received Zigbee message from '0xf4ce36250feaeb0e', type 'readResponse', cluster 'genBasic', data '{"swBuildId":""}' from endpoint 10 with groupID 0
    Zigbee2MQTT:debug 2021-03-05 14:01:01: No converter available for '52840' with cluster 'genBasic' and type 'readResponse' and data '{"swBuildId":""}'
    Zigbee2MQTT:info  2021-03-05 14:01:01: Successfully interviewed '0xf4ce36250feaeb0e', device has successfully been paired
    

    and that it doesn't have converters for those clusters. (but these are type: readResponse, so I think that they were just a reply for request from the coordinator to report attributes/read data?)

    I must be missing something essential.

    Here is my project: https://drive.google.com/file/d/1bpcZeKO3sUFscLU_ucjY_cyF46ljWgtB/view?usp=sharing

    Thanks very much in advance Edvin!

    Best regards,

    Krystof Vydra

  • Try this:

    typedef struct
    {
        zb_uint8_t battery_voltage;
        zb_uint8_t battery_size;
        zb_uint8_t battery_quantity;
        zb_uint8_t battery_rated_voltage;
        zb_uint8_t battery_alarm_mask;
        zb_uint8_t battery_voltage_min_threshold;
        zb_uint8_t battery_percentage_remaining;
        zb_uint8_t battery_voltage_threshold1;
        zb_uint8_t battery_voltage_threshold2;
        zb_uint8_t battery_voltage_threshold3;
        zb_uint8_t battery_percentage_min_threshold;
        zb_uint8_t battery_percentage_threshold1;
        zb_uint8_t battery_percentage_threshold2;
        zb_uint8_t battery_percentage_threshold3;
        zb_uint32_t battery_alarm_state;
        
    } zb_zcl_power_config_attrs_t;

    At least the alarm_state should be an uint32_t I believe. I will have to look more into your project tomorrow if you didn't get it to work. Please check whether that simple fix solves it.

    I guess the Zigbee2mqtt is running on something else (Not nRF). I have never tried it before, so I am not familiar with it.

  • So I tried your project now. Either, you need to start with an unmodified unzip of the SDK, or you need to look into your compiler errors. After changing zb_ha_window_covering.h to the following, it compiled without any errors:

    zb_ha_window_covering.h

    I didn't get the error that you got, but please ensure that you didn't make any unintentional changes in zb_zcl_power_config.h, and that zb_zcl_power_config.h is included in your project (#include "zb_zcl_power_config.h" in your main.c file).

    If it doesn't work, try to unzip it to an unmodified SDK, and replace the zb_ha_window_covering.h with the one attached.

    BR,

    Edvin

Reply
  • So I tried your project now. Either, you need to start with an unmodified unzip of the SDK, or you need to look into your compiler errors. After changing zb_ha_window_covering.h to the following, it compiled without any errors:

    zb_ha_window_covering.h

    I didn't get the error that you got, but please ensure that you didn't make any unintentional changes in zb_zcl_power_config.h, and that zb_zcl_power_config.h is included in your project (#include "zb_zcl_power_config.h" in your main.c file).

    If it doesn't work, try to unzip it to an unmodified SDK, and replace the zb_ha_window_covering.h with the one attached.

    BR,

    Edvin

Children
No Data
Related