In developing a Zigbee application, certain static configuration is required before the application is built. Configuring the network size, adding a new cluster, making the device discoverable and adding a new endpoint can be done by changing parameters in the following files:
These files are responsible for setting up network parameters like device type and associated parameters, mainly related to the APS and NWK layers of the ZigBee PRO stack.
Network Configuration
The ZigBee device can be configured to be a coordinator, router and end device. The following section details the way in which the user can configure each device type.
The app_zps_cfg header file lets the user configure the ZPS ZDO parameters of the node. The following macros are necessary for the corresponding device types:
#define ZPS_COORDINATOR
#define ZPS_ZDO_DEVICE_TYPE ZPS_ZDO_DEVICE_COORD
#define ZPS_ROUTER
#define ZPS_ZDO_DEVICE_TYPE ZPS_ZDO_DEVICE_ROUTER
#define ZPS_ENDDEVICE
#define ZPS_ZDO_DEVICE_TYPE ZPS_ZDO_DEVICE_ENDDEVICE
Other ZPS ZDO configurations which are defined using macro are explained in comments inside the header file (app_zps_cfg.h). These macros provide the user with the ability to configure the device according to their network needs.
The type of security for the ZigBee network can also be configured by the macro ZPS_ZDO_NWK_KEY_STATE. The user can change the security type to no network security (ZPS_ZDO_NO_NETWORK_KEY), pre-configured link key security (ZPS_ZDO_PRECONFIGURED_LINK_KEY), distributed link key security (ZPS_ZDO_DISTRIBUTED_LINK_KEY) or pre-configured installation code security (ZPS_ZDO_PRCONFIGURED_INSTALLATION_CODE).
/* Specify No network Security */ #define ZPS_ZDO_NWK_KEY_STATE ZPS_ZDO_NO_NETWORK_KEY
The application allows through this header file to configure ZPS APS AIB parameters, like extended PANID (ZPS_APS_AIB_INIT_USE_EXTENDED_PANID) or channel mask (ZPS_APS_AIB_INIT_CHANNEL_MASK).
/* NWK EXTENDED PANID (EPID) that the device will use.*/ #define ZPS_APS_AIB_INIT_USE_EXTENDED_PANID 0x0000000000000000ULL
/*! CHANNEL MASK : Define all channels from 11 to 26*/ #define ZPS_APS_AIB_INIT_CHANNEL_MASK 0x07fff800UL
User can also configure the simple descriptor table size (AF_SIMPLE_DESCRIPTOR_TABLE_SIZE) as part of the ZPS AF Layer configuration parameters.The value depends on number of endpoints defined in application, one endpoint is always reserved for ZDO . So, for a device with one endpoint, the value would be 2 (1 ZDO + 1 application endpoint)
#define AF_SIMPLE_DESCRIPTOR_TABLE_SIZE 2
Among other ZPS network configuration parameters that can be changed by the user are scan duration (ZPS_SCAN_DURATION), default permit joining time (ZPS_DEFAULT_PERMIT_JOINING_TIME) and the maximum number of simultaneous key requests (ZPS_MAX_NUM_SIMULTANEOUS_REQUEST_KEY_REQS).
Also, NIB values can be changed, like for example, the maximum number of routers in the network (ZPS_NWK_NIB_INIT_MAX_ROUTERS), the maximum number of children for a node (ZPS_NWK_NIB_INIT_MAX_CHILDREN), the maximum network depth (ZPS_NWK_NIB_INIT_MAX_DEPTH) or the network security level (ZPS_NWK_NIB_INIT_SECURITY_LEVEL).
Different ZigBee network table sizes can be adjusted by the user from this header file. The important tables are mentioned below:
ZCL Configuration
The app_zcl_cfg header file is used by the application to configure the ZigBee Cluster library. This file contains the definition for the application profile and cluster ids. The default application profiles are ZDP, HA, ZLO, GP.
The ZDP (ZigBee Device Profile) id is identified by the following line:
#define ZDP_PROFILE_ID (0x0000)
ZDP provides services for the following categories as cluster Ids:
The HA (Home Automation) profile id is identified by the following line:
#define HA_PROFILE_ID (0x0104)
HA provides services for the following categories as cluster Ids:
The ZLO (ZigBee Lighting and Occupancy) profile is not an application profile but devices in this collection use the same application profile id as for the Home Automation application profile. This ensures backward compatibility with applications for devices based on the Home Automation 1.2 profile.
ZigBee Green Power (GP) is an optional cluster with the aim of minimizing the power demands on a network node in order to support:
The GP profile id is identified by the following line:
#define GP_PROFILE_ID (0xa1e0)
The Zigbee GP cluster ID is defined as following:
#define GP_GREENPOWER_CLUSTER_ID (0x0021)
Depending on the application, the app_zcl_cfg header file also contains the defines for the node endpoints. For example, the occupancy_sensor application contains the following endpoints:
/* Node 'Coordinator' */
/* Endpoints */
#define COORDINATOR_ZDO_ENDPOINT (0)
#define COORDINATOR_COORD_ENDPOINT (1)
/* Node 'OccupancySensor' */
/* Endpoints */
#define OCCUPANCYSENSOR_ZDO_ENDPOINT (0)
#define OCCUPANCYSENSOR_SENSOR_ENDPOINT (1)
/* Node 'LightSensor' */
/* Endpoints */
#define LIGHTSENSOR_ZDO_ENDPOINT (0)
#define LIGHTSENSOR_SENSOR_ENDPOINT (1)
/* Node 'LightTemperatureOccupancySensor' */
/* Endpoints */
#define LIGHTTEMPERATUREOCCUPANCYSENSOR_ZDO_ENDPOINT (0)
#define LIGHTTEMPERATUREOCCUPANCYSENSOR_SENSOR_ENDPOINT (1)
The source file app_zcl_globals.c is used to declare the cluster lists for each endpoint. These act as simple descriptors for the node.
Each endpoint has two cluster lists, containing uint16_t data. One is for input and one for output. The sizes of these two lists must be equal. For example, for endpoint 0, the declared lists will be the following:
PRIVATE const uint16 s_au16Endpoint0InputClusterList[16] = { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006 , 0x0007, \
0x0008, 0x0010, 0x0011, 0x0012, 0x0012, 0x0013, 0x0014 , 0x0015};
PRIVATE const uint16 s_au16Endpoint0OutputClusterList[16] = { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006 , 0x0007, \
0x0008, 0x0010, 0x0011, 0x0012, 0x0012, 0x0013, 0x0014 , 0x0015};
The input list must also have a corresponding cluster APDU list, matching in size. For the endpoint 0 example, this will look like:
PRIVATE const PDUM_thAPdu s_ahEndpoint0InputClusterAPdus[16] = { apduZDP, apduZDP, apduZDP, apduZDP, apduZDP, apduZDP, apduZDP, apduZDP,\
apduZDP, apduZDP, apduZDP, apduZDP, apduZDP, apduZDP, apduZDP, apduZDP};
Each output and input cluster list has a corresponding cluster discovery enabled flags list. As each bit inside the Cluster Disc Flag corresponds to cluster , for 16 clusters declared in Input and Output cluster list, one needs 2 bytes for Discoverable flag. In this example, the declaration is the following:
PRIVATE uint8 s_au8Endpoint0InputClusterDiscFlags[2] = {0x1F, 0x08};
PRIVATE uint8 s_au8Endpoint0OutputClusterDiscFlags[2] = {0x08, 0x1B};
These parameters are registered in the node’s endpoints simple descriptor structure. The declared variable for the structure is s_asSimpleDescConts and its size depends on the number of endpoints available on the node. For example, for two endpoints, the declaration will be as below:
PUBLIC zps_tsAplAfSimpleDescCont s_asSimpleDescConts[2] = {
{
{
0x0000,
0,
0,
0,
84,
84,
s_au16Endpoint0InputClusterList,
s_au16Endpoint0OutputClusterList,
s_au8Endpoint0InputClusterDiscFlags,
s_au8Endpoint0OutputClusterDiscFlags,
},
s_ahEndpoint0InputClusterAPdus,
1
},
{
{
0x0104,
0,
0,
1,
6,
4,
s_au16Endpoint1InputClusterList,
s_au16Endpoint1OutputClusterList,
s_au8Endpoint1InputClusterDiscFlags,
s_au8Endpoint1OutputClusterDiscFlags,
},
s_ahEndpoint1InputClusterAPdus,
1
},
};
The AF Context definition is as below:
typedef struct _zps_tsAplAfSimpleDescCont
{
ZPS_tsAplAfSimpleDescriptor sSimpleDesc;
const PDUM_thAPdu *phAPduInClusters;
bool_t bEnabled;
} zps_tsAplAfSimpleDescCont;
And the endpoint simple descriptor has the following structure definition:
typedef struct {
uint16 u16ApplicationProfileId;
uint16 u16DeviceId;
uint8 u8DeviceVersion;
uint8 u8Endpoint;
uint8 u8InClusterCount;
uint8 u8OutClusterCount;
const uint16 *pu16InClusterList;
const uint16 *pu16OutClusterList;
uint8 *au8InDiscoveryEnabledFlags;
uint8 *au8OutDiscoveryEnabledFlags;
} ZPS_tsAplAfSimpleDescriptor;