Hello, my name is Lyubomir Nachev, I am nineteen years old and currently a freshman at Technological University - Sofia, majoring in Electronic and Information Systems.
What is my idea?
I want to improve the quality of life of all people around the world. And my idea is aiming to solve the problem of poor and inconsistent indoor air quality and its regulation, and the limited ability of the elderly and disabled to take care of it.
People need to keep an eye on the indoor air quality and temperature in their homes. If the air inside gets stagnant, a person has to go and open up the window. If it gets too cold inside, you might have to close your window and even go and adjust the temperature of the air conditioner. Those tasks, even though simple and mundane, can be annoying and sometimes even distracting.
These tasks are especially difficult for the elderly as they, sometimes, can't even get up to open or close the window and require assistance that is not always there. Furthermore, old people tend to become numb to changes in the temperature and can't decide for themselves whether they are hot or cold. So an automated system could improve the lives of many people.
How does it work?
My solution will monitor the temperature, humidity and air quality in a room and if the air quality deteriorates, a couple of things will activate - visual and sound indication (a light and a buzzer), a smart window actuator will turn on and open the window to improve the air quality, and at the same time an infrared transmitter will send a signal to the air conditioning to turn it off, with the aim to lower the energy consumption.
I will use Matter in this project to control the devices, so I think it's necessary to summarize what is Matter and how it works:
What is Matter?
Matter is an open-source connectivity standard for smart home and IoT (Internet of Things) devices. Its goal is to establish a single, compatible standard for smart devices so that they can connect and communicate with each other easily, independent of the manufacturer. Before being renamed as Matter, this protocol was known as Project CHIP (Connected Home over IP).
How does it work?
Matter runs over existing protocols: Thread for low-power, low-bandwidth devices, and Wi-Fi or Ethernet for higher bandwidth devices. Matter defines a set of rules and standards for devices to follow, ensuring they can discover each other on a network, communicate and perform tasks in a standardized manner. This standardization helps to eliminate compatibility problems that could happen when devices with proprietary protocols from different manufacturers are used.
Topology of the networkFigure 1 shows the topology of the network including all devices in the project. I am using one PC running Ubuntu that has the CHIP(Connected Home IP) tool installed. This will be my Matter Controller. I then have configured a second computer with Ubuntu, and an nRF52840 Dongle configured as RCP(Radio Co-processor), to create the Thread Border Router in my network. Next I have two Matter over Wi-Fi devices - Node 1 and Node 2, as well as two Matter over Thread devices - Node 3 and Node 4.
Workflow
The workflow was a bit chaotic at first, I spent 2-3 days creating a plan of how I was going to work and breaking the whole project down into small tasks that could be tackled each day. Here is the required configuration for each device:
Creating the Matter ControllerI installed the pre-built tool package from the Matter nRF Connect releases GitHub page. The package needs to be the same version as the nRF Connect SDK version I am using, which is v2.5.0. I installed the.zip file for my system, extracted it, and opened a terminal in the same location.
Creating the Thread Border RouterSince my PC does not have a built-in IEEE 802.15.4 radio and I need one to establish connection to the IEEE 802.15.4 network that is used by Thread, I had to configure a nRF52840-Dongle as an RCP, which in short allows me to use the IEEE 802.15.4 radio that the dongle has for my PC. There is a Thread: Co-processor example that is included in the nRF Connect SDK that I compiled and uploaded to the dongle. I won't go into details because the whole process is documented by Nordic. You can read more about it here - Thread: Co-processor.
After that, I cloned the ot-br-posix repository from GitHub and followed the official OpenThread Border Router Codelab tutorial for setting up the OTBR.
In the end, I created a fully functional OpenThread Border Router:
In Fig. 2.1. you can see the active dataset that is running on the OpenThread Border Router. I have displayed it in the OTBR console using the command dataset active. To access the OTBR console, you can type sudo ot-ctl to open it in interactive mode.
The OTBR also has a web page that is hosted when the Border Router is active(Fig. 2.2.). It can be accessed from any device on the local network by typing the private IP address of the device that is hosting the OTBR, which in this case is 192.168.0.106.
Figure 2.3. shows the active topology of the OpenThread network, which changes automatically when a new device is added or removed or something changes in the running network. Right now there is only one device in the OpenThread network which is the Border Router.
In Figure 2.4. is shown how the OTBR is discovered from a mobile phone that is connected in the local network.
Creating the first device for the visual and sound indicationAfter setting up the Matter controller and the Border Router, I needed a device to test if everything was working properly. I decided to start with Node 4 from Fig. 1.
First, I copied the Matter template from the nRF Connect SDK and because I am using the nRF52840 Dongle, which isn't supported by default I need to make the following changes:
In the project folder, I have created a new file named pm_static_nrf52840dongle_nrf52840_no_dfu.yml
Figure 3.2. shows the contents of the file. I have defined the partitions for the memory of the nRF52840-Dongle.
The prj_no_dfu.conf file should have the configurations shown in Fig.3.3.
After all that I need to create the Endpoint that I need. This is done with the help of the ZAP tool. To run it, you need to navigate to the matter directory in the nRF Connect SDK, which in my case is ncs/v2.5.0/modules/lib/matter/. From there, the command to run the ZAP tool is:
./scripts/tools/zap/run_zaptool.sh ~/Downloads/buzzer_dongle/src/template.zap
in my case. After running it the ZAP tool is opened as shown in Fig 3.4.
From Fig. 3.4. you can see that I have already created the necessary endpoint, which is endpoint 1, while endpoint 0 exists by default. The steps to reproduce this are thoroughly documented in Adding clusters to Matter application.
After that I use the modified template.zap to generate the C++ code containing the selected clusters by running the following command:
python3 ./scripts/tools/zap/generate.py ~/Downloads/buzzer_dongle/src/template.zap -t src/app/zap-templates/app-templates.json -o ~/Downloads/buzzer_dongle/src/zap-generated
Next, you need to create an overlay file and select which GPIO pin to use to control the LED and the buzzer. I will turn on the buzzer and the LED simultaneously so I can use only one pin to control them.
I create the file - nrf52840dongle_nrf52840.overlay in the boards folder of the project, its contents are shown in Fig. 3.5.
I then worked on the app_event.h and app_config.h files. More importantly, I created a new file zcl_callbacks.cpp which has the logic to turn the LED and Buzzer on and off when an OnOff command is received.
Creating the second device for the temperature, humidity and gas detectionThe process of creating Node 3 is very similar to that of Node 4, so I won't go into detail about it. Here is a screenshot of the Endpoints I configured for it (see Fig.4.2.).
As you can see, Endpoint 4 is an illuminance endpoint and I am using it because there is no air quality or gas endpoint in the ZAP tool yet.
Creating the third device for controlling the window actuatorFor Node 1 I used nRF7002DK and with Matter over Wi-Fi I can control 2 relays which, when switched on, make the window actuator extend or retract.
Most of the code is from the light_bulb example in the nRF Connect SDK, although I have added an overlay file where I have placed the two relays on different GPIO pins. The attributes that control the relays are 2 and are both of type On/Off. The rest of the code is made analogous to Node 4
Creating the fourth device for controlling the air conditionerSince I had no more nRF52840 Dongles, I decided to create the IR transmitter device using an ESP32. For it I found IR libraries that support the air conditioner which I use - Fujitsu model ARRAH2E. Here is the code to turn the air conditioner on and off(at the moment I turn the air conditioner on and off every 10 seconds).
I also found a Matter library, but due to time limitations I didn't have time to configure this device with Matter.
Creating a Schematic and PCBI decided to create a schematic and design a PCB that can be used for both Node 3 and Node 4, as they are very similar by design. Figure 7.3. shows the schematic and figure 7.4. shows the printed circuit board.
First, I developed a solution for powering Node 3 or/and node 4 with a battery. In short, I have added the TP4056 Lithium Battery Charger Module, to it I connected a Li-ion Battery, added a Schottky diode for protection in case you connect the cable for charging the lithium battery from the TP4056 and the USB at the same time, a regulator to lower the voltage to exactly 3V (which is the voltage needed to power on the nRF52840 Dongle), and capacitors used to filter unwanted noise and to stabilize the signal. Finally, before I could connect the dongle to the external power supply, I had to cut connection SB2 and solder SB1 on the nRF52840 Dongle as shown in Figure 7.1.
On Figure 7.2. with red are shown the connections that I am modifying to provide external power to the board. In Figure 7.3. on the left side you can see the added battery power circuit to the schematic of my whole device.
I also created a 3D model of the board, which is shown on Figure 7.5.
Connecting the devices with CHIP ToolI used the following commands to commission the nodes in my matter network:
For Matter over Wi-Fi:
./chip-tool pairing ble-wifi <node_id> <ssid> <password> <pin_code> <discriminator>
For Matter over Thread:
./chip-tool pairing ble-thread <node_id> hex:<operational_dataset> <pin_code> <discriminator>
To toggle the onoff cluster I used the following command:
./chip-tool onoff toggle <node_id> <endpoint_id>
To get temperature readings I used:
./chip-tool temperaturemeasurement read measured-value <node_id> <endpoint_id>
To get humidity readings I used:
./chip-tool relativehumiditymeasurement read measured-value <node_id> <endpoint_id>
To get air quality reading I used (i have recycled the illuminance ednpoint):
./chip-tool illuminancemeasurement read measured-value <node_id> <endpoint_id>
The logic that connects everything togetherDue to time constraints, I was not able to finalize the logic that will automate the whole process of toggling each node on and off based on the measurement readings.
TestingHere is a working demo of the project.
Future realizationI plan to continue working on the project and bring it to its full potential by adding the whole automation logic, finishing Node 2 and adding more advanced features.
Sources that I used in the development of the projectI mainly followed the tutorial from Nordic for the creation of the Matter controller and Thread Border Router - https://docs.nordicsemi.com/bundle/ncs-2.2.0/page/nrf/ug_matter_gs_testing_thread_separate_otbr_android.html
I used the Working with the CHIP Tool guide to learn how to commission the devices and control them. - https://docs.nordicsemi.com/bundle/ncs-latest/page/matter/chip_tool_guide.html
I used this repository that helped me a lot for creating my code for Node 3 and 4 -
https://github.com/samuel-barrett/nrf5340-matter-sensor-test
I used this library for the IR transmission code - https://github.com/crankyoldgit/IRremoteESP8266
Comments