Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Adding ZCL clusters to application - Temperature - Error with build

Hi,

I've been trying to learn how to use the SDK and I was following the Adding ZCL clusters to application guide to add temperature. I skipped adding the on/off switch and so I used `ZBOSS_DECLARE_DEVICE_CTX_2_EP` instead of `ZBOSS_DECLARE_DEVICE_CTX_3_EP`.

I've been getting build errors and I haven't been able to figure out what I've done wrong. I've been comparing my main.c to the guide, and also to several of the SDK examples (light bulb, light switch, weather station, etc.). I'm using SDK V2.2.0

Can somebody please help me figure this out?

Kind regards,
Dan

What I've Done:

Following the guide, I included zb_zcl_temp_measurement_addons.h

#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <dk_buttons_and_leds.h>

#include <zboss_api.h>
#include <zigbee/zigbee_error_handler.h>
#include <zigbee/zigbee_app_utils.h>
#include <zb_nrf_platform.h>
#include "zb_range_extender.h"

/* Include temperature measurement. */
#include <addons/zcl/zb_zcl_temp_measurement_addons.h>

I defined the temperature measurement endpoint and placed this under the app template endpoint.

/* Device endpoint, used to receive ZCL commands. */
#define APP_TEMPLATE_ENDPOINT               10

/* Endpoint used to send temperature data. */
#define TEMPERATURE_SENSOR_ENDPOINT			12

I added the temperature measurement attributes to the zb_device_ctx structure.

struct zb_device_ctx {
	zb_zcl_basic_attrs_t 			basic_attr;
	zb_zcl_identify_attrs_t 		identify_attr;
	zb_zcl_temp_measurement_attrs_t	temp_measure_attrs;
};

I declared the attribute list for the temperature measurement cluster, the cluster list for the device, declared the endpoint, and edited the device context. I also moved the device context below the other declarations.

/* Declare attribute list for temperature measurement cluster. */
ZB_ZCL_DECLARE_TEMP_MEASUREMENT_ATTRIB_LIST(
	temp_measurement_attr_list,
	&dev_ctx.temp_measure_attrs.measure_value,
	&dev_ctx.temp_measure_attrs.min_measure_value,
	&dev_ctx.temp_measure_attrs.max_measure_value,
	&dev_ctx.temp_measure_attrs.tolerance);

/* Declare cluster list for temperature measurement device. */
ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST(
	temperature_sensor_clusters,
	basic_attr_list,
	identify_attr_list,
	temp_measurement_attr_list);

/* Declare endpoint for temperature measurement device. */
ZB_HA_DECLARE_TEMPERATURE_SENSOR_EP(
	temperature_sensor_ep,
	TEMPERATURE_SENSOR_ENDPOINT,
	temperature_sensor_clusters);

ZBOSS_DECLARE_DEVICE_CTX_2_EP(
	app_template_ctx,
	app_template_ep,
	temperature_sensor_ep);

VS Code highlights `TEMPERATURE_SENSOR_ENDPOINT` from the `ZB_HA_DECLARE_TEMPERATURE_SENSOR_EP` declaration saying "expected an identifier".
And it highlights `ZBOSS_DECLARE_DEVICE_CTX_2_EP(...` saying "identifier "temperature_sensor_ep" is undefined".

When I try to build, I get the following output in terminal.

n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:114:1: warning: data definition has no type or storage class
  114 | ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST(
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:114:1: error: type defaults to 'int' in declaration of 'ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST' [-Werror=implicit-int]
n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:118:9: warning: parameter names (without types) in function declaration
  118 |         temp_measurement_attr_list);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:122:31: error: expected ')' before numeric constant
  122 |         temperature_sensor_ep,
      |                               ^
      |                               )
In file included from C:\ncs\SDK\v2.2.0\nrfxlib\zboss\production\include\zboss_api.h:52,
                 from n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:38:
n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:129:9: error: 'temperature_sensor_ep' undeclared here (not in a function)
  129 |         temperature_sensor_ep);
      |         ^~~~~~~~~~~~~~~~~~~~~
C:\ncs\SDK\v2.2.0\nrfxlib\zboss\production\include\zboss_api_af.h:586:6: note: in definition of macro 'ZBOSS_DECLARE_DEVICE_CTX_2_EP'
  586 |     &ep2_name,                                                          \
      |      ^~~~~~~~
cc1.exe: some warnings being treated as errors

