Matter on ubuntu: getting started with the standard for smart home devices

Matter on Ubuntu: getting started with the standard for smart home devices

Canonical joined the Connectivity Standards Alliance last year to lead the charge for Linux in the smart home. The Matter standard is a particular focus for us. Its secure design and open ecosystem align well with Ubuntu’s own values of security and openness.

Ubuntu Core and Matter make for a powerful pair. Ubuntu Core’s containerisation makes it a highly secure OS that pairs well with the highly secure protocol. Its update and device management capabilities provide the missing pieces that the Matter standard leaves up to device makers to implement.

Since joining the alliance, we’ve been working to support the Matter standard on Ubuntu and Ubuntu Core. As part of that effort, we’ve created a set of reference snaps which enable the creation of a Matter fabric running entirely on Ubuntu. 

Sponsored

This blog is a how-to guide for creating a Matter fabric running entirely on Ubuntu Core devices. In it, we’ll describe how to set up a simple end device (in this case a light) and then commission and control it with our controller snap.

Hardware

In this guide, we use the following hardware:

  • A PC running Ubuntu 22.04
  • A Raspberry Pi 4B with a 64bit Ubuntu 22.04
  • A 10mm 3v LED
See also  Make VirtualBox VMs to Have Separate Icons in Ubuntu

Since we use a large 3v LED, we can directly connect it to the GPIO. We connect the LED to GPIO 4 (pin 7) and GND (pin 9). Read more about the Raspberry Pi pinout.

Installation

In this section, we’ll install a Matter application to turn the Raspberry Pi into a Matter lighting device. We will use the matter-pi-gpio-commander snap which contains a lighting app built on top of the Matter SDK.

SSH to the Raspberry Pi and install the snap:

sudo snap install matter-pi-gpio-commander --beta

Set the GPIO to 4:

sudo snap set matter-pi-gpio-commander gpio=4

Read the instructions for other possible configurations such as changing the default pass code (i.e. 20202021).

Grant the snap access to the GPIO memory, needed by this application:

sudo snap connect matter-pi-gpio-commander:gpio-memory-control

The application is almost ready to start and join a Matter network. But before doing so, it is better to test locally to see if we can control the GPIO via the app:

sudo matter-pi-gpio-commander.test-blink

Take a look at the logs and the LED. If there are no errors and the LED blinks every half second, we are ready to proceed!

Before we start the application, we’d also grant it access to register itself via DNS-SD to allow discovery later on:

See also  7 Most Useful Steps to Configure ‘sudo’ in Linux Terminal
sudo snap connect matter-pi-gpio-commander:avahi-control

Now, let’s start the application service:

Sponsored
sudo snap start matter-pi-gpio-commander

You can monitor the logs with:

sudo snap logs -n 100 -f matter-pi-gpio-commander

Keep it running in a dedicate terminal window which we commission and control the application in the next section.

Commissioning

Now that we have our application running, we can go ahead and commission it using a Matter controller.

We will use the chip-tool snap which is a CLI controller.

Install the controller on the PC:

sudo snap install chip-tool --beta

Assuming the the Pi and PC are connected to the same network, we should be able to commission the device by discovering its IP address via DNS-SD. This way, we don’t have to manually enter the IP address.

First, grant the necessary access to chip-tool to discover services via DNS-SD:

sudo snap connect chip-tool:avahi-observe

We are ready to pair:

sudo chip-tool pairing onnetwork 104 20202021

where:

See also  Can it play Doom? Running an AI LAN party on a Spark cluster with ViZDoom
  • 110 is the node id being assigned to this device
  • 20202021 is the default setup passcode

If this doesn’t work, it may be because it has taken too long to reach this step and the device has stopped listenning to commissioning requests. Try restarting it on the Pi with sudo snap restart matter-pi-gpio-commander.

Control

There are a few ways to control the device. The toggle command is stateless and simplest.

sudo chip-tool onoff toggle 110 1

You may need to send this command a few time to make the GPIO output state in sync (see issue #14).


By now, you have created a fully containerised Matter controller and end device. To adapt these reference snaps to your purposes, feel free to take a look at the source code, linked below. To read more about Canonical’s approach to smart home technology, take a look at our website or get in touch.

For further instructions and to report issues:


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply