Logo
Developing with ZBOSS for Zigbee

Macros

#define ZB_SE_DEVICE_VER_METERING   0
 Metering device version.
 
#define SUB_GHZ_CLUSTER_ENABLED_ID
 
#define ZB_ZCL_SUBGHZ_CLUSTER_DESC_CLIENT()
 
#define ZB_SE_DECLARE_METERING_DEV_CLUSTER_LIST(cluster_list_name, basic_attr_list, kec_attr_list, identify_attr_list, metering_attr_list, prepayment_attr_list)
 Declare clusters list for Metering device. More...
 
#define ZB_SE_DECLARE_METERING_DEV_EP(ep_name, ep_id, cluster_list)
 Declare endpoint for Metering device. More...
 
#define ZB_SE_DECLARE_METERING_DEV_CTX(device_ctx_name, ep_name)
 Declare Metering device context. More...
 

Detailed Description

The Metering end device is a meter (electricity, gas, water, heat, etc.) that is fitted with a Zigbee device. Depending on what is being metered, the device may be capable of immediate (requested) reads or it will autonomously send readings periodically. A Metering end device may also be capable of communicating certain status indicators (e.g. battery low, tamper detected).

Supported Clusters
Metering Device has X clusters (see SE spec 1.4 subclauses 6.1, 6.3.2.1):
Server roles Client roles
ZCL Basic cluster SE Key Establishment Cluster
SE Key Establishment Cluster ZCL Keep Alive Cluster (optional)
ZCL Metering Cluster ZCL Tunneling cluster (optional)
ZCL Identify cluster (optional)
SE Events cluster (optional)
SE Prepayment cluster (optional)
Example

Declare clusters
/**
* Declaring attributes for each cluster
*/
/* Basic cluster attributes */
ZB_ZCL_DECLARE_BASIC_ATTR_LIST(basic_attr_list, g_dev_ctx.basic_attrs);
/* Key Establishment cluster attributes */
ZB_ZCL_DECLARE_KEC_ATTR_LIST(kec_attr_list, g_dev_ctx.kec_attrs);
/* Identify cluster attributes */
ZB_ZCL_DECLARE_IDENTIFY_ATTR_LIST(identify_attr_list, g_dev_ctx.identify_attrs);
/* Metering cluster attributes */
ZB_ZCL_DECLARE_METERING_ATTR_LIST(metering_attr_list, g_dev_ctx.metering_attrs);
/* Metering cluster attributes */
ZB_ZCL_DECLARE_PREPAYMENT_ATTR_LIST(prepayment_attr_list, g_dev_ctx.prepayment_attrs);
/* Declare SE cluster list for the device */
basic_attr_list,
kec_attr_list,
identify_attr_list,
metering_attr_list,
prepayment_attr_list);
/* Declare endpoint */
ZB_SE_DECLARE_METERING_DEV_EP(metering_dev_ep, METERING_DEV_ENDPOINT, metering_dev_clusters);
/* Declare device context */
ZB_SE_DECLARE_METERING_DEV_CTX(metering_dev_zcl_ctx, metering_dev_ep);

Register device context
/* Register device ZCL context */
ZB_AF_REGISTER_DEVICE_CTX(&metering_dev_zcl_ctx);

Signal handler example
/* Application signal handler. Used for informing application about important ZBOSS
* events/states (device started first time/rebooted, key establishment completed etc).
* Application may ignore signals in which it is not interested.
*/
{
if (ZB_GET_APP_SIGNAL_STATUS(param) == 0)
{
switch (sig)
{
if (zb_buf_len(param) > sizeof(zb_zdo_app_signal_hdr_t))
{
se_app_production_config_t *prod_cfg =
ZB_ZDO_SIGNAL_GET_PARAMS(sg_p, se_app_production_config_t);
TRACE_MSG(TRACE_APP1, "Loading application production config", (FMT__0));
if (prod_cfg->version == SE_APP_PROD_CFG_CURRENT_VERSION)
{
zb_set_node_descriptor_manufacturer_code_req(prod_cfg->manuf_code, NULL);
}
}
break;
TRACE_MSG(TRACE_APP1, "ZB_ZDO_SIGNAL_SKIP_STARTUP: boot, not started yet", (FMT__0));
/* This call is here because reporting configuration is saved to nvram, so it must be called after nvram loaded. */
metering_dev_default_reporting_init(0);
zboss_start_continue();
break;
/* wait button click to start commissioning */
TRACE_MSG(TRACE_APP1, "ZB_SE_SIGNAL_SKIP_JOIN", (FMT__0));
#ifdef ZB_USE_BUTTONS
zb_button_register_handler(BUTTON_LEFT, 0, metering_dev_left_button_handler);
zb_button_register_handler(BUTTON_RIGHT, 16, metering_dev_right_button_handler);
#else
metering_dev_left_button_handler(0);
#endif
break;
zb_se_indicate_commissioning_started();
break;
case ZB_SIGNAL_DEVICE_FIRST_START:
case ZB_SIGNAL_DEVICE_REBOOT:
TRACE_MSG(TRACE_APP1, "Device STARTED OK: first_start %hd",
(FMT__H, sig == ZB_SIGNAL_DEVICE_FIRST_START));
{
TRACE_MSG(TRACE_APP1, "TCLK: " TRACE_FORMAT_128, (FMT__B, TRACE_ARG_128(key)));
TRACE_MSG(TRACE_APP1, "NWK key: " TRACE_FORMAT_128, (FMT__B, TRACE_ARG_128(key)));
TRACE_MSG(TRACE_APP1, "TCLK by installcode: " TRACE_FORMAT_128, (FMT__B, TRACE_ARG_128(key)));
}
ZB_SCHEDULE_APP_CALLBACK(metering_dev_measure, 0);
zb_se_indicate_default_start();
break;
TRACE_MSG(TRACE_APP1, "ZB_SE_SIGNAL_CBKE_OK: Key Establishment with Trust Center (CBKE) OK", (FMT__0));
break;
#if defined ZB_USE_BUTTONS
if (dev_sd_start_enabled == ZB_FALSE) {
break;
}
#endif
TRACE_MSG(TRACE_APP1, "Start Service Discovery", (FMT__0));
zb_se_service_discovery_start(METERING_DEV_ENDPOINT);
zb_se_indicate_service_discovery_started();
break;
{
TRACE_MSG(TRACE_APP1, "can bind cluster %d commodity_type %d remote_dev " TRACE_FORMAT_64,
(FMT__D_D_A, bind_params->cluster_id, bind_params->commodity_type,
TRACE_ARG_64(bind_params->device_addr)));
{
/* Do not bind, but request tunnel to this dev */
g_dev_ctx.metering_tunneling.srv_addr = zb_address_short_by_ieee(bind_params->device_addr);
g_dev_ctx.metering_tunneling.srv_ep = bind_params->endpoint;
ZB_SCHEDULE_APP_CALLBACK(metering_dev_request_tunnel, param);
param = 0;
}
}
break;
{
TRACE_MSG(TRACE_APP1, "Bind dev 0x%x OK", (FMT__D, *addr));
break;
}
TRACE_MSG(TRACE_APP1, "Service Discovery OK", (FMT__0));
zb_se_indicate_commissioning_stopped();
break;
TRACE_MSG(TRACE_APP1, "Service Discovery failed", (FMT__0));
zb_se_indicate_commissioning_fail(0, /* erase nvram */
0); /* reboot */
break;
TRACE_MSG(TRACE_APP1, "sub-ghz. TX suspended", (FMT__0));
s_tx_suspended = 1;
break;
TRACE_MSG(TRACE_APP1, "sub-ghz. TX resumed", (FMT__0));
s_tx_suspended = 0;
break;
/* skip*/
break;
default:
TRACE_MSG(TRACE_APP1, "zboss_signal_handler: skip sig %hd status %hd",
(FMT__H_H_H, param, sig, ZB_GET_APP_SIGNAL_STATUS(param)));
break;
}
}
{
TRACE_MSG(TRACE_APP1, "Production config is not present or invalid", (FMT__0));
}
else
{
zb_se_indicate_commissioning_fail(0, /* erase nvram */
0); /* reboot */
TRACE_MSG(TRACE_ERROR, "Device started FAILED status %d", (FMT__D, ZB_GET_APP_SIGNAL_STATUS(param)));
}
SE_APP_AUX_SIGNAL_HANDLER(param);
if (param)
{
zb_buf_free(param);
}
}

Macro Definition Documentation

§ ZB_SE_DECLARE_METERING_DEV_CLUSTER_LIST

#define ZB_SE_DECLARE_METERING_DEV_CLUSTER_LIST (   cluster_list_name,
  basic_attr_list,
  kec_attr_list,
  identify_attr_list,
  metering_attr_list,
  prepayment_attr_list 
)

Declare clusters list for Metering device.

Parameters
cluster_list_name- cluster list variable name
basic_attr_list- attribute list for Basic cluster
kec_attr_list- attribute list for Key Establishment cluster
identify_attr_list- attribute list for Identify cluster
metering_attr_list- attribute list for Metering cluster
prepayment_attr_list- attribute list for Prepayment cluster

§ ZB_SE_DECLARE_METERING_DEV_CTX

#define ZB_SE_DECLARE_METERING_DEV_CTX (   device_ctx_name,
  ep_name 
)
Value:
ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_##device_ctx_name) \
&ep_name, \
ZB_AF_FINISH_DECLARE_ENDPOINT_LIST; \
ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_##device_ctx_name, \
ZB_ZCL_ARRAY_SIZE(ep_list_##device_ctx_name, zb_af_endpoint_desc_t*))
Endpoint descriptor.
Definition: zboss_api_af.h:339
#define ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_name)
Definition: zboss_api_af.h:415

Declare Metering device context.

Parameters
device_ctx_name- device context variable name.
ep_name- endpoint variable name.

§ ZB_SE_DECLARE_METERING_DEV_EP

#define ZB_SE_DECLARE_METERING_DEV_EP (   ep_name,
  ep_id,
  cluster_list 
)
Value:
ZB_ZCL_DECLARE_METERING_DEV_SIMPLE_DESC(ep_name, \
ep_id, \
ZB_SE_METERING_DEV_IN_CLUSTER_NUM, \
ZB_SE_METERING_DEV_OUT_CLUSTER_NUM, \
SUB_GHZ_CLUSTER_ENABLED_ID); \
ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## ep_name, \
ZB_SE_METERING_DEV_REPORT_ATTR_COUNT); \
ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, \
ep_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_SE_METERING_DEV_REPORT_ATTR_COUNT, reporting_info##ep_name, \
0, NULL) \
ZCL cluster description.
Definition: zb_zcl_common.h:129
#define ZB_AF_SE_PROFILE_ID
Definition: zboss_api_af.h:297

Declare endpoint for Metering device.

Parameters
ep_name- endpoint variable name
ep_id- endpoint ID
cluster_list- endpoint cluster list