Matter: Window covering

This sample demonstrates the usage of the Matter application layer to build a window covering device. This device works as a Matter accessory device, meaning it can be paired and controlled remotely over a Matter network built on top of a low-power 802.15.4 Thread network. Additionally, this device works as a Thread Synchronized Sleepy End Device (SSED).

Use this sample as a reference for developing your own application. See the Adding clusters to Matter application page for an overview of the process you need to follow.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF21540 DK

PCA10112

nrf21540dk_nrf52840

nrf21540dk_nrf52840

If you want to commission the window covering device and control it remotely through a Thread network, you also need a Matter controller device configured on PC or smartphone. This requires additional hardware depending on the setup you choose.

Note

Matter requires the GN tool. If you are updating from the nRF Connect SDK version earlier than v1.5.0, see the GN installation instructions.

Overview

The sample uses buttons for gradually changing the position and movement mode of the window cover, and LEDs to show the state of these changes. The following movement modes are available:

  • Lift - In this movement mode, the window cover moves up and down.

  • Tilt - In this movement mode, the window cover slats are tilted forward or backward without the cover moving vertically.

See User interface for information about how to switch the movement modes.

SSED device type

The SSED device type was created for the window covering devices to optimize the power usage of the device and communication pattern with the parent.

A Thread Synchronized Sleepy End Device (SSED) is synchronized with its parent router and uses the radio only at scheduled intervals, by using the Coordinated Sampled Listening (CSL) feature introduced as one of Thread 1.2 Base Features. During those intervals, the device waits for the router to send it any data related to the desired device activity. The SSED does require sending packets occasionally to keep synchronization with the router. However, unlike a regular SED, an SSED does not actively communicate with the router by polling and goes into the idle mode in-between the scheduled activity periods. If there is no application-related traffic for a longer period of time, the SSED sends a data poll request packet to synchronize with the parent. Overall, the SSED features further reduce energy consumption of the device and generate less data traffic compared to a standard Thread SED.

Comparison of Thread SED and Thread SSED radio activity

Comparison of Thread SED and Thread SSED radio activity

Sample testing

You can test the sample in the following ways:

  • Standalone, using a single DK that runs the window covering application.

  • Remotely over the Thread protocol, which requires more devices.

The remote control testing requires a Matter controller that you can configure either on a PC or mobile device (for remote testing in a network). You can enable both methods after building and running the sample.

Remote testing in a network

By default, the Matter accessory device has Thread disabled. You must pair it with the Matter controller over Bluetooth® LE to get the configuration from the controller to use the device within a Thread network. The controller must get the commissioning information from the Matter accessory device and provision the device into the network. For details, see the Commissioning the device section.

Configuration

See Configuring your application for information about how to permanently or temporarily change the configuration.

Matter window covering build types

The sample uses different configuration files depending on the supported features. Configuration files are provided for different build types and they are located in the application root directory.

The prj.conf file represents a debug build type. Other build types are covered by dedicated files with the build type added as a suffix to the prj part, as per the following list. For example, the release build type file name is prj_release.conf. If a board has other configuration files, for example associated with partition layout or child image configuration, these follow the same pattern.

When the CONF_FILE variable contains a single file and this file follows the naming pattern prj_<buildtype>.conf, then the build type will be inferred to be <buildtype>. The build type cannot be set explicitly. The <buildtype> can be any string, but it is common to use release and debug.

For information about how to set variables, see Important Build System Variables in the Zephyr documentation.

The Partition Manager’s static configuration can also be made dependent on the build type. When the build type has been inferred, the file pm_static_<buildtype>.yml will have precedence over pm_static.yml.

The child image Kconfig configuration can also be made dependent on the build type. The child image Kconfig file is named <child_image>.conf instead of prj.conf, but otherwise follows the same pattern as the parent Kconfig.

Before you start testing the application, you can select one of the build types supported by the sample. This sample supports the following build types, depending on the selected board:

  • debug – Debug version of the application - can be used to enable additional features for verifying the application behavior, such as logs or command-line shell.

  • release – Release version of the application - can be used to enable only the necessary application functionalities to optimize its performance.

  • no_dfu – Debug version of the application without Device Firmware Upgrade feature support - can be used for the nRF52840 DK, nRF5340 DK, and nRF21540 DK.

Note

Selecting a build type is optional. The debug build type is used by default if no build type is explicitly selected.

Device Firmware Upgrade support

Note

You can enable over-the-air Device Firmware Upgrade only on hardware platforms that have external flash memory. Currently only nRF52840 DK and nRF5340 DK support Device Firmware Upgrade feature.

The sample supports over-the-air (OTA) device firmware upgrade (DFU) using one of the two following protocols:

  • Matter OTA update protocol that uses the Matter operational network for querying and downloading a new firmware image.

  • Simple Management Protocol (SMP) over Bluetooth® LE. In this case, the DFU can be done either using a smartphone application or a PC command line tool. Note that this protocol is not part of the Matter specification.

In both cases, MCUboot secure bootloader is used to apply the new firmware image.

The DFU over Matter is enabled by default. The following configuration arguments are available during the build process for configuring DFU:

  • To configure the sample to support the DFU over Matter and SMP, use the -DCONFIG_CHIP_DFU_OVER_BT_SMP=y build flag.

  • To configure the sample to disable the DFU and the secure bootloader, use the -DCONF_FILE=prj_no_dfu.conf build flag.

See Providing CMake options for instructions on how to add these options to your build.

When building on the command line, run the following command with build_target replaced with the build target name of the hardware platform you are using (see Requirements), and dfu_build_flag replaced with the desired DFU build flag:

west build -b build_target -- dfu_build_flag

For example:

west build -b nrf52840dk_nrf52840 -- -DCONFIG_CHIP_DFU_OVER_BT_SMP=y

FEM support

You can add support for the nRF21540 front-end module to this sample by using one of the following options, depending on your hardware:

  • Build the sample for one board that contains the nRF21540 FEM, such as nrf21540dk_nrf52840.

  • Manually create a devicetree overlay file that describes how FEM is connected to the nRF5 SoC in your device. See Set devicetree overlays for different ways of adding the overlay file.

  • Provide nRF21540 FEM capabilities by using a shield, for example the nRF21540 EK shield that is available in the nRF Connect SDK. In this case, build the project for a board connected to the shield you are using with an appropriate variable included in the build command. This variable instructs the build system to append the appropriate devicetree overlay file. For example, to build the sample from the command line for an nRF52833 DK with the nRF21540 EK attached, use the following command within the sample directory:

    west build -b nrf52833dk_nrf52833 -- -DSHIELD=nrf21540_ek
    

    This command builds the application firmware. See Programming nRF21540 EK for information about how to program when you are using a board with a network core, for example nRF5340 DK.

Each of these options adds the description of the nRF21540 FEM to the devicetree. See Working with RF front-end modules for more information about FEM in the nRF Connect SDK.

To add support for other front-end modules, add the respective devicetree file entries to the board devicetree file or the devicetree overlay file.

User interface

LED 1:

Shows the overall state of the device and its connectivity. The following states are possible:

  • Short Flash On (50 ms on/950 ms off) - The device is in the unprovisioned (unpaired) state and is waiting for a commissioning application to connect.

  • Rapid Even Flashing (100 ms on/100 ms off) - The device is in the unprovisioned state and a commissioning application is connected over Bluetooth LE.

  • Solid On - The device is fully provisioned.

LED 2:

Indicates the lift position of the window cover, which is represented by the brightness of the LED. The brightness level ranges from 0 to 255, where the brightness level set to 0 (switched off LED) indicates a fully opened window cover (lifted) and the brightness level set to 255 indicates a fully closed window cover (lowered).

Additionally, the LED starts blinking evenly (500 ms on/500 ms off) when the Identify command of the Identify cluster is received on the endpoint 1. The command’s argument can be used to specify the duration of the effect.

LED 3:

Indicates the tilt position of the window cover, which is represented by the brightness of the LED. The brightness level ranges from 0 to 255, where the brightness level set to 0 (switched off LED) indicates a fully opened window cover (tilted to a horizontal position) and the brightness level set to 255 indicates a fully closed window cover (tilted to a vertical position).

Button 1:

Depending on how long you press the button:

  • If pressed for less than three seconds, it initiates the SMP server (Security Manager Protocol). After that, the Direct Firmware Update (DFU) over Bluetooth Low Energy can be started. (See Upgrading the device firmware.)

  • If pressed for more than three seconds, it initiates the factory reset of the device. Releasing the button within the 3-second window cancels the factory reset procedure.

Button 2:

When pressed once and released, it moves the window cover towards the open position by one step. Depending on the movement mode of the cover (see Overview), the button decreases the brightness of either LED 2 for the lift mode or LED 3 for the tilt mode.

Button 3:

When pressed once and released, it moves the cover towards the closed position by one step. Depending on the movement mode of the cover (see Overview), the button increases the brightness of either LED 2 for the lift mode or LED 3 for the tilt mode.

Button 2 and Button 3:

When pressed at the same time, they toggle the cover movement mode between lift and tilt. After each device reset, the mode is set to lift by default.

Note

Completely opening and closing the cover requires 20 button presses (steps). Each step takes approximately 200 ms to simulate the real window cover movement. The cover position and the LED brightness values are stored in non-volatile memory and are restored after every device reset. After the firmware update or factory reset both LEDs are switched off by default, which corresponds to the cover being fully open, both lift-wise and tilt-wise.

Button 4:

Starts the NFC tag emulation, enables Bluetooth LE advertising for the predefined period of time (15 minutes by default), and makes the device discoverable over Bluetooth LE. This button is used during the commissioning procedure.

SEGGER J-Link USB port:

Used for getting logs from the device or for communicating with it through the command-line interface.

NFC port with antenna attached:

Optionally used for obtaining the commissioning information from the Matter accessory device to start the commissioning procedure.

Building and running

This sample can be found under samples/matter/window_covering in the nRF Connect SDK folder structure.

To build the sample with Visual Studio Code, follow the steps listed on the Building nRF Connect SDK application quick guide page in the nRF Connect for VS Code extension documentation. See Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.

Selecting a build type

Before you start testing the application, you can select one of the Matter window covering build types, depending on your building method.

Selecting a build type in Visual Studio Code

To select the build type in the nRF Connect for VS Code extension:

  1. When Building an application as described in the nRF Connect for VS Code extension documentation, follow the steps for setting up the build configuration.

  2. In the Add Build Configuration screen, select the desired .conf file from the Configuration drop-down menu.

  3. Fill in other configuration options, if applicable, and click Build Configuration.

Selecting a build type from command line

To select the build type when building the application from command line, specify the build type by adding the following parameter to the west build command:

-- -DCONF_FILE=prj_selected_build_type.conf

For example, you can replace the selected_build_type variable to build the release firmware for nrf52840dk_nrf52840 by running the following command in the project directory:

west build -b nrf52840dk_nrf52840 -d build_nrf52840dk_nrf52840 -- -DCONF_FILE=prj_release.conf

The build_nrf52840dk_nrf52840 parameter specifies the output directory for the build files.

Note

If the selected board does not support the selected build type, the build is interrupted. For example, if the shell build type is not supported by the selected board, the following notification appears:

File not found: ./ncs/nrf/samples/matter/window_covering/configuration/nrf52840dk_nrf52840/prj_shell.conf

Testing

After building the sample and programming it to your development kit, complete the following steps to test its basic features:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator that supports VT100/ANSI escape characters (for example, PuTTY). See How to connect with PuTTY for the required settings.

  3. Observe that LED 2 and LED 3 are turned off, which means that the window cover is fully open. The device starts in the lift movement mode by default.

  4. Press Button 3 20 times to fully close the cover in the lift movement mode. LED 2 lights up and its brightness increases with each button press until it reaches full brightness.

  5. Press Button 2 20 times to fully lift the cover up. The brightness of LED 2 decreases with each button press until the LED turns off.

  6. Press Button 2 and Button 3 together to switch into the tilt movement mode.

  7. Press Button 3 20 times to fully tilt the cover into the closed position. LED 3 light up and its brightness increases with each button press until it reaches full brightness.

  8. Press Button 2 20 times to fully tilt the cover into the open position. The brightness of LED 3 decreases with each button press until the LED turns off.

  9. Press Button 1 to initiate the factory reset of the device.

The device reboots after all its settings are erased.

Enabling remote control

Remote control allows you to control the Matter window covering device from a Thread network.

Commissioning the device allows you to set up a testing environment and remotely control the sample over a Matter-enabled Thread network.

Commissioning the device

To commission the device, go to the Testing Matter in the nRF Connect SDK page and complete the steps for the Matter over Thread development environment and the Matter controller you want to use. After choosing the environment configuration, the guide walks you through the following steps:

  • Configure the Thread Border Router.

  • Build and install the Matter controller.

  • Commission the device.

  • Send Matter commands that cover scenarios described in the Testing section.

If you are new to Matter, the recommended approach is to use CHIP Tool for Linux or macOS.

Before starting the commissioning procedure, the device must be made discoverable over Bluetooth LE. Press Button 4 to enable the Bluetooth LE advertising.

When you start the commissioning procedure, the controller must get the commissioning information from the Matter accessory device. The data payload includes the device discriminator and setup PIN code. It is encoded within a QR code printed to the UART console and can be shared using an NFC tag.

Upgrading the device firmware

To upgrade the device firmware, complete the steps listed for the selected method in the Performing Device Firmware Upgrade in the nRF Connect examples tutorial of the Matter documentation.

Dependencies

This sample uses the Matter library that includes the nRF Connect SDK platform integration layer:

In addition, the sample uses the following nRF Connect SDK components:

The sample depends on the following Zephyr libraries: