Matter weather station
The Matter weather station application demonstrates the usage of the Matter application layer to build a weather station device using the Nordic Thingy:53 or nRF54L15 TAG. Such a device lets you remotely gather different kinds of data using the device sensors, such as temperature, air pressure, and relative humidity.
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.11ax (Wi-Fi® 6) or 802.15.4 (Thread) protocol.
In case of Thread, this device works as a Thread Sleepy End Device.
In case of Wi-Fi, this device works in the Legacy Power Save mode. This means that the device sleeps most of the time and wakes up on each Delivery Traffic Indication Message (DTIM) interval to poll for pending messages.
You can use this application as a reference for creating your own application. See the Adding clusters to Matter application page for an overview of the process you need to follow.
Note
The Matter weather station application from the v2.1.1 nRF Connect SDK release participated in Matter Specification Validation Event (SVE) and successfully passed all required test cases to be considered as a device compliant with Matter 1.0. You can use the nRF Connect SDK v2.1.1 release to see the application configuration and the files that were originally used in Matter 1.0 certification.
Application overview
The application uses a single button for controlling the device state. The weather station device is periodically performing temperature, air pressure, and relative humidity measurements. The measurement results are stored in the device memory and can be read using the Matter controller. The controller communicates with the weather station device over the Matter protocol and exchanges data using the Matter Data Model. The data model describes data measurements within the proper clusters that correspond to the measurement type.
Testing with the Matter Quick Start app
The weather station application is available in the Matter Quick Start app desktop application. Use this app to enable fast and easy evaluation of the application without compiling it or setting the development environment thanks to the pre-compiled hex files. After flashing, follow the step-by-step instructions to commission the application to the Matter network and interact with commercial ecosystems.
Download the Matter Quick Start app from the nRF Connect for Desktop application.
Requirements
The application supports the following development kits:
Hardware platforms |
PCA |
Board name |
|
|---|---|---|---|
PCA20053 |
|
||
PCA20072 |
|
If you want to commission the weather station device and control it remotely through a Thread or Wi-Fi network, you need to set-up the Thread Border Router (Matter over Thread only) and control it with the chip-tool, or use a commercial ecosystem controller. When this happens, you will also be able to control it through 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 following development kits for this application offer IPv6 network support for Matter:
Matter over Thread is supported for the
thingy53/nrf5340/cpuappandnrf54l15tag/nrf54l15/cpuappboard targets.Matter over Wi-Fi is supported for the
thingy53/nrf5340/cpuappboard target with thenrf7002ebexpansion board attached.
Programming requirements
To commission the weather station device and control it remotely through a Thread or Wi-Fi network, you also need a Matter controller device configured on PC or smartphone. This requires additional hardware depending on your setup. The recommended way of getting measurement values is using the mobile Matter controller application that comes with a graphical interface, performs measurements automatically and visualizes the data.
To program a Thingy:53 device where the preprogrammed MCUboot bootloader has been erased, you need the external J-Link programmer. If you have an nRF5340 DK that has an onboard J-Link programmer, you can also use it for this purpose.
If the Thingy:53 is programmed with a compatible sample or application, you can also update the firmware using MCUboot’s serial recovery or DFU over Bluetooth Low Energy (LE).
Note
If you build Matter weather station firmware with factory data support it will not be compatible with other Thingy:53 samples and applications. Then, the only way to program the new firmware image is to use the J-Link programmer.
See Application guide for Thingy:53 for details.
To program nRF54L15 TAG, you need the external J-Link programmer. If you have an nRF54L15 DK that has an onboard J-Link programmer, you can also use it for this purpose.
If your tag is already programmed with one of the Matter samples, you can use DFU over Bluetooth LE or Matter OTA Software Update.
See nRF54L15 TAG for details.
User interface
- LED (LD1 on Thingy:53, LED1 on nRF54L15 TAG):
Shows the overall state of the device and its connectivity. The following states are possible:
Short flash on (green color, 50 ms on/950 ms off) - The device is in the unprovisioned (unpaired) state and is not advertising over Bluetooth LE.
Short flash on (blue color, 50 ms on/950 ms off) - The device is in the unprovisioned (unpaired) state, but is advertising over Bluetooth LE.
Rapid even flashing (blue color, 100 ms on/100 ms off) - The device is in the unprovisioned state and a commissioning application is connected through Bluetooth LE.
Short flash on (purple color, 50 ms on/950 ms off) - The device is fully provisioned and has Thread enabled or has Wi-Fi connection established.
Rapid even flashing after commissioning (blue color, 100 ms on/100 ms off) - The device lost connection to Wi-Fi network (only in Wi-Fi mode).
Note
The boards allow to control RGB components of its single LED independently. This means that the listed color components can overlap, creating additional color effects.
- Button (SW3 on Thingy:53, BTN1 on nRF54L15 TAG):
Used during the commissioning procedure. Depending on how long you press the button:
If pressed for 6 seconds, it initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset procedure.
If pressed for less than 3 seconds, it 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.
- USB port:
Used for getting logs from the device or communicating with it through the command-line interface. It is enabled only for the debug configuration of an application.
- NFC port with antenna attached:
Optionally used for obtaining the onboarding information from the Matter accessory device to start the commissioning the device procedure while using a commercial ecosystem. See the Testing with commercial ecosystem section.
Note
USB and NFC are not available on nRF54L15 TAG. To receive logs from the device, connect to it through RTT.
Configuration
This section describes the configuration options for the application.
See Configuring and building for information about how to permanently or temporarily change the configuration.
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.
Note
If you are working with multiple devices, set a unique discriminator for each one, or commission them one at a time. See Matter device identification for more information.
The application supports the following build 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. |
Note
Currently, only the release configuration is supported when Building for the nRF7002 Wi-Fi expansion board.
Advanced configuration options
This section describes advanced configuration options that you can apply in this application.
Use the click to show toggle to expand the content.
Device firmware upgrade support
The application supports device firmware upgrade (DFU) over-the-air (OTA) using the 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. This protocol is not part of the Matter specification.
In both cases, the MCUboot secure bootloader is used to apply the new firmware image.
The DFU over Matter is enabled by default.
Additionally, you can enable the DFU over SMP by using 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.
The following platforms require external flash memory to perform the DFU:
nRF52840 DK
nRF5340 DK
nRF54L10 DK
You can run DFU without external flash memory on the nRF54L15 and nRF54LM20 DKs using the MCUboot image compression feature.
To see if the application supports this feature, check whether the internal build configuration is available in the build configuration table.
When building with nRF Connect for VS Code, add your desired dfu_build_flag to Extra CMake arguments.
For example add -DCONFIG_CHIP_DFU_OVER_BT_SMP=y to enable DFU over BT SMP.
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 nrf54l15dk/nrf54l15/cpuapp -- -DCONFIG_CHIP_DFU_OVER_BT_SMP=y
Building and running
This section describes how to build the application and commission it to the Matter network.
This sample can be found under applications/matter_weather_station 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.
When building this application with Sysbuild for an SoC that has a network core, the IPC radio firmware is automatically applied to the build.
The IPC radio is one of the companion components in the nRF Connect SDK and allows to use the radio peripheral from another core in a multicore device.
If needed, you can modify the IPC radio configuration in the prj.conf source file in the application’s sysbuild/ipc_radio directory.
Before starting the commissioning procedure, make sure that the device is discoverable over Bluetooth LE. The device becomes discoverable automatically upon the device startup, but only for a predefined period of time (one hour by default). If the Bluetooth LE advertising times out, enable it again.
Advanced building options
Building with factory data support
To build the application in nRF Connect for VS Code with factory data support, add -DEXTRA_CONF_FILE=overlay-factory_data.conf -DFILE_SUFFIX=factory_data to Extra CMake arguments in your build configuration.
Use board target thingy53/nrf5340/cpuapp or nrf54l15tag/nrf54l15/cpuapp.
To build the application with factory data support, run the following command:
west build -b <board_target> -- -DEXTRA_CONF_FILE=overlay-factory_data.conf -DFILE_SUFFIX=factory_data
Where <board_target> is thingy53/nrf5340/cpuapp or nrf54l15tag/nrf54l15/cpuapp.
Note
Matter factory data support requires a dedicated partition layout.
This means that if you build the application using the overlay-factory_data configuration overlay, it will not be compatible with other Thingy:53 applications and samples.
To generate a new factory data set when building for the given board target:
Add -DEXTRA_CONF_FILE=overlay-factory_data.conf -DSB_CONFIG_MATTER_FACTORY_DATA_GENERATE=y -DFILE_SUFFIX=factory_data to Extra CMake arguments in your build configuration.
Run the following command:
west build -b <board_target> -- -DEXTRA_CONF_FILE=overlay-factory_data.conf -DSB_CONFIG_MATTER_FACTORY_DATA_GENERATE=y -DFILE_SUFFIX=factory_data
Where <board_target> is thingy53/nrf5340/cpuapp or nrf54l15tag/nrf54l15/cpuapp.
This command builds the application with default certificates.
After building for the board target, the generated factory_data.hex file will be merged with the application target HEX file, so you can use the regular command to flash it to the device.
If you want to use Vendor ID, Product ID or other data that is not reserved for tests, you need custom test certificates. To build with custom certificates, you need to install the CHIP Certificate Tool.
To learn more about factory data, read the Factory provisioning in Matter user guide.
Building for the nRF7002 Wi-Fi expansion board
To build this application to work with the nRF7002 Wi-Fi expansion board:
Connect the nRF7002 EB to the P9 connector on Thingy:53.
Build the application:
To build the application in the nRF Connect for VS Code IDE for Thingy:53 with the nRF7002 EB attached, add
-Dmatter_weather_station_SHIELD=nrf7002eb -DFILE_SUFFIX=release -DSB_CONFIG_WIFI_NRF70=yto Extra CMake arguments in your build configuration.To build the sample from the command line for Thingy:53 with the nRF7002 EB attached, use the following command within the sample directory:
west build -b thingy53/nrf5340/cpuapp -- -Dmatter_weather_station_SHIELD=nrf7002eb -DFILE_SUFFIX=release -DSB_CONFIG_WIFI_NRF70=y
Testing
This section shows how to test the application. You can test it using your PC and the CHIP Tool for Linux or macOS or commercial ecosystem that supports Matter.
Testing with CHIP Tool
Complete the following steps to test the weather station device using CHIP Tool:
Turn on the device
The application starts in an unprovisioned state. Advertising over Bluetooth LE and DFU start automatically and LED starts blinking blue (short flash on).
If the device does not start advertising over Bluetooth LE and it is not blinking blue, press the Button for 6 seconds to initiate the factory reset of the device.
Commission to Matter network
To commission the device to the Matter network complete the following steps:
Obtain a Thread active dataset from OTBR:
Connect to the Raspberry Pi through USB or SSH.
Run the following commands:
sudo ot-ctl > dataset active -x
Run the following command:
sudo docker exec -it otbr sh -c "ot-ctl dataset active -x"The output should look like:
080000000000000000000300001735060004001fffe00208deadbeefcafe12340708fd123456789abc00000510112233445566778899aabbccddeeff00030a54657374576f726b3031010211220410aabbccddeeff00112233445566778899aa0c0402a0f7f8 Done
Run the following command and fill the <thread dataset> argument obtain in the previous step:
chip-tool pairing ble-thread 1 hex:<thread dataset> 20202021 3840
Collect the following parameters of your Wi-Fi access point:
<ssid> - SSID of your Wi-Fi network.
<password> - A password to your Wi-Fi network associated with the SSID.
Run the following command and fill the <ssid> and <password> arguments:
chip-tool pairing ble-wifi 1 <ssid> <password> 20202021 3840
Once the commissioning is complete and the device has full Thread or Wi-Fi connectivity, LED starts blinking purple (short flash on).
Read temperature
Run the following command:
chip-tool temperaturemeasurement read measured-value 1 1
Example of the temperature measurement value log:
[1675846190.922905][72877:72879] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0402 Attribute 0x0000_0000 DataVersion: 1236968801
[1675846190.922946][72877:72879] CHIP:TOO: MeasuredValue: 2348
This means that the current temperature value is equal to 23.48°C.
Read relative humidity
Run the following command:
chip-tool relativehumiditymeasurement read measured-value 1 2
Example of the relative humidity measurement value log:
[1675849697.750923][164859:164861] CHIP:TOO: Endpoint: 2 Cluster: 0x0000_0405 Attribute 0x0000_0000 DataVersion: 385127250
[1675849697.750953][164859:164861] CHIP:TOO: measured value: 2526
This means that the current relative humidity value is equal to 25.26%.
Read air pressure
Run the following command:
chip-tool pressuremeasurement read measured-value 1 3
[1675849714.536985][164896:164898] CHIP:TOO: Endpoint: 3 Cluster: 0x0000_0403 Attribute 0x0000_0000 DataVersion: 3096547
[1675849714.537008][164896:164898] CHIP:TOO: MeasuredValue: 1015
This means that the current air pressure value is equal to 1015 hPa.
Testing with commercial ecosystem
You can also test the application with the commercial ecosystems and the mobile apps. To test the application, see the ecosystem manual page.
When you start the commissioning procedure, the ecosystem controller must get the onboarding information from the Matter accessory device. The onboarding information representation depends on your commissioner setup.
For this application, the data payload, which includes the device discriminator and setup PIN code, is encoded and shared using an NFC tag. When using the debug configuration, you can also get this type of information from the logs.
Use one of the following onboarding information formats to provide the commissioner with the data required:
For the debug and release configurations:
Weather station application onboarding information for the debug or release configurations QR Code
QR Code Payload
Manual pairing code
Scan the following QR code with the app for your ecosystem:
MT:M1TJ342C00KA0648G00
34970112332
Additionally, if the factory data build configuration overlay is selected:
Weather station application onboarding information for the factory data build configuration overlay QR Code
QR Code Payload
Manual pairing code
Scan the following QR code with the app for your ecosystem:
MT:KAYA36PF1509673GE10
14575339844
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.
Dependencies
This application uses the Matter library that includes the nRF Connect SDK platform integration layer:
In addition, the application uses the following nRF Connect SDK components:
The application depends on the following Zephyr libraries: