Matter: Template
This sample demonstrates a minimal implementation of the Matter application layer. This basic implementation enables the commissioning on the device, which allows it to join a Matter network built on top of a low-power, 802.15.4 Thread network or on top of a Wi-Fi network. Support for both Thread and Wi-Fi is mutually exclusive and depends on the hardware platform, so only one protocol can be supported for a specific Matter device. In case of Thread, this device works as a Thread Minimal End Device.
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 |
Board target |
Shields |
---|---|---|---|---|
PCA10143 |
|
|||
PCA10156 |
|
|||
nRF54L15 DK |
PCA10156 |
|
||
PCA10175 |
|
|
||
PCA10095 |
|
|||
PCA10056 |
|
For testing purposes, that is to commission the 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.
IPv6 network support
The development kits for this sample offer the following IPv6 network support for Matter:
Matter over Thread is supported for
nrf52840dk/nrf52840
,nrf5340dk/nrf5340/cpuapp
,nrf21540dk/nrf52840
,nrf54l15dk/nrf54l15/cpuapp
, andnrf54h20dk/nrf54h20/cpuapp
.Matter over Wi-Fi is supported for
nrf5340dk/nrf5340/cpuapp
ornrf54h20dk/nrf54h20/cpuapp
with thenrf7002ek
shield attached, or fornrf7002dk/nrf5340/cpuapp
.
Overview
The sample starts the Bluetooth® LE advertising automatically and prepares the Matter device for commissioning into a Matter-enabled Thread network. The sample uses an LED to show the state of the connection. You can press a button to start the factory reset when needed.
Remote testing in a network
Testing in either a Matter-enabled Thread or a Wi-Fi network requires a Matter controller that you can configure on PC or mobile device. By default, the Matter accessory device has IPv6 networking disabled. You must pair the device with the Matter controller over Bluetooth® LE to get the configuration from the controller to use the device within a Thread or a Wi-Fi network. You can enable the controller after building and running the sample.
To pair the device, the controller must get the Onboarding information from the Matter accessory device and commission the device into the network.
Commissioning in Matter
In Matter, the commissioning procedure takes place over Bluetooth LE between a Matter accessory device and the Matter controller, where the controller has the commissioner role. When the procedure has completed, the device is equipped with all information needed to securely operate in the Matter network.
During the last part of the commissioning procedure (the provisioning operation), the Matter controller sends the Thread or Wi-Fi network credentials to the Matter accessory device. As a result, the device can join the IPv6 network and communicate with other devices in the network.
Onboarding information
When you start the commissioning procedure, the controller must get the onboarding information from the Matter accessory device. The onboarding information representation depends on your commissioner setup.
For this sample, you can use one of the following onboarding information formats to provide the commissioner with the data payload that includes the device discriminator and the setup PIN code:
QR Code
QR Code Payload
Manual pairing code
Scan the following QR code with the app for your ecosystem:
MT:Y.K9042C00KA0648G00
34970112332
When the factory data support is enabled, the onboarding information will be stored in the build directory in the following files:
The
factory_data.png
file includes the generated QR code.The
factory_data.txt
file includes the QR Code Payload and the manual pairing code.
This data payload also includes test Device Attestation, with test Certification Declaration, Product ID, and Vendor ID. These are used for Device Attestation within commissioning, and you can generate your own test Certification Declaration when you work on Matter end product.
Configuration
See Configuring and building for information about how to permanently or temporarily change the configuration.
Matter template custom configurations
The sample uses a prj.conf
configuration file located in the sample root directory for the default configuration.
It also provides additional files for different custom configurations.
When you build the sample, you can select one of these configurations using the FILE_SUFFIX variable.
See Custom configurations and Providing CMake options for more information.
The sample supports the following configurations:
Configuration |
File name |
FILE_SUFFIX |
Supported board |
Description |
---|---|---|---|---|
Debug (default) |
|
No suffix |
All from Requirements |
Debug version of the application. Enables additional features for verifying the application behavior, such as logs. |
Release |
|
|
All from Requirements |
Release version of the application. Enables only the necessary application functionalities to optimize its performance. |
Matter template with Trusted Firmware-M
The sample supports using Trusted Firmware-M on the nRF54L15 DK. The memory map of the sample has been aligned to meet the TF-M partition alignment requirements.
You can build the sample with Trusted Firmware-M support by adding the ns
suffix to the nrf54l15pdk/nrf54l15/cpuapp
build target.
For example:
west build -p -b nrf54l15pdk/nrf54l15/cpuapp/ns
Note
The firmware built for nrf54l15pdk/nrf54l15/cpuapp/ns
will not work on the nRF54L15 DK.
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, nRF5340 DK, nRF7002 DK and nRF54L15 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.
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 board_target replaced with the board 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 board_target -- dfu_build_flag
For example:
west build -b nrf52840dk/nrf52840 -- -DCONFIG_CHIP_DFU_OVER_BT_SMP=y
Alternatively, for the nRF54L15 DK, the DFU can be configured to only use the internal MRAM for storage. This means that both the currently running firmware and the new firmware to be updated will be stored within the device’s internal flash memory. This configuration is only available for the release configuration.
The following is an example command to build the sample on the nRF54L15 DK with support for Matter OTA DFU and DFU over Bluetooth® SMP, and using internal MRAM only:
west build -p -b nrf54l15dk/nrf54l15/cpuapp -- -DFILE_SUFFIX=release -DCONFIG_CHIP_DFU_OVER_BT_SMP=y -DPM_STATIC_YML_FILE=pm_static_nrf54l15dk_nrf54l15_cpuapp_internal.yml -Dmcuboot_EXTRA_CONF_FILE=<absolute_path_to_the_template_sample>/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp_internal.conf -Dmcuboot_EXTRA_DTC_OVERLAY_FILE=<absolute_path_to_the_template_sample>/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp_internal.overlay
Note that in this case, the size of the application partition is half of what it would be when using a configuration with external flash memory support.
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 Developing with 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, for example
SHIELD=nrf21540ek
. This variable instructs the build system to append the appropriate devicetree overlay file.To build the sample in the nRF Connect for VS Code IDE for an nRF52840 DK with the nRF21540 EK attached, add the shield variable in the build configuration’s Extra CMake arguments and rebuild the build configuration. For example:
-DSHIELD=nrf21540ek
.See nRF Connect for VS Code extension pack documentation for more information.
To build the sample from the command line for an nRF52840 DK with the nRF21540 EK attached, use the following command within the sample directory:
west build -b nrf52840dk/nrf52840 -- -DSHIELD=nrf21540ek
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 Developing with 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.
Factory data support
In this sample, the factory data support is enabled by default for all configurations except for the target board nRF21540 DK. This means that a new factory data set will be automatically generated when building for the target board.
To disable factory data support, set the following Kconfig options to n
:
SB_CONFIG_MATTER_FACTORY_DATA_GENERATE
To learn more about factory data, read the Configuring factory data for the nRF Connect examples page in the Matter documentation.
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.
- Button 1:
Depending on how long you press the button:
If pressed for less than three seconds:
If the device is not provisioned to the Matter network, it initiates the SMP server (Simple Management Protocol) and Bluetooth LE advertising for Matter commissioning. After that, the Device Firmware Update (DFU) over Bluetooth Low Energy can be started. (See Upgrading the device firmware.) Bluetooth LE advertising makes the device discoverable over Bluetooth LE for the predefined period of time (1 hour by default).
If the device is already provisioned to the Matter network, it re-enables the SMP server. After that, the 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 a 3-second window of the initiation cancels the factory reset procedure.
- SEGGER J-Link USB Port:
Used for getting logs from the device or for communicating with it through the command-line interface.
- LED 0:
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.
- Button 0:
Depending on how long you press the button:
If pressed for less than three seconds:
If the device is not provisioned to the Matter network, it initiates the SMP server (Simple Management Protocol) and Bluetooth LE advertising for Matter commissioning. After that, the Device Firmware Update (DFU) over Bluetooth Low Energy can be started. (See Upgrading the device firmware.) Bluetooth LE advertising makes the device discoverable over Bluetooth LE for the predefined period of time (1 hour by default).
If the device is already provisioned to the Matter network, it re-enables the SMP server. After that, the 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 a 3-second window of the initiation cancels the factory reset procedure.
- SEGGER J-Link USB Port:
Used for getting logs from the device or for communicating with it through the command-line interface.
Building and running
This sample can be found under samples/matter/template
in the nRF Connect SDK folder structure.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild
parameter to every build command or configure west to always use it.
To use nrf54H20 DK with the nrf7002ek
shield attached (2.4 GHz or 5 GHz), follow the Developing with nRF7002 EB user guide to connect all required pins and then use the following command to build the sample:
west build -b nrf54h20dk/nrf54h20/cpuapp -p -- -DSB_CONFIG_WIFI_NRF700X=y -DCONFIG_CHIP_WIFI=y -Dtemplate_SHIELD=nrf700x_nrf54h20dk
Selecting a configuration
Before you start testing the application, you can select one of the Matter template custom configurations. See Custom configurations and Providing CMake options for more information how to select a configuration.
Testing
When you have built the sample and programmed it to your development kit, it automatically starts the Bluetooth LE advertising and the LED 1 starts flashing (Short Flash On). At this point, you can press Button 1 for six seconds to initiate the factory reset of the device.
When you have built the sample and programmed it to your development kit, it automatically starts the Bluetooth LE advertising and the LED 0 starts flashing (Short Flash On). At this point, you can press Button 0 for six seconds to initiate the factory reset of the device.
Testing in a network
To test the sample in a Matter-enabled Thread network, complete the following steps:
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.
Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Commission the device into a Matter network by following the guides linked on the Testing Matter in the nRF Connect SDK page for the Matter controller you want to use. The guides walk you through the following steps:
Only if you are configuring Matter over Thread: Configure the Thread Border Router.
Build and install the Matter controller.
Commission the device. You can use the Onboarding information listed earlier on this page.
Send Matter commands.
At the end of this procedure, LED 1 of the Matter device programmed with the sample starts flashing in the Short Flash Off state. This indicates that the device is fully provisioned, but does not yet have full IPv6 network connectivity.
Keep the Button 1 pressed for more than six seconds to initiate factory reset of the device.
The device reboots after all its settings are erased.
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.
Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Commission the device into a Matter network by following the guides linked on the Testing Matter in the nRF Connect SDK page for the Matter controller you want to use. The guides walk you through the following steps:
Only if you are configuring Matter over Thread: Configure the Thread Border Router.
Build and install the Matter controller.
Commission the device. You can use the Onboarding information listed earlier on this page.
Send Matter commands.
At the end of this procedure, LED 0 of the Matter device programmed with the sample starts flashing in the Short Flash Off state. This indicates that the device is fully provisioned, but does not yet have full IPv6 network connectivity.
Keep the Button 0 pressed for more than six seconds to initiate factory reset of the device.
The device reboots after all its settings are erased.
The device reboots after all its settings are erased.
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: