Configuring Zigbee libraries in nRF Connect SDK

The Zigbee protocol in nRF Connect SDK can be customized by enabling and configuring several libraries.

This page lists options and steps required for configuring the available libraries.

Configuring default signal handler

The default signal handler provides a default logic to handle ZBOSS stack signals.

The default signal handler can be used by calling the zigbee_default_signal_handler() in the application’s zboss_signal_handler() implementation. For more information, see Zigbee default signal handler.

Configuring Zigbee FOTA

The Zigbee Over The Air Device Firmware Upgrade (Zigbee FOTA) library provides a mechanism to upgrade the firmware of the device through the Zigbee network.

To enable and configure the library, you must set the CONFIG_ZIGBEE_FOTA Kconfig option. Other Zigbee FOTA Kconfig options can be used with default values.

Because the Zigbee OTA DFU performs the upgrade using the DFU target library, the are several non-Zigbee options that must be set to configure the update process:

Configuring these options allows you to use Zigbee FOTA in the Zigbee: Light switch sample. Alternatively, you can use ota_overlay.conf file during the sample building process.

Enabling Zigbee FOTA in an application

If you want to use the Zigbee FOTA functionality in your application, you must add several code snippets to its main file:

  • Because the Zigbee OTA DFU library provides only the definition of the OTA endpoint, the application has to include it inside the device context:

    #include <zigbee_fota.h>
    extern zb_af_endpoint_desc_t ota_upgrade_client_ep;
    ZBOSS_DECLARE_DEVICE_CTX_2_EP(<your_device>_ctx, ota_upgrade_client_ep, <your_application>_ep);
    
  • The application is informed about the update status though a callback. The callback must reboot the device once the firmware update is completed:

    static void ota_evt_handler(const struct zigbee_fota_evt *evt)
    {
        switch (evt->id) {
        case ZIGBEE_FOTA_EVT_FINISHED:
            LOG_INF("Reboot application.");
            sys_reboot(SYS_REBOOT_COLD);
            break;
        }
    }
    
  • Apart from the library initialization, the application must pass ZCL events to the Zigbee FOTA library. If the application does not implement additional ZCL event handlers, the Zigbee FOTA handler may be passed directly to the ZBOSS stack:

    /* Initialize Zigbee FOTA download service. */
    zigbee_fota_init(ota_evt_handler);
    /* Register callback for handling ZCL commands. */
    ZB_ZCL_REGISTER_DEVICE_CB(zigbee_fota_zcl_cb);
    
  • The periodical OTA server discovery must be started from the signal handler. The application should pass the received signals to the Zigbee FOTA library:

    void zboss_signal_handler(zb_bufid_t bufid)
    {
        /* Pass signal to the OTA client implementation. */
        zigbee_fota_signal_handler(bufid);
        ...
    
  • To inform the MCUboot about successful device firmware upgrade, the application must call the following function once it is sure that all intended functionalities work after the upgrade:

    boot_write_img_confirmed();
    

See the samples/zigbee/light_switch/src/main.c file of the Zigbee: Light switch sample for an example implementation of the Zigbee FOTA in an application.

Generating Zigbee FOTA upgrade image

By enabling the Zigbee OTA DFU, the west tool will automatically generate the upgrade image. To specify the target device of the generated image, use the following Kconfig options:

The manufacturer ID, image type and version of the generated image are obtained from the application settings.

The upgrade image will be created in a dedicated directory in the build/zephyr/ directory.