When in search of the perfect problem to solve, the journey to find 'the one' can be challenging. After delving deep into the Matter protocol, I must admit it significantly simplifies the integration of smart home devices. However, navigating the learning curve consumed valuable time, leaving little room to identify 'the' problem. My motivation came from addressing a personal inconvenience – the reluctance to leave my chair to lock the door. While I initially implemented a solution with MQTT, Matter proved to be a more user-friendly option, allowing seamless integration of my custom door lock with the Google Nest Hub. Despite the substantial certification requirements for selling, the development process is undeniably smoother.
Components NeededI used nRF5340, door lock, power supply and some jumper wires.
Tasks at Hand- Creating the matter accessory with nRF5340 and nRF Connect SDK
- Implementing commissioner and controller using chiptool for testing. (kind of optional)
- Integrating with Google Nest Hub
First install nRF Connect SDK extension in VS Code
For Matter , Door Lock example is available but that one is too much for my finctionality. I simply needed one endpoint and one onoff cluster for my application. Depending on our need we can add multiple endpoints and different clusters in our project using zaptool.
For my application I am going to modify the existing light application to use only onoff cluster.
So open nRF Connect SDK and click on create a new create a application and choose nrf light bulb. Create nRF5340 DK build configuration and test build it. Lightbulb have onoff, level and color control clusters in it, I only need onoff, I am using zaptool to modify this.
Install zaptool by running the python script file get_zap.py
python3 ncs/v2.4.0/modules/lib/matter/scripts/setup/nrfconnect/get_zap.py -l zap_loc -o
cd zap_loc/zap-linux
run zap and edit configuration in endpoint 1, remove level cluster from clusters.
find gpio in device tree and connect the relay to that pin P0.31. And connect the door lock to relay and 12V power supply.
Build and Flash the program.
OTBR and chiptool in Raspberry PiSetup Raspberry pi with raspian OS
Install OTBR in Raspberry Pi
git clone https://github.com/openthread/ot-br-posix
cd ot-br-posix
./script/bootstrap
INFRA_IF_NAME=wlan0 ./script/setup
Install Radio Co Processor in nrfdongle:
git clone –recursive https://github.com/openthread/ot-nrf528xx.git
cd ot-nrf528xx
./script/bootstrap
./script/build nrf52840 USB_trans -DOT_BOOTLOADER=USB -DOTTHREAD_VERSION=1.2
arm-none-eabi-objcopy -O ihex build/bin/ot-rcp ot-rcp.hex
Flash the rcp-hex to nrf dongle using nrf programmer app and plug in RPi and reboot RPi.
Access local host, openthread local host will open. On the FORM tab click to form network. Once it is successful you will see node in TOPOLOGY tab.
Type "sudo ot-ctl dataset active -x" in RPi to get thread details and copy that string.
For the chiptool i used the precompiled binary from nRF.
https://github.com/nrfconnect/sdk-nrf/releases
I was able to build chiptool for RPi with docker. (Since the precompiled version works I am not going to details).
Commission matter device using this command which node number we can assign as second parameter :
/chip-tool pairing ble-thread 1 hex:0e080000000000010000000300000f35060004001fffe0020811111111222222220708fdc8332113b45d5a051000112233445566778899aabbccddeeff030e4f70656e54687265616454657374010212340410c8e3af4123992a2433ef8feb2304d8650c0402a0f7f8 20202021 3840
Control the Lock:
./chip-tool onoff on 1 1
./chip-tool onoff off 1 1
Last two parameter and endpoint and cluster:
To read state :
./chip-tool onoff read on-off 1 1
Setting up with Google Home:Open Google Home App, click on add device (usually your smart phone has popup if a device is nearby) and select matter device. Scan the QR or type the code 34970112332.
Device will get commissioned and you will see a onoff cluster to control in Google Home App. This way I can control my door lock with Google Home.
Comments