nRF5 SDK for Thread and Zigbee v4.1.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 or join a new network when it leaves the previous one.

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.
ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid));
break;
}
if (bufid)
{
zb_buf_free(bufid);
}
}

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:

Once handling of the signal is finished, the stack will generate the ZB_BDB_SIGNAL_STEERING signal, and will continue to Zigbee network formation and commissioning.

signal_handler_03_first_start.png
Scenario for factory new devices (ZB_BDB_SIGNAL_DEVICE_FIRST_START)

Commissioned device scenario

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

Once finished, the stack will generate the ZB_BDB_SIGNAL_STEERING signal, and continue to Zigbee network formation and commissioning.

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.
    • When a device has joined and Zigbee network rejoining is running, the procedure is cancelled.
    • If no device has joined and the procedure is not running, the procedure will be started.
      signal_handler_06_steering.png
      Forming a network following the generation of ZB_BDB_SIGNAL_STEERING

Zigbee network leaving

The default signal handler implements the same behaviour for handling ZB_ZDO_SIGNAL_LEAVE for both routers and end devices. When leaving the network, the default handler calls start_network_rejoin() to start Zigbee network rejoining to join a new network.

Once start_network_rejoin() is called, the stack will generate the ZB_BDB_SIGNAL_STEERING signal and will continue to Zigbee network formation and commissioning.

signal_handler_09_leave.png
Leaving the network following ZB_ZDO_SIGNAL_LEAVE

Zigbee network rejoining

The Zigee network rejoin procedure is a mechanism that is similar to the ZDO rejoin backoff procedure. It is implemented to work with both routers and end devices and simplify handling of cases such as device joining, rejoining, or leaving the network. It is used in default_signal_handler() by default.

If the network is left by a router or an end device, the device will try to join any open network.

The Zigbee rejoin procedure retries to join a network with each try after a specified amount of time: 2^n seconds, where n is the number of retries. The period is limited to 15 minutes if the result is higher than that.

Warning
The Zigbee network rejoin procedure is managed from multiple signals in default_signal_handler(). If the application controls the network joining, rejoining, or leaving, each signal in which the Zigbee network rejoin procedure is managed should be handled in the application. In this case, user_input_indicate() must not be called.

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