This code demonstrates a proof of concept for an IoT sensor setup to measure temperature, humidity, illumination (lux), and even co2, using the Matter standard.
- Adafruit ESP32 Feather microcontroller
- BMP280 Temperature and Pressure Sensor (connected using the I2C protocol)
- BH1750 Light Sensor (connected using the I2C protocol)
- Matter hub (Apple TV 4k 3rd Gen with Ethernet)
- iPhone with the Apple Home App installed
-
ESP-MATTER: Espressif's official SDK for Matter applications
- Link to a forked repository which includes functions for light and pressure readings
The purpose of this code is to provide a sample implementation of a temperature and illumination IoT sensor setup using the Matter standard. The code can be used as a starting point for building similar IoT sensor applications.
This setup procedure was test with an Apple Silicon Mac, but could likely be modified to work for Intel Macs, Linux machines, and potentially Windows.
git clone --recursive https://github.com/samuel-barrett/esp32-matter-sensor-test.git
-
Install git lf
brew install git-lfs
-
Clone the repository, using the following command:
git clone --recursive https://github.com/samuel-barrett/esp-matter.git
-
If you have cloned the repository, but need to add the submodules, use:
git submodule update --init --recursive
-
If you alerady have ESP-MATTER installed, you can do a shallow clone, and then fork that repository to use the samuel-barrett/esp-matter.git remote fork
-
To preserve your current esp-matter repository, you can copy the contents first
cp -rH [PATH TO ESP-MATTER]/esp-matter [SOME PATH]/esp-matter-fork
-
Then change directories to the esp-matter repository you want to modify, and change the remote to point to this fork: samuel-barrett/esp-matter
cd [ESP-MATTER Repository to modify] git remote set-url origin https://github.com/samuel-barrett/esp-matter.git git pull
-
-
Enable IDF_CCACHE
echo "export IDF_CCACHE_ENABLE=1" >> ~/.zshrc source ~/.zshrc
-
Install prerequisites:
# Install prerequisites brew install cmake cmake-docs ninja dfu-util ccache xcode-select --install # Clone version 4.4.3 of the ESP-IDF repo git clone --recursive https://github.com/espressif/esp-idf.git cd esp-idf git checkout v4.4.3 git submodule update --init --recursive source ~/.zshrc source ~/.zprofile # Install esp32 cd ~/esp-idf ./install.sh esp32 . ./export.sh
-
Install Visual Studio Code if not installed
-
Install and configure the extension named "Espressif IDF" by following the instructions provided here
- Note: If you have done a recursive clone then, the esp-idf repository is already downloaded, and you can select it during setup at esp32-matter-sensor-test/esp-idf
-
Install Prerequisite software (See: here)
brew install openssl pkg-config echo 'export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"' >> ~/.zshrc echo "export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"" >> ~/.zshrc echo "export LDFLAGS=\"-L/opt/homebrew/opt/openssl@3/lib\"" >> ~/.zshrc echo "export CPPFLAGS=\"-I/opt/homebrew/opt/openssl@3/include\"" >> ~/.zshrc
-
You may need to install ZAP
-
Activate
cd esp-matter/connectedhomeip/connectedhomeip/ source scripts/activate.sh
-
CD to esp32-matter-sensor-test
cd [PATH]/esp32-matter-sensor-test
-
Set ESP_MATTER_PATH
export ESP_MATTER_PATH="[# PATH to esp matter (e.g. /Users/esp-user/esp-matter)]"
-
Set target
idf.py set-target esp32
-
Add mdns dependency
idf.py add-dependency "espressif/mdns^1.0.7"
-
Make sure you are using a python version from .espressif
which python or which python3
-
Install lark
python -m pip install lark stringcase or python3 -m pip install lark stringcase
-
Open the esp32-matter-sensor-test folder in visual studio code
-
Type [CMD]+[SHIFT]+[P], then type
>ESP-IDF: Install ESP-Matter
-
Select "Yes, download all submodules" -> "Use existing repository"
- Select the forked repository from the previous step
-
Select the port to use
>ESP-IDF: Select port to use (COM,tty, usbserial)
-
Type [CMD]+[SHIFT]+[P], then type
>ESP-IDF: Build your project
-
Connect the BMP280, and BH1750 sensors to the microcontroller using the i2C protocol
-
To ensure, that the devices are connected properly, you can use the Arduino I2C scanner sketch
- First install the Arduino ID ESP32 addon
-
Select the correct Serial port and flash method (tested using UART), and then
-
Build and flash the code to the ESP32 microcontroller using the ESP-IDF tools. Type [CMD]+[SHIFT]+[P], then
>ESP-IDF: Build, Flash and start a monitor on your device
TODO: Find out how to get QR code
The code has been tested with a very specific set of devices, and is not designed to be portable. It can however, be modified to fit
The code is currently a basic implementation of the temperature and illumination sensor setup, and there is potential for future updates and improvements, such as:
- Adding more sensors or endpoints
- Adding support for different kinds of ESP32 development boards
- Improving the logging and data storage functionality
- Adding support for remote management and control