Matter: Light switch¶
This light switch sample demonstrates the usage of the Matter (formerly Project Connected Home over IP, Project CHIP) application layer to build a basic controller device for the Matter light bulb sample. This device works as a Matter controller, meaning that it can control a light bulb remotely over a Matter network built on top of a low-power, 802.15.4 Thread network. You can use this sample as a reference for creating your own application.
The sample supports the following development kits:
For this sample to work, you also need the Matter light bulb sample programmed to another supported development kit.
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.
The light switch must be put into the test mode and paired with a light bulb device to be able to send Matter light bulb control commands such as toggling the light and setting its brightness level.
Unlike other samples, such as Matter door lock, the light switch sample does not support Matter commissioning over Bluetooth® LE. To make the light switch and the light bulb devices able to communicate with each other, they must be initialized with the same static Thread network parameters and static Matter cryptographic keys.
Pressing Button 3 activates the test mode before enabling the pairing phase on the device.
After the test mode is activated and both devices are initialized with the same network parameters, the pairing phase starts. During this phase, the light bulb device periodically sends multicast messages with static content. Once such a message is intercepted by the light switch device, the light switch is made aware of the IP address of the nearby light bulb device and the pairing is done.
See Configuring your application for information about how to permanently or temporarily change the configuration.
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 Radio front-end module (FEM) support 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.
- LED 1:
Shows the overall state of the device and its connectivity. The following states are possible:
Solid Off - The device is not paired with any light bulb device.
Short Flash On (100 ms on/900 ms off) - The device is in the pairing phase.
Solid On - The device is paired with a light bulb device.
- Button 1:
Initiates the factory reset of the device.
- Button 2:
Toggles the light on the paired light bulb device.
- Button 3:
- Button 4:
Brightens the light on the paired light bulb device. The brightness level is increased gradually while the button is being pressed. When the button is pressed for too long, the brightness level wraps around and becomes the lowest possible.
- SEGGER J-Link USB port:
Used for getting logs from the device or for communicating with it through the command-line interface.
This sample can be found under
samples/matter/light_switch in the nRF Connect SDK folder structure.
See Building and programming an application for information about how to build and program the application.
After building this and Matter light bulb samples, and programming them to your development kits, test communication between both devices by performing the following steps:
Complete the following actions for both devices:
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.
Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.
On both devices, press Button 1 to reset them to factory settings.
Pair both devices by completing the following steps:
On the light switch device, press Button 3 to enable pairing on this device. The light switch becomes the Thread network Leader. The following messages appear in the console for the light switch device:
I: Device is not commissioned to a Thread network. Starting with the default configuration I: Starting light bulb discovery
On the light bulb device, press Button 3 to enable pairing on this device. The following messages appear on the console for the light bulb device:
I: Device is not commissioned to a Thread network. Starting with the default configuration I: Started Publish service
At this point, the light bulb is discovered by the light switch device and the following messages appear on the console for the light switch device:
I: Stopping light bulb discovery I: Pairing with light bulb fdde:ad00:beef:0:7b0:750e:6d96:49e9
On the light switch device, press Button 2 to turn off the light on the light bulb device. The following message appears on the console for the light switch device:
I: Toggling the light
LED 2 on the light bulb device turns off.
On the light switch device, press Button 2 to turn on the light again. LED 2 on the light bulb device turns back on.
On the light switch device, press Button 4 and hold it for a few seconds. Messages similar to the following one appear in the console:
I: Setting brightness level to 7
The brightness of LED 2 on the light bulb device changes while the button is pressed.