Parents
  • Hi, 

    I'm using SDK V2.2.0

    The guide is only suitable for v2.3.0. Please use NCS v2.3.0. 

    -Amanda H.

  • Is anybody still looking at this? I don't think the `ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST` or `ZB_HA_DECLARE_TEMPERATURE_SENSOR_EP` macros are defined in the SDK.

  • Do you have an example where this file is used? Even better if you have a Zigbee Light Bulb example where this file is used.

    I get the same error after a pristine build when I include that file. See below.

    I couldn't find zb_ha_temperature_sensor.h in the SDK so I instead added it in the same directory as main.c and included it like this. (Listing the individual parts of my code to keep it readable makes it difficult to follow so I've also just uploaded my main.c at the end.)

    #include <zephyr/kernel.h>
    #include <zephyr/logging/log.h>
    #include <dk_buttons_and_leds.h>
    
    #include <zboss_api.h>
    #include <zigbee/zigbee_error_handler.h>
    #include <zigbee/zigbee_app_utils.h>
    #include <zb_nrf_platform.h>
    #include "zb_range_extender.h"
    
    /* Include temperature measurement. */
    #include <addons/zcl/zb_zcl_temp_measurement_addons.h>
    //#include <zb_ha_temperature_sensor.h>
    #include "zb_ha_temperature_sensor.h"

    The rest of my code is the same as written in my original post.

    This is the build output

     *  Executing task: nRF Connect: Build: RGBWC_nRF52840/build (active) 
    
    Building RGBWC_nRF52840
    west build --build-dir n:\Projects\Nordic\myApps\RGBWC_nRF52840\build n:\Projects\Nordic\myApps\RGBWC_nRF52840
    
    [1/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_meter_identification.c.obj
    [2/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_illuminance_measurement.c.obj
    [3/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_ota_upgrade_common.c.obj
    [4/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_on_off_switch_config.c.obj
    [5/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_level_control_commands.c.obj
    [6/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_occupancy_sensing_commands.c.obj
    [7/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_main.c.obj
    [8/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_on_off_commands.c.obj
    [9/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_ota_upgrade_minimal.c.obj
    [10/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_poll_control_client.c.obj
    [11/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_ota_upgrade_srv_commands.c.obj
    [12/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_ota_upgrade_commands.c.obj
    [13/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_poll_control_commands.c.obj
    [14/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_rel_humidity.c.obj
    [15/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_reporting.c.obj
    [16/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_power_config_commands.c.obj
    [17/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_s_daily_schedule.c.obj
    [18/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_s_drlc.c.obj
    [19/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_s_messaging.c.obj
    [20/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_s_metering.c.obj
    [21/239] Building C object CMakeFiles/app.dir/src/main.c.obj
    FAILED: CMakeFiles/app.dir/src/main.c.obj 
    C:\ncs\SDK\toolchains\v2.3.0\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DCUSTOM_IEEE802154_L2=ZIGBEE_L2 -DKERNEL -DLIBZBOSS_CONFIG_FILE=\"C:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include/osif/libzboss_config.h\" -DNRF52840_XXAA -DNRF_802154_ACK_TIMEOUT_ENABLED=1 -DNRF_802154_CCA_CORR_LIMIT_DEFAULT=2 -DNRF_802154_CCA_CORR_THRESHOLD_DEFAULT=45 -DNRF_802154_CCA_ED_THRESHOLD_DEFAULT=45 -DNRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_ED -DNRF_802154_ECB_PRIORITY=-1 -DNRF_802154_ENCRYPTION_ENABLED=0 -DNRF_802154_IE_WRITER_ENABLED=0 -DNRF_802154_INTERNAL_RADIO_IRQ_HANDLING=0 -DNRF_802154_PENDING_EXTENDED_ADDRESSES=16 -DNRF_802154_PENDING_SHORT_ADDRESSES=16 -DNRF_802154_RX_BUFFERS=16 -DNRF_802154_SECURITY_WRITER_ENABLED=0 -DNRF_802154_SWI_PRIORITY=1 -DNRF_802154_TX_STARTED_NOTIFY_ENABLED=1 -DNRF_802154_USE_RAW_API=1 -DUSE_PARTITION_MANAGER=1 -DZIGBEE_L2=ZIGBEE -D__PROGRAM_START -D__ZEPHYR__=1 -I../include -IC:/ncs/SDK/v2.3.0/nrf/drivers/mpsl/clock_control -IC:/ncs/SDK/v2.3.0/zephyr/include -Izephyr/include/generated -IC:/ncs/SDK/v2.3.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/SDK/v2.3.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/SDK/v2.3.0/nrf/include -IC:/ncs/SDK/v2.3.0/nrf/lib/multithreading_lock/. -IC:/ncs/SDK/v2.3.0/zephyr/drivers/flash -IC:/ncs/SDK/v2.3.0/nrf/tests/include -IC:/ncs/SDK/v2.3.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/SDK/v2.3.0/modules/hal/nordic/nrfx -IC:/ncs/SDK/v2.3.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/SDK/v2.3.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/SDK/v2.3.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/SDK/v2.3.0/modules/debug/segger/SEGGER -IC:/ncs/SDK/v2.3.0/modules/debug/segger/Config -IC:/ncs/SDK/v2.3.0/zephyr/modules/segger/. -IC:/ncs/SDK/v2.3.0/nrfxlib/mpsl/include -IC:/ncs/SDK/v2.3.0/nrfxlib/mpsl/include/protocol -IC:/ncs/SDK/v2.3.0/nrfxlib/nrf_802154/driver/include -IC:/ncs/SDK/v2.3.0/nrfxlib/nrf_802154/sl/include -IC:/ncs/SDK/v2.3.0/nrf/subsys/zigbee/osif -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/src/zb_error -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include/addons -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include/zcl -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include/ha -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include/se -IC:/ncs/SDK/v2.3.0/nrfxlib/zboss/production/include/osif -isystem C:/ncs/SDK/v2.3.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/sdk/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/include -isystem c:/ncs/sdk/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/include-fixed -isystem C:/ncs/SDK/v2.3.0/nrfxlib/crypto/nrf_cc310_platform/include -fno-strict-aliasing -Og -imacros N:/Projects/Nordic/myApps/RGBWC_nRF52840/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mfp16-format=ieee --sysroot=C:/ncs/SDK/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/SDK/v2.3.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=N:/Projects/Nordic/myApps/RGBWC_nRF52840=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/SDK/v2.3.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/SDK/v2.3.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -Wno-packed-bitfield-compat -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
    n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:115:1: warning: data definition has no type or storage class
      115 | ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST(
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:115:1: error: type defaults to 'int' in declaration of 'ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST' [-Werror=implicit-int]
    n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:119:9: warning: parameter names (without types) in function declaration
      119 |         temp_measurement_attr_list);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
    n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:123:31: error: expected ')' before numeric constant
      123 |         temperature_sensor_ep,
          |                               ^
          |                               )
    In file included from C:\ncs\SDK\v2.3.0\nrfxlib\zboss\production\include\zboss_api.h:52,
                     from n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:38:
    n:\Projects\Nordic\myApps\RGBWC_nRF52840\src\main.c:130:9: error: 'temperature_sensor_ep' undeclared here (not in a function)
      130 |         temperature_sensor_ep);
          |         ^~~~~~~~~~~~~~~~~~~~~
    C:\ncs\SDK\v2.3.0\nrfxlib\zboss\production\include\zboss_api_af.h:586:6: note: in definition of macro 'ZBOSS_DECLARE_DEVICE_CTX_2_EP'
      586 |     &ep2_name,                                                          \
          |      ^~~~~~~~
    cc1.exe: some warnings being treated as errors
    [22/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_pressure_measurement.c.obj
    [23/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_s_price.c.obj
    [24/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_scenes.c.obj
    [25/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_shade_config_commands.c.obj
    [26/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_s_wwah.c.obj
    [27/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_temp_measurement.c.obj
    [28/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_thermostat_ui_config.c.obj
    [29/239] Linking C static library zephyr\libzephyr.a
    [30/239] Building C object modules/nrfxlib/nrfxlib/zboss/production/src/CMakeFiles/zboss-sources.dir/zcl/zcl_thermostat_commands.c.obj
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'c:\ncs\SDK\toolchains\v2.3.0\opt\bin\cmake.EXE' --build 'n:\Projects\Nordic\myApps\RGBWC_nRF52840\build'
    
     *  The terminal process terminated with exit code: 1. 
     *  Terminal will be reused by tasks, press any key to close it. 

    It still doesn't seem to like this part, which I checked and is still the same as the guide. Except that "#define TEMPERATURE_SENSOR_ENDPOINT 12" is defined further up with the rest of the definitions.

    /* Declare endpoint for temperature measurement device. */
    ZB_HA_DECLARE_TEMPERATURE_SENSOR_EP(
    	temperature_sensor_ep,
    	TEMPERATURE_SENSOR_ENDPOINT,
    	temperature_sensor_clusters);
    
    ZBOSS_DECLARE_DEVICE_CTX_2_EP(
    	app_template_ctx,
    	app_template_ep,
    	temperature_sensor_ep);

    My main.c file might be easier to look at than the individual code blocks above.

    /*
     * Copyright (c) 2021 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    /** @file
     *
     * @brief Zigbee application template.
     */
    
    
    
    /*
    ________ Guides
    
    Adding ZCL clusters to application
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/protocols/zigbee/adding_clusters.html
    
    https://devzone.nordicsemi.com/f/nordic-q-a/77860/join-existing-zigbee-network-with-light-bulb-example
    
    ________ Steps
    
    1. Start with nRF Zigbee Template example, from SDK V2.3.0. https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/zigbee/template/README.html#zigbee-template-sample
    2. Add temperature by following this guide. https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/protocols/zigbee/adding_clusters.html
    */
    
    
    #include <zephyr/kernel.h>
    #include <zephyr/logging/log.h>
    #include <dk_buttons_and_leds.h>
    
    #include <zboss_api.h>
    #include <zigbee/zigbee_error_handler.h>
    #include <zigbee/zigbee_app_utils.h>
    #include <zb_nrf_platform.h>
    #include "zb_range_extender.h"
    
    /* Include temperature measurement. */
    #include <addons/zcl/zb_zcl_temp_measurement_addons.h>
    //#include <zb_ha_temperature_sensor.h>
    #include "zb_ha_temperature_sensor.h"
    
    /* Device endpoint, used to receive ZCL commands. */
    #define APP_TEMPLATE_ENDPOINT               10
    
    /* Endpoint used to send temperature data. */
    #define TEMPERATURE_SENSOR_ENDPOINT			12
    
    /* Type of power sources available for the device.
     * For possible values see section 3.2.2.2.8 of ZCL specification.
     */
    #define TEMPLATE_INIT_BASIC_POWER_SOURCE    ZB_ZCL_BASIC_POWER_SOURCE_DC_SOURCE
    
    /* LED indicating that device successfully joined Zigbee network. */
    #define ZIGBEE_NETWORK_STATE_LED            DK_LED3
    
    /* LED used for device identification. */
    #define IDENTIFY_LED                        DK_LED4
    
    /* Button used to enter the Identify mode. */
    #define IDENTIFY_MODE_BUTTON                DK_BTN4_MSK
    
    /* Button to start Factory Reset */
    #define FACTORY_RESET_BUTTON                IDENTIFY_MODE_BUTTON
    
    
    LOG_MODULE_REGISTER(app, LOG_LEVEL_INF);
    
    /* Main application customizable context.
     * Stores all settings and static values.
     */
    struct zb_device_ctx {
    	zb_zcl_basic_attrs_t 			basic_attr;
    	zb_zcl_identify_attrs_t 		identify_attr;
    	zb_zcl_temp_measurement_attrs_t	temp_measure_attrs;
    };
    
    /* Zigbee device application context storage. */
    static struct zb_device_ctx dev_ctx;
    
    ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(
    	identify_attr_list,
    	&dev_ctx.identify_attr.identify_time);
    
    ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST(
    	basic_attr_list,
    	&dev_ctx.basic_attr.zcl_version,
    	&dev_ctx.basic_attr.power_source);
    
    ZB_DECLARE_RANGE_EXTENDER_CLUSTER_LIST(
    	app_template_clusters,
    	basic_attr_list,
    	identify_attr_list);
    
    ZB_DECLARE_RANGE_EXTENDER_EP(
    	app_template_ep,
    	APP_TEMPLATE_ENDPOINT,
    	app_template_clusters);
    
    /* Declare attribute list for temperature measurement cluster. */
    ZB_ZCL_DECLARE_TEMP_MEASUREMENT_ATTRIB_LIST(
    	temp_measurement_attr_list,
    	&dev_ctx.temp_measure_attrs.measure_value,
    	&dev_ctx.temp_measure_attrs.min_measure_value,
    	&dev_ctx.temp_measure_attrs.max_measure_value,
    	&dev_ctx.temp_measure_attrs.tolerance);
    
    /* Declare cluster list for temperature measurement device. */
    ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST(
    	temperature_sensor_clusters,
    	basic_attr_list,
    	identify_attr_list,
    	temp_measurement_attr_list);
    
    /* Declare endpoint for temperature measurement device. */
    ZB_HA_DECLARE_TEMPERATURE_SENSOR_EP(
    	temperature_sensor_ep,
    	TEMPERATURE_SENSOR_ENDPOINT,
    	temperature_sensor_clusters);
    
    ZBOSS_DECLARE_DEVICE_CTX_2_EP(
    	app_template_ctx,
    	app_template_ep,
    	temperature_sensor_ep);
    
    /**@brief Function for initializing all clusters attributes. */
    static void app_clusters_attr_init(void)
    {
    	/* Basic cluster attributes data */
    	dev_ctx.basic_attr.zcl_version = ZB_ZCL_VERSION;
    	dev_ctx.basic_attr.power_source = TEMPLATE_INIT_BASIC_POWER_SOURCE;
    
    	/* Identify cluster attributes data. */
    	dev_ctx.identify_attr.identify_time =
    		ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE;
    }
    
    /**@brief Function to toggle the identify LED
     *
     * @param  bufid  Unused parameter, required by ZBOSS scheduler API.
     */
    static void toggle_identify_led(zb_bufid_t bufid)
    {
    	static int blink_status;
    
    	dk_set_led(IDENTIFY_LED, (++blink_status) % 2);
    	ZB_SCHEDULE_APP_ALARM(toggle_identify_led, bufid, ZB_MILLISECONDS_TO_BEACON_INTERVAL(100));
    }
    
    /**@brief Function to handle identify notification events on the first endpoint.
     *
     * @param  bufid  Unused parameter, required by ZBOSS scheduler API.
     */
    static void identify_cb(zb_bufid_t bufid)
    {
    	zb_ret_t zb_err_code;
    
    	if (bufid) {
    		/* Schedule a self-scheduling function that will toggle the LED */
    		ZB_SCHEDULE_APP_CALLBACK(toggle_identify_led, bufid);
    	} else {
    		/* Cancel the toggling function alarm and turn off LED */
    		zb_err_code = ZB_SCHEDULE_APP_ALARM_CANCEL(toggle_identify_led, ZB_ALARM_ANY_PARAM);
    		ZVUNUSED(zb_err_code);
    
    		dk_set_led(IDENTIFY_LED, 0);
    	}
    }
    
    /**@brief Starts identifying the device.
     *
     * @param  bufid  Unused parameter, required by ZBOSS scheduler API.
     */
    static void start_identifying(zb_bufid_t bufid)
    {
    	ZVUNUSED(bufid);
    
    	if (ZB_JOINED()) {
    		/* Check if endpoint is in identifying mode,
    		 * if not put desired endpoint in identifying mode.
    		 */
    		if (dev_ctx.identify_attr.identify_time ==
    		ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
    
    			zb_ret_t zb_err_code = zb_bdb_finding_binding_target(
    				APP_TEMPLATE_ENDPOINT);
    
    			if (zb_err_code == RET_OK) {
    				LOG_INF("Enter identify mode");
    			} else if (zb_err_code == RET_INVALID_STATE) {
    				LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
    			} else {
    				ZB_ERROR_CHECK(zb_err_code);
    			}
    		} else {
    			LOG_INF("Cancel identify mode");
    			zb_bdb_finding_binding_target_cancel();
    		}
    	} else {
    		LOG_WRN("Device not in a network - cannot enter identify mode");
    	}
    }
    
    /**@brief Callback for button events.
     *
     * @param[in]   button_state  Bitmask containing buttons state.
     * @param[in]   has_changed   Bitmask containing buttons
     *                            that have changed their state.
     */
    static void button_changed(uint32_t button_state, uint32_t has_changed)
    {
    	if (IDENTIFY_MODE_BUTTON & has_changed) {
    		if (IDENTIFY_MODE_BUTTON & button_state) {
    			/* Button changed its state to pressed */
    		} else {
    			/* Button changed its state to released */
    			if (was_factory_reset_done()) {
    				/* The long press was for Factory Reset */
    				LOG_DBG("After Factory Reset - ignore button release");
    			} else   {
    				/* Button released before Factory Reset */
    
    				/* Start identification mode */
    				ZB_SCHEDULE_APP_CALLBACK(start_identifying, 0);
    			}
    		}
    	}
    
    	check_factory_reset_button(button_state, has_changed);
    }
    
    /**@brief Function for initializing LEDs and Buttons. */
    static void configure_gpio(void)
    {
    	int err;
    
    	err = dk_buttons_init(button_changed);
    	if (err) {
    		LOG_ERR("Cannot init buttons (err: %d)", err);
    	}
    
    	err = dk_leds_init();
    	if (err) {
    		LOG_ERR("Cannot init LEDs (err: %d)", err);
    	}
    }
    
    /**@brief Zigbee stack event handler.
     *
     * @param[in]   bufid   Reference to the Zigbee stack buffer
     *                      used to pass signal.
     */
    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));
    
    	/* All callbacks should either reuse or free passed buffers.
    	 * If bufid == 0, the buffer is invalid (not passed).
    	 */
    	if (bufid) {
    		zb_buf_free(bufid);
    	}
    }
    
    void main(void)
    {
    	LOG_INF("Starting Zigbee application template example");
    
    	/* Initialize */
    	configure_gpio();
    	register_factory_reset_button(FACTORY_RESET_BUTTON);
    
    	/* Register device context (endpoints). */
    	ZB_AF_REGISTER_DEVICE_CTX(&app_template_ctx);
    
    	app_clusters_attr_init();
    
    	/* Register handlers to identify notifications */
    	ZB_AF_SET_IDENTIFY_NOTIFICATION_HANDLER(APP_TEMPLATE_ENDPOINT, identify_cb);
    
    	/* Start Zigbee default thread */
    	zigbee_enable();
    
    	LOG_INF("Zigbee application template started");
    }

  • Hi, 

    I follow the Adding ZCL clusters to application guide and include this file https://github.com/NordicPlayground/lgup-sdk-nrfxlib/blob/ae9013efd0cf07b565fc8569a6037f1b08dd0094/zboss/include/ha/zb_ha_temperature_sensor.h. I don't get any build error. Here is my test project template_sensor.7z for NCS v2.3.0.

    Beware that this code/configuration is not fully tested or qualified and should be considered provided “as-is”. Please test it with your application and let me know if you find any issues.

    Regards,
    Amanda H.

  • Thanks Amanda,

    I can also confirm that your project builds.

    However, you added this line which isn't part of the template and isn't covered by the guide. Where is ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR used? Adding this to my project fixes the problem.

    #define ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR 1

    Did you include zb_ha_temperature_sensor.h by copying the GitHub file into the Include folder manually, or can VSCode automatically pull that file from the SDK? I noticed that the light bulb sample has zb_dimmable_light.h in its include folder, and your project also has zb_ha_on_off_switch.h which would be needed for the first part of the Adding ZCL clusters to application guide, except that the guide doesn't mention including it.

    Kind regards,

    Dan

  • Hi, 

    I include zb_ha_temperature_sensor.h by copying the GitHub file into the Include folder manually as I suggested to you in the previous reply. I would suggest the team add the missing information. 

    -Amanda H.

  • Thanks Amanda,

    Your code builds but doesn't send any temperature sensor data to the coordinator.
    Does it transmit temperature data for you?

    Here is the Wireshark output from my Zigbee sniffer showing your code joining the network, followed by a heap of Link Status messages while I wait for the temperature to be sent.

    I decided to follow the same guide and your code to add temperature to the ZigBee light bulb example but that also doesn't output temperature, even though temperature has been added to the application.
    Here is the Wireshark output from my Zigbee sniffer showing the light turning on and off, followed by a heap of Link Status messages while I wait for the temperature to be sent.

    (filtering messages to and from the nRF52840DK address)

    Kind regards,
    Dan

Reply
  • Thanks Amanda,

    Your code builds but doesn't send any temperature sensor data to the coordinator.
    Does it transmit temperature data for you?

    Here is the Wireshark output from my Zigbee sniffer showing your code joining the network, followed by a heap of Link Status messages while I wait for the temperature to be sent.

    I decided to follow the same guide and your code to add temperature to the ZigBee light bulb example but that also doesn't output temperature, even though temperature has been added to the application.
    Here is the Wireshark output from my Zigbee sniffer showing the light turning on and off, followed by a heap of Link Status messages while I wait for the temperature to be sent.

    (filtering messages to and from the nRF52840DK address)

    Kind regards,
    Dan

Children
Related