nRF5 SDK for Thread and Zigbee v4.0.0
Zigbee application helper functions

Table of Contents

The nRF5 SDK for Thread and Zigbee provides several helper functions that are intended to facilitate the end user application implementation. They implement the default behavior of a Zigbee device and are used in the Zigbee examples in this SDK.

Zigbee default signal handler

The Zigbee default signal handler is a function called from the zboss_signal_handler() function that is mandatory for each application.

Because most of Zigbee devices behave in a similar way, zigbee_default_signal_handler() was introduced to provide a default logic to handle stack signals.

As a result, the minimal implementation of zboss_signal_handler includes only a call to the default signal handler:

{
/* Call default signal handler. */
zigbee_default_signal_handler(param);
/* Free the Zigbee stack buffer. */
zb_buf_free(param);
}

With this call, the device will be able to join the Zigbee network.

In general, using the default signal handler is worth considering, because of the following reasons:

Apart from that, the default signal handler serves as a good starting point for a custom signal handler implementation.

Complete zboss_signal_handler implementation

In its complete implementation, the zboss_signal_handler allows the application to control a broader set of basic functionalities, including joining, commissioning, and network formation.

There are in fact cases in which the default handler will not be sufficient and needs to be extended. For example, when the application wants to use the procedure of the initiator of finding & binding or use the production configuration feature.

If the application wants to change or extend the default behavior, use a switch-case statement and then the default signal handler inside the default case:

{
zb_zdo_app_signal_hdr_t * p_sg_p = NULL;
switch (sig)
{
/* fall-through */
if (status == RET_OK)
{
NRF_LOG_INFO("Joined network successfully");
// TODO: Start application-specific logic that requires the device to be connected to a Zigbee network.
}
else
{
zb_bool_t comm_status;
NRF_LOG_INFO("Unable to join the network. Restart network steering.");
ZB_COMM_STATUS_CHECK(comm_status);
}
break;
default:
// Call default signal handler.
zigbee_default_signal_handler(param);
break;
}
if (param)
{
zb_buf_free(param);
}
}

Zigbee stack startup without autostart

Whenever zigbee_default_signal_handler() is used, the stack should be started using a call to zboss_start_no_autostart():

The reason for this is that although the Zigbee stack provides some automatic initialization procedure with zboss_start(), the default signal handler requires the application to start the stack without those mechanisms.

Starting the stack with zboss_start_no_autostart() has the following advantages:

signal_handler_00_stack_init.png
Zigbee stack startup without autostart

When the stack is started through zboss_start_no_autostart(), the stack generates the following signals:

The reception of these signals determines the behavior of the default signal handler:

signal_handler_01_production_config.png
ZB_ZDO_SIGNAL_PRODUCTION_CONFIG_READY signal handler

Zigbee Base Device Behavior initialization

Once the BDB initialization procedure is finished, depending on the data stored inside the Zigbee persistent storage, the stack will complete one of the following scenarios:

Both scenarios will cause different behavior of the the default signal handler.

New device scenario

For factory new devices, the default signal handler will:

Commissioned device scenario

For devices that have been already commissioned, the default handler will:

signal_handler_04_reboot.png
Scenario for already commissioned devices (ZB_BDB_SIGNAL_DEVICE_REBOOT)

Zigbee network formation and commissioning

According to the logic implemented inside the default signal handler, the devices can either form a network or join an existing network:

  1. Coordinators will first form a network. Attempts to form the network will continue infinitely, with a one-second delay between each attempt.
    signal_handler_05_formation.png
    Forming a network following the generation of ZB_BDB_SIGNAL_FORMATION
    By default, after the successful network formation on the coordinator node, a single-permit join period of 180 seconds will be started, which will allow new Zigbee devices to join the network.
  2. Other devices will then join an existing network during this join period.
    signal_handler_06_steering.png
    Forming a network following the generation of ZB_BDB_SIGNAL_STEERING

Zigbee stack sleep routines

The Zigbee stack provides the following mechanisms to reduce power consumption:

On Zigbee sleepy end devices, the sleep_threshold period lasts approximately 15 ms by default and can be modified by using the zb_sleep_set_threshold API.

If the device implements a Zigbee sleepy end device, the ZB_COMMON_SIGNAL_CAN_SLEEP signal is generated whenever the device can be put into the deep sleep mode. This signal can also be handled using the Zigbee default signal handler. If so, it will allow the Zigbee stack to enter the deep sleep state.

If the default behavior is not applicable for the application, you can customize the sleep functionality by using the following options:


Documentation feedback | Developer Zone | Subscribe | Updated