Hands-on Matter - The Matter Light Bulb (Part 2)

In Part 1 of this blog series, we provided a theoretical overview by following Alice’s journey from unboxing a new Matter switch to commission the device into the Fabric and binding it to a Matter light bulb. In the following parts, we will recreate Alice’s setup. In this part we will start with a Matter light bulb, we will guide you through the process of setting up a low-cost example to get real hands-on experience with Matter and evaluate it for yourself. We will use a ESP32 with a basic LED and a resistor to create our own light bulb as a proof of concept.

Hardware Setup and Components

ESP32 and LED Schematics:

To build our light bulb, we need the following components:

  • ESP32-WROOM DevKitC

  • 330 Ohm Resistor

  • LED

  • Wires

  • Breadboard

  • Micro-USB Cable

  • Computer with BLE and Wi-Fi

The costs of the hardware should be below 10,- € for our Matter light bulb setup. Place the ESP32 on the breadboard and connect the LED and resistor with the wires as shown in the picture. The GPIO 2 (labeled “G2” or “2”) is used in our case. After setting up our basic circuit, we will connect the ESP32 with our computer via the USB cable.

(Matter) Chip GitHub Repository

The Matter GitHub repository can be found here: https://github.com/project-chip/connectedhomeip First we will bootstrap the repository as detailed here and then take a look at the directory structure as detailed in BUILDING.md.

sudo apt-get install git gcc g++ python pkg-config libssl-dev libdbus-1-dev \
     libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev \
     python3-pip unzip libgirepository1.0-dev libcairo2-dev
     
git clone --recurse-submodules git@github.com:project-chip/connectedhomeip.git

cd connectedhomeip/

source scripts/bootstrap.sh

source scripts/activate.sh

Looking at our repository structure, we have a few areas that are of the most interest for us:

  • docs/guides - here are platform-specific instructions and user guides to help setup-specific tools, e.g. the chip-tool which is the CLI tool to interact with Matter devices.

  • examples/ - here are all example projects for different platforms sorted by application, e.g. the all-cluster-app includes all available functionality of Matter in one application and is the go-to app to start firsts steps with.

For our setup we will need to build two applications, first the chip-tool and secondly the all-cluster-app for the ESP32.

Building the Chip-Tool

From the root of the repository, you can build the chip-tool directly via the following command.

scripts/examples/ gn_build_example.sh 
examples/chip-tool out/chip-tool

After successfully building the chip-tool, you can start it with the following command.

out/chip-tool/chip-tool

The output will look something like this.

[1649943820.702390][30597:30597] CHIP:TOO: Missing cluster name
Usage:
  out/chip-tool/chip-tool cluster_name command_name [param1 param2 ...]

  +-------------------------------------------------------------------------------------+
  | Clusters:                                                                           |
  +-------------------------------------------------------------------------------------+
  | * accesscontrol                                                                     |
  | * accountlogin                                                                      |
  | * administratorcommissioning                                                        |
  | * alarms                                                                            |
  | * any                                                                               |
  | * appliancecontrol                                                                  |
  | * applianceeventsandalert                                                           |
  | * applianceidentification                                                           |
  | * appliancestatistics                                                               |
  | * applicationbasic                                                                  |
  | * applicationlauncher                                                               |
  | * audiooutput                                                                       |
  | * ballastconfiguration                                                              |
  | * barriercontrol                                                                    |
  | * basic                                                                             |
  | * binaryinputbasic                                                                  |
  | * binding                                                                           |
  | * booleanstate                                                                      |
  | * bridgedactions                                                                    |
  | * bridgeddevicebasic                                                                |
  | * bromateconcentrationmeasurement                                                   |
  | * bromodichloromethaneconcentrationmeasurement                                      |
  | * bromoformconcentrationmeasurement                                                 |
  | * carbondioxideconcentrationmeasurement                                             |
  | * carbonmonoxideconcentrationmeasurement                                            |
  | * channel                                                                           |
  | * chloraminesconcentrationmeasurement                                               |
  | * chlorineconcentrationmeasurement                                                  |
  | * chlorodibromomethaneconcentrationmeasurement                                      |
  | * chloroformconcentrationmeasurement                                                |
  | * colorcontrol                                                                      |
  | * contentlauncher                                                                   |
  | * copperconcentrationmeasurement                                                    |
  | * dehumidificationcontrol                                                           |
  | * descriptor                                                                        |
  | * devicetemperatureconfiguration                                                    |
  | * diagnosticlogs                                                                    |
  | * discover                                                                          |
  | * dissolvedoxygenconcentrationmeasurement                                           |
  | * doorlock                                                                          |
  | * electricalmeasurement                                                             |
  | * ethernetnetworkdiagnostics                                                        |
  | * ethyleneconcentrationmeasurement                                                  |
  | * ethyleneoxideconcentrationmeasurement                                             |
  | * fancontrol                                                                        |
  | * fecalcoliformandecoliconcentrationmeasurement                                     |
  | * fixedlabel                                                                        |
  | * flowmeasurement                                                                   |
  | * fluorideconcentrationmeasurement                                                  |
  | * generalcommissioning                                                              |
  | * generaldiagnostics                                                                |
  | * groupkeymanagement                                                                |
  | * groupsettings                                                                     |
  | * groups                                                                            |
  | * haloaceticacidsconcentrationmeasurement                                           |
  | * hydrogenconcentrationmeasurement                                                  |
  | * hydrogensulphideconcentrationmeasurement                                          |
  | * iasace                                                                            |
  | * iaswd                                                                             |
  | * iaszone                                                                           |
  | * identify                                                                          |
  | * illuminancemeasurement                                                            |
  | * keypadinput                                                                       |
  | * leadconcentrationmeasurement                                                      |
  | * levelcontrol                                                                      |
  | * localizationconfiguration                                                         |
  | * lowpower                                                                          |
  | * manganeseconcentrationmeasurement                                                 |
  | * mediainput                                                                        |
  | * mediaplayback                                                                     |
  | * messaging                                                                         |
  | * meteridentification                                                               |
  | * modeselect                                                                        |
  | * networkcommissioning                                                              |
  | * nitricoxideconcentrationmeasurement                                               |
  | * nitrogendioxideconcentrationmeasurement                                           |
  | * occupancysensing                                                                  |
  | * onoff                                                                             |
  | * onoffswitchconfiguration                                                          |
  | * operationalcredentials                                                            |
  | * otasoftwareupdateprovider                                                         |
  | * otasoftwareupdaterequestor                                                        |
  | * oxygenconcentrationmeasurement                                                    |
  | * ozoneconcentrationmeasurement                                                     |
  | * pairing                                                                           |
  | * payload                                                                           |
  | * pollcontrol                                                                       |
  | * powerconfiguration                                                                |
  | * powerprofile                                                                      |
  | * powersource                                                                       |
  | * powersourceconfiguration                                                          |
  | * pressuremeasurement                                                               |
  | * proxyconfiguration                                                                |
  | * proxydiscovery                                                                    |
  | * proxyvalid                                                                        |
  | * pulsewidthmodulation                                                              |
  | * pumpconfigurationandcontrol                                                       |
  | * relativehumiditymeasurement                                                       |
  | * scenes                                                                            |
  | * shadeconfiguration                                                                |
  | * sodiumconcentrationmeasurement                                                    |
  | * softwarediagnostics                                                               |
  | * subscriptions                                                                     |
  | * sulfateconcentrationmeasurement                                                   |
  | * sulfurdioxideconcentrationmeasurement                                             |
  | * switch                                                                            |
  | * targetnavigator                                                                   |
  | * temperaturemeasurement                                                            |
  | * testcluster                                                                       |
  | * tests                                                                             |
  | * thermostat                                                                        |
  | * thermostatuserinterfaceconfiguration                                              |
  | * threadnetworkdiagnostics                                                          |
  | * time                                                                              |
  | * timeformatlocalization                                                            |
  | * timesynchronization                                                               |
  | * totalcoliformbacteriaconcentrationmeasurement                                     |
  | * totaltrihalomethanesconcentrationmeasurement                                      |
  | * turbidityconcentrationmeasurement                                                 |
  | * unitlocalization                                                                  |
  | * userlabel                                                                         |
  | * wakeonlan                                                                         |
  | * wifinetworkdiagnostics                                                            |
  | * windowcovering                                                                    |
  | * interactive                                                                       |
  +-------------------------------------------------------------------------------------+
[1649943820.702695][30597:30597] CHIP:TOO: Run command failure: 
../../examples/chip-tool/commands/common/Commands.cpp:71: Error 0x0000002F

Our output will have the error message [1649943820.702390][30597:30597] CHIP:TOO: Missing cluster name which we will ignore now. After building and flashing the firmware for the ESP32 we will come back to the topic of Clusters and discuss this concepts in more detail.

Building the all-cluster-app

First, you need to install Espressif’s ESP-IDF to build and flash the examples (all instructions can be found in the example as well, if something does not work as described look here).

mkdir ${HOME}/tools
cd ${HOME}/tools
git clone https://github.com/espressif/esp-idf.git
cd esp-idf
git checkout v4.4
git submodule update --init
./install.sh
. ./export.sh

Now move back to the Matter repository and activate the environment.

cd /path/to/connectedhomeip
source scripts/activate.sh

cd examples/all-clusters-app/esp32
idf.py set-target esp32
idf.py build

After the firmware is successfully built, you can now flash the ESP32 and monitor the results. Here /dev/ttyUSB0 is the ESP32, this might be different on your system or if you have more than one development board attached.

idf.py -p /dev/ttyUSB0 flash monitor
idf.py -p /dev/ttyUSB0 erase-flash

The following will show the flashing of the ESP and monitoring the device.

Now you have successfully set up the chip-tool and the ESP with everything you need for your first Matter device. Now we need a bit more theory on how the interaction model works. After this, we will commission our new device into our own Wi-Fi network. If you don’t have a Wi-Fi that you can use, you can create your own access point with Ubuntu as described here.

Endpoints, Clusters, Commands and Attributes

The interaction model is quite simple to understand. We will continue to explain it with our light bulb example. For the demonstration purposes we consider the light as dimmable, no color changing or any other fancy features. So, typically features of a conventional dimmable light are:

  • Turning light on

  • Turning light off

  • Set the brightness to a specific level

In Matter terms, we will group these features in clusters and expose them on endpoints and the node/device. The following figure will give a simplified overview of the interaction model.

Let’s discuss this figure step by step:

  • Node - The physical device on the network, represented by a Node ID in our Fabric.

  • Endpoint - Are related to one device characteristic. e.g. a lighting device with two light bulbs would have two identical endpoints to control each light bulb separately. Endpoint 0 is reserved for Matter-specific features, such as pairing the device with the network.

  • Cluster - A set of features to control on a specific endpoint. E.g. the feature of turning the device on and off is called the OnOff Cluster.

    • Servers - A light bulb would implement a Cluster Server awaiting commands to turn on and off the light.

    • Clients - A light switch would implement a Cluster Client to send on/off commands to the light bulb.

  • Commands - Will trigger a specific action on the Cluster. E.g. turn on light.

  • Attributes - Will store information about a specific Cluster state. E.g. is light turned on or off?

With this background, we can start using the chip-tool to commission our ESP32 Matter device.

Commissioning the ESP32

To start the commissioning, we will need the following things:

  • Wi-Fi Network Credentials (we will use SSID “IoT Testing” and Password “NotTheRealPassword”)

  • Device Discriminator (in this example it is “3840“)

  • Device Passcode (in this example it is “20202021”)

At first, we want to pair our laptop with the chip-tool (the Commissioner) with our ESP32 (the Commissionee) and provide the Wi-Fi credentials, the following command will do this for us. The Node ID (here “12344321”) can be chosen freely.

# ./chip-tool pairing ble-wifi node-id ssid password setup-pin-code discriminator 
./chip-tool pairing ble-wifi 12344321 "IoT Testing" NotTheRealPassword 20202021 3840

This will perform the complete commissioning discussed in Part 1. In the GIF below, you can see both the monitoring of the device (bottom) and the commissioning with the chip-tool (top).

Let’s have a look at the logs of the chip-tool for the commissioning process and match the output to what we learned in Part 1.

The location where the Fabric credentials are stored. You need to back up these files if you want to keep access to your matter devices, as they will be removed after reboot, when the /tmp folder is cleared.

[...]
[1658309310.347076][132461:132461] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_kvs
[1658309310.347179][132461:132461] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_factory.ini
[1658309310.347204][132461:132461] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_config.ini
[1658309310.347218][132461:132461] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_counters.ini
[...]

The log output with comments to explain each section and a summary after the listing.

[...]

# Finding the BLE device and matching with the discriminator
[1658309311.070510][132461:132464] CHIP:BLE: New device scanned: C8:C9:A3:C5:65:BA
[1658309311.070546][132461:132464] CHIP:BLE: Device discriminator match. Attempting to connect.
[...]
[1658309312.208721][132461:132464] CHIP:DL: ConnectDevice complete
[...]

# Start of PASE and successfull session establishment to communicate securly via BLE
[1658309313.022392][132461:132467] CHIP:SC: Sent spake2p msg1
[...]
[1658309315.540046][132461:132467] CHIP:SC: Received spake2p msg2
[...]
[1658309315.540344][132461:132467] CHIP:SC: Sent spake2p msg3
[...]
[1658309315.672418][132461:132467] CHIP:SC: SecureSession[0x7fdfa0001a30]: Moving from state 'kEstablishing' --> 'kActive'
[1658309315.672421][132461:132467] CHIP:IN: SecureSession[0x7fdfa0001a30]: Activated - Type:1 LSID:45062
[1658309315.672425][132461:132467] CHIP:IN: New secure session activated for device <FFFFFFFB00000000, 0>, LSID:45062 PSID:44671!
[1658309315.672431][132461:132467] CHIP:CTL: Remote device completed SPAKE2+ handshake
[1658309315.672434][132461:132467] CHIP:TOO: Pairing Success
[1658309315.672437][132461:132467] CHIP:TOO: PASE establishment successful
[1658309315.672440][132461:132467] CHIP:CTL: Commissioning stage next step: 'SecurePairing' -> 'ReadCommissioningInfo'
[...]

# ReadCommissioningInfo -> ArmFailSafe -> ConfigRegulatory:
# Basic configuration for the commissioning
[1658309315.856534][132461:132467] CHIP:CTL: Successfully finished commissioning step 'ReadCommissioningInfo'
[1658309315.856550][132461:132467] CHIP:CTL: Commissioning stage next step: 'ReadCommissioningInfo' -> 'ArmFailSafe'
[...]
[1658309316.035322][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0030 Command=0x0000_0001
[1658309316.035345][132461:132467] CHIP:CTL: Received ArmFailSafe response errorCode=0
[1658309316.035362][132461:132467] CHIP:CTL: Successfully finished commissioning step 'ArmFailSafe'
[1658309316.035372][132461:132467] CHIP:CTL: Commissioning stage next step: 'ArmFailSafe' -> 'ConfigRegulatory'
[...]
[1658309316.213618][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0030 Command=0x0000_0003
[1658309316.213637][132461:132467] CHIP:CTL: Received SetRegulatoryConfig response errorCode=0
[1658309316.213647][132461:132467] CHIP:CTL: Successfully finished commissioning step 'ConfigRegulatory'
[1658309316.213652][132461:132467] CHIP:CTL: Commissioning stage next step: 'ConfigRegulatory' -> 'SendPAICertificateRequest'
[...]

# SendPAICertificateRequest -> SendDACCertificateRequest -> SendAttestationRequest -> AttestationVerification:
# Perform the Device Attestation process to validate the authenticity of the device.
[1658309316.405915][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0003
[1658309316.405925][132461:132467] CHIP:CTL: Received certificate chain from the device
[1658309316.405934][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendPAICertificateRequest'
[1658309316.405941][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendPAICertificateRequest' -> 'SendDACCertificateRequest'
[...]
[1658309316.582616][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0003
[1658309316.582638][132461:132467] CHIP:CTL: Received certificate chain from the device
[1658309316.582659][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendDACCertificateRequest'
[1658309316.582675][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendDACCertificateRequest' -> 'SendAttestationRequest'
[...]
[1658309317.296396][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0001
[1658309317.296407][132461:132467] CHIP:CTL: Received Attestation Information from the device
[1658309317.296416][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendAttestationRequest'
[1658309317.296434][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendAttestationRequest' -> 'AttestationVerification'
[...]
[1658309317.296446][132461:132467] CHIP:CTL: Verifying attestation
[1658309317.298651][132461:132467] CHIP:CTL: Successfully validated 'Attestation Information' command received from the device.
[1658309317.298687][132461:132467] CHIP:CTL: Successfully finished commissioning step 'AttestationVerification'
[1658309317.298693][132461:132467] CHIP:CTL: Commissioning stage next step: 'AttestationVerification' -> 'SendOpCertSigningRequest'
[...]

# SendOpCertSigningRequest -> ValidateCSR -> GenerateNOCChain -> SendTrustedRootCert -> SendNOC:
# Configure cetifcicates to allow access to the device based on the added credentials
1658309318.959302][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0005
[1658309318.959313][132461:132467] CHIP:CTL: Received certificate signing request from the device
[1658309318.959321][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendOpCertSigningRequest'
[1658309318.959326][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendOpCertSigningRequest' -> 'ValidateCSR'
[...]
[1658309318.959622][132461:132467] CHIP:CTL: Successfully finished commissioning step 'ValidateCSR'
[1658309318.959629][132461:132467] CHIP:CTL: Commissioning stage next step: 'ValidateCSR' -> 'GenerateNOCChain'
[1658309318.959633][132461:132467] CHIP:CTL: Performing next commissioning step 'GenerateNOCChain'
[1658309318.959638][132461:132467] CHIP:CTL: Getting certificate chain for the device from the issuer
[1658309318.959706][132461:132467] CHIP:CTL: Verifying Certificate Signing Request
[1658309318.959917][132461:132467] CHIP:CTL: Generating NOC
[1658309318.959996][132461:132467] CHIP:CTL: Providing certificate chain to the commissioner
[1658309318.960003][132461:132467] CHIP:CTL: Received callback from the CA for NOC Chain generation. Status ../../examples/chip-tool/third_party/connectedhomeip/src/controller/ExampleOperationalCredentialsIssuer.cpp:261: Success
[1658309318.960009][132461:132467] CHIP:CTL: Successfully finished commissioning step 'GenerateNOCChain'
[1658309318.960057][132461:132467] CHIP:CTL: Performing next commissioning step 'SendTrustedRootCert'
[1658309318.960062][132461:132467] CHIP:CTL: Sending root certificate to the device
[...]
[1658309319.183569][132461:132467] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_003E Command=0x0000_000B Status=0x0
[1658309319.183577][132461:132467] CHIP:CTL: Device confirmed that it has received the root certificate
[1658309319.183584][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendTrustedRootCert'
[1658309319.183589][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendTrustedRootCert' -> 'SendNOC'
[...]
[1658309321.568391][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0008
[1658309321.568399][132461:132467] CHIP:CTL: Device returned status 0 on receiving the NOC
[1658309321.568402][132461:132467] CHIP:CTL: Operational credentials provisioned on device 0x7fdfa0000b60
[1658309321.568406][132461:132467] CHIP:TOO: Secure Pairing Success
[1658309321.568409][132461:132467] CHIP:TOO: CASE establishment successful
[1658309321.568415][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendNOC'
[1658309321.568418][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendNOC' -> 'WiFiNetworkSetup'
[...]

# WiFiNetworkSetup -> WiFiNetworkEnable: 
# Setup the network access for the wifi
[1658309321.703555][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0031 Command=0x0000_0005
[1658309321.703577][132461:132467] CHIP:CTL: Received NetworkConfig response, networkingStatus=0
[1658309321.703584][132461:132467] CHIP:CTL: Successfully finished commissioning step 'WiFiNetworkSetup'
[1658309321.703587][132461:132467] CHIP:CTL: Commissioning stage next step: 'WiFiNetworkSetup' -> 'WiFiNetworkEnable'
[...]
[1658309322.873512][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0031 Command=0x0000_0007
[1658309322.873524][132461:132467] CHIP:CTL: Received ConnectNetwork response, networkingStatus=0
[1658309322.873533][132461:132467] CHIP:CTL: Successfully finished commissioning step 'WiFiNetworkEnable'
[1658309322.873538][132461:132467] CHIP:CTL: Commissioning stage next step: 'WiFiNetworkEnable' -> 'FindOperational'
[...]

# FindOperational:
# Test access and configuration of the setup by connecting to the device via wifi instead of BLE (using CASE)
[1658309322.873544][132461:132467] CHIP:CTL: Performing next commissioning step 'FindOperational'
[...]
# CASE is used to secure the access
[1658309324.113041][132461:132467] CHIP:SC: Sent Sigma1 msg
[1658309325.728491][132461:132467] CHIP:SC: Received Sigma2 msg
[1658309325.729381][132461:132467] CHIP:SC: Sending Sigma3
[1658309325.729581][132461:132467] CHIP:SC: Sent Sigma3 msg
[...]
[1658309324.112694][132461:132467] CHIP:IN: SecureSession[0x7fdfa0012d60]: Allocated Type:2 LSID:45063
[1658309324.112703][132461:132467] CHIP:SC: Initiating session on local FabricIndex 1 from 0x000000000001B669 -> 0x0000000000BC5C01
[...]
[1658309328.881997][132461:132467] CHIP:CTL: Successfully finished commissioning step 'FindOperational'
[1658309328.882001][132461:132467] CHIP:CTL: Commissioning stage next step: 'FindOperational' -> 'SendComplete'
[1658309328.882005][132461:132467] CHIP:CTL: Performing next commissioning step 'SendComplete'
[...]

# SendComplete -> Cleanup: 
# Close sessions and shutdown BLE, all future access will no be via wifi.
[1658309329.130822][132461:132467] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0030 Command=0x0000_0005
[1658309329.130830][132461:132467] CHIP:CTL: Received CommissioningComplete response, errorCode=0
[1658309329.130837][132461:132467] CHIP:CTL: Successfully finished commissioning step 'SendComplete'
[1658309329.130841][132461:132467] CHIP:CTL: Commissioning stage next step: 'SendComplete' -> 'Cleanup'
[...]
[1658309329.131667][132461:132461] CHIP:DL: Inet Layer shutdown
[1658309329.131671][132461:132461] CHIP:DL: BLE shutdown
[1658309329.131938][132461:132461] CHIP:DL: System Layer shutdown
[1658309329.131953][132461:132461] CHIP:IN: SecureSession[0x7fdfa0001a30]: Released - Type:1 LSID:45062

# End of pairing

In summary, the chip-tool does the following:

1.) Discover device via BLE using the discriminator

2.) Setup secure communication (PASE)

3.) Communicate basic information

4.) Perform device attestation

5.) Configure operational credentials on the device

6.) Enable Wi-Fi access on the device

7.) Test connection to the device (CASE)

8.) Close and cleanup all sessions.

Now you can easily turn the light on and off by sending the following command.

# ./chip-tool onoff toggle destination-id endpoint-id
./chip-tool onoff toggle 12344321 1

The following GIF will demonstrate toggling the light.

A brief look at the chip-tool output to explain what is happening.

[...]
# Setup credentials for Fabric 1
[1658316828.616743][241737:241737] CHIP:CTL: System State Initialized...
[1658316828.616757][241737:241737] CHIP:CTL: Stopping commissioning discovery over DNS-SD
[1658316828.616764][241737:241737] CHIP:CTL: Setting attestation nonce to random value
[1658316828.616774][241737:241737] CHIP:CTL: Setting CSR nonce to random value
[...]
[1658316828.616819][241737:241737] CHIP:CTL: Stopping commissioning discovery over DNS-SD
[1658316828.616822][241737:241737] CHIP:CTL: Setting attestation nonce to random value
[1658316828.616827][241737:241737] CHIP:CTL: Setting CSR nonce to random value
[1658316828.617696][241737:241737] CHIP:CTL: Generating NOC
[1658316828.618026][241737:241737] CHIP:FP: Validating NOC chain
[1658316828.618437][241737:241737] CHIP:FP: NOC chain validation successful
[1658316828.618481][241737:241737] CHIP:FP: Updated fabric at index: 0x1, Node ID: 0x000000000001B669
[...]
[1658316828.620696][241737:241737] CHIP:CTL: Joined the fabric at index 1. Compressed fabric ID is: 0x0000000000000000
[...]

# Identify the node and establish a session (CASE) (0xbc5c01 = 12344321)
[1658316828.657279][241737:241742] CHIP:TOO: Sending command to node 0xbc5c01
[1658316828.657288][241737:241742] CHIP:CSM: FindOrEstablishSession: PeerId = 5981134D36BF4317:0000000000BC5C01
[1658316828.657292][241737:241742] CHIP:CSM: FindOrEstablishSession: No existing OperationalDeviceProxy instance found
[...]
[1658316828.857614][241737:241742] CHIP:CTL: Updating device address to UDP:[fe80::cac9:a3ff:fec5:65b8%wlp0s20f3]:5540 while in state 2
[1658316828.857631][241737:241742] CHIP:CTL: OperationalDeviceProxy[5981134D36BF4317:0000000000BC5C01]: State change 2 --> 3
[1658316828.857730][241737:241742] CHIP:IN: SecureSession[0x7f40e00018a0]: Allocated Type:2 LSID:22504
[1658316828.857756][241737:241742] CHIP:SC: Initiating session on local FabricIndex 1 from 0x000000000001B669 -> 0x0000000000BC5C01
[...]

# CASE
[1658316828.858806][241737:241742] CHIP:SC: Sent Sigma1 msg
[...]
[1658316829.938517][241737:241742] CHIP:SC: Received Sigma2 msg
[...]
[1658316829.939354][241737:241742] CHIP:SC: Sending Sigma3
[...]
[1658316829.939545][241737:241742] CHIP:SC: Sent Sigma3 msg
[...]
[1658316832.001580][241737:241742] CHIP:IN: New secure session activated for device <0000000000BC5C01, 1>, LSID:22504 PSID:44672!
[...]

# Send the command toggle (0x2) to onoff cluster (0x6) to endpoint 1
# See also: https://github.com/project-chip/connectedhomeip/blob/master/src/app/zap-templates/zcl/data-model/chip/onoff-cluster.xml
[1658316832.001604][241737:241742] CHIP:TOO: Sending cluster (0x00000006) command (0x00000002) on endpoint 1
[...]

# Receiving the response from the device (all successful)
[1658316832.204861][241737:241742] CHIP:DMG: InvokeResponseMessage =
[1658316832.204865][241737:241742] CHIP:DMG: {
[1658316832.204869][241737:241742] CHIP:DMG: 	suppressResponse = false, 
[1658316832.204873][241737:241742] CHIP:DMG: 	InvokeResponseIBs =
[1658316832.204880][241737:241742] CHIP:DMG: 	[
[1658316832.204884][241737:241742] CHIP:DMG: 		InvokeResponseIB =
[1658316832.204890][241737:241742] CHIP:DMG: 		{
[1658316832.204895][241737:241742] CHIP:DMG: 			CommandStatusIB =
[1658316832.204899][241737:241742] CHIP:DMG: 			{
[1658316832.204903][241737:241742] CHIP:DMG: 				CommandPathIB =
[1658316832.204908][241737:241742] CHIP:DMG: 				{
[1658316832.204913][241737:241742] CHIP:DMG: 					EndpointId = 0x1,
[1658316832.204918][241737:241742] CHIP:DMG: 					ClusterId = 0x6,
[1658316832.204922][241737:241742] CHIP:DMG: 					CommandId = 0x2,
[1658316832.204926][241737:241742] CHIP:DMG: 				},
[1658316832.204933][241737:241742] CHIP:DMG: 				
[1658316832.204937][241737:241742] CHIP:DMG: 				StatusIB =
[1658316832.204942][241737:241742] CHIP:DMG: 				{
[1658316832.204947][241737:241742] CHIP:DMG: 					status = 0x00 (SUCCESS),
[1658316832.204951][241737:241742] CHIP:DMG: 				},
[1658316832.204956][241737:241742] CHIP:DMG: 				
[1658316832.204960][241737:241742] CHIP:DMG: 			},
[1658316832.204966][241737:241742] CHIP:DMG: 			
[1658316832.204970][241737:241742] CHIP:DMG: 		},
[1658316832.204975][241737:241742] CHIP:DMG: 		
[1658316832.204979][241737:241742] CHIP:DMG: 	],
[1658316832.204985][241737:241742] CHIP:DMG: 	
[1658316832.204989][241737:241742] CHIP:DMG: 	InteractionModelRevision = 1
[1658316832.204992][241737:241742] CHIP:DMG: },
[1658316832.205009][241737:241742] CHIP:DMG: Received Command Response Status for Endpoint=1 Cluster=0x0000_0006 Command=0x0000_0002 Status=0x0

In summary, the chip-tool does the following:

1.) Setup credentials for Fabric 1

2.) Find Node 12344321 (0xbc5c01) and establish a session using CASE

3.) Send the toggle command (0x2) to the OnOff cluster (0x6) and endpoint 1. (OnOff cluster definitions here)

4.) Receive a response from the node if the command was successful.

We now can see a bright light and controlled our first hand made Matter device. We used many of the concepts explained in Part 1 and the Part 3 of this series we will take a look at binding a light switch to the light bulb to have a more complete setup and get rid of the chip-tool to control the light.

Further reading:

Tim Conrad — Senior Security Consultant

October 4, 2022

Do you have questions?

Patrick Sernetz — Head of Solution Architecture

If you have any questions or would like to realise a project with us, please contact us by e-mail.