Matter: Door lock

This door lock sample demonstrates the usage of the Matter (formerly Project Connected Home over IP, Project CHIP) application layer to build a door lock device with one basic bolt. 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. You can use this sample as a reference for creating your own application.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

For remote testing scenarios, if you want to commission the lock device and control it remotely through a Thread network, you also need the following:

Note

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

Overview

The sample uses buttons for changing the lock and device states, and LEDs to show the state of these changes. It can be tested in the following ways:

  • Standalone, by using a single DK that runs the door lock application.

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

The remote control testing requires a Matter controller, which can be configured either on PC or mobile (for remote testing in a network). Both methods can be enabled after building and running the sample.

Remote testing in a network

By default, the Matter accessory device has Thread disabled, and it must be paired with the Matter controller over Bluetooth LE to get configuration from it if you want to use the device within a Thread network. To do this, the device must be made discoverable manually (for security reasons) and 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.

Remote testing using test mode

Alternatively to the commissioning procedure, you can use the test mode, which allows to join a Thread network with default static parameters and static cryptographic keys. Use Button 3 to enable this mode after building and running the sample.

Note

The test mode is not compliant with Matter and it only works together with Matter controller and other devices which use the same default configuration.

Configuration

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

Device Firmware Upgrade support

You can configure the sample to use the secure bootloader for performing over-the-air Device Firmware Upgrade using Bluetooth LE. To build the sample with configuration that enables the DFU, run the following command with build_target replaced with the build target name of the hardware platform you are using (see Requirements):

west build -b build_target -- -DOVERLAY_CONFIG=../common/config/overlay-dfu_support.conf -DPM_STATIC_YML_FILE="configuration/build-target/pm_static.yml"

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 through Bluetooth LE.

  • Short Flash Off (950 ms on/50 ms off) - The device is fully provisioned, but does not yet have full Thread network or service connectivity.

  • Solid On - The device is fully provisioned and has full Thread network and service connectivity.

LED 2:

Shows the state of the lock. The following states are possible:

  • Solid On - The bolt is extended and the door is locked.

  • Off - The bolt is retracted and the door is unlocked.

  • Rapid Even Flashing (50 ms on/50 ms off during 2 s) - The simulated bolt is in motion from one position to another.

Button 1:

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 initiates the OTA software update process. The OTA process is disabled by default, but you can enable it when you build the sample with the DFU support (see Configuration).

Button 2:

Changes the lock state to the opposite one.

Button 3:

Starts the Thread networking in the test mode using the default configuration.

Button 4:

Starts the the NFC tag emulation, enables Bluetooth LE advertising for the predefined period of time, 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/lock in the nRF Connect SDK folder structure.

See Building and programming a sample application for information about how to build and program the application.

See Configuration for information about building the sample with the DFU support.

Testing

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

  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 (for example, PuTTY). See How to connect with PuTTY for the required settings.

  3. Observe that initially LED 2 is lit, which means that the door lock is closed.

  4. Press Button 2 to unlock the door. LED 2 is blinking while the lock is opening. After approximately 2 seconds, LED 2 turns off permanently. The following messages appear on the console:

    I: Unlock Action has been initiated
    I: Unlock Action has been completed
    
  5. Press Button 2 one more time to lock the door again. LED 2 starts blinking and then remains turned on. The following messages appear on the console:

    I: Lock Action has been initiated
    I: Lock Action has been completed
    
  6. Press Button 1 to initiate factory reset of the device.

The device is rebooted after all its settings are erased.

Enabling remote control

Remote control allows you to control the Matter door lock device from a Thread network.

You can use one of the following options to enable this option:

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

  • Remote testing using test mode, which allows you to test the sample functionalities in a Thread network with default parameters, without commissioning. Use Button 3 to enable this mode after building and running the sample.

Commissioning the device

To commission the device, go to the Configuring Matter development environment page and complete the steps for the Matter controller you want to use. As part of this tutorial, you will configure Thread Border Router, build and install the Matter controller, commission the device, and send Matter commands that cover scenarios described in the Testing section. If you are new to Matter, the recommended approach is Running Thread Border Router and Matter controller on separate devices using an Android smartphone.

In Matter, the commissioning procedure is done over Bluetooth LE between a Matter accessory device and the Matter controller, where the controller has the commissioner role. When the procedure is finished, the device should be equipped with all information needed to securely operate in the Matter network.

During the last part of the commissioning procedure (the provisioning operation), Thread network credentials are sent from the Matter controller to the Matter accessory device. As a result, the device is able to join the Thread network and communicate with other Thread devices in the network.

To start the commissioning procedure, the controller must get the commissioning information from the Matter accessory device. The data payload, which includes the device discriminator and setup PIN code, 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 Matter device tutorial.

Dependencies

This sample uses the Matter library, which 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: