Skip to content

Add matter over thread #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build

on:
push:
branches:
- main
- feature/*

workflow_dispatch:

permissions: read-all

jobs:
trunk_check:
name: Trunk Check
runs-on: ubuntu-latest
permissions:
checks: write # For trunk to post annotations
contents: read # For repo checkout

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Trunk Check
uses: trunk-io/trunk-action@v1

build_docker_image:
name: Build docker image
runs-on: ubuntu-latest
needs: trunk_check
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
context: ./ci/docker/
tags: ghcr.io/begoonlab/esp_idf_xiao_esp32c6_sensor:latest
cache-from: type=gha
cache-to: type=gha,mode=max

build_for_wifi:
name: Build firmware for WiFi setup
runs-on: ubuntu-latest
needs: build_docker_image
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build firmware
run: |
docker run --rm -t \
-v $PWD:/opt/esp/project \
-w /opt/esp/project \
ghcr.io/begoonlab/esp_idf_xiao_esp32c6_sensor:latest idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.ci.wifi" build
4 changes: 4 additions & 0 deletions .trunk/configs/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Following source doesn't work in most setups
ignored:
- SC1090
- SC1091
7 changes: 7 additions & 0 deletions .trunk/configs/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
24 changes: 15 additions & 9 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.8
version: 1.22.9
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.6
ref: v1.6.7
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected].0
- black@24.10.0
- [email protected].344
- [email protected].2
- black@25.1.0
- [email protected].358
- git-diff-check
- isort@5.13.2
- markdownlint@0.43.0
- isort@6.0.0
- markdownlint@0.44.0
- [email protected]
- [email protected]
- ruff@0.8.4
- [email protected].0
- ruff@0.9.3
- [email protected].3
- [email protected]
ignore:
- linters: [ALL]
Expand All @@ -40,6 +45,7 @@ lint:
- venv/**
- cmake-*/**
- vendor/**
- ci/docker/Dockerfile
actions:
enabled:
- trunk-announce
Expand Down
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,26 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")

set(PROJECT_VER "1.0")
set(PROJECT_VER_NUMBER 1)

set(ESP_MATTER_PATH "/opt/esp/esp-matter")
set(MATTER_SDK_PATH ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

set(EXTRA_COMPONENT_DIRS
"${ESP_MATTER_PATH}/examples/common"
"${MATTER_SDK_PATH}/config/esp32/components"
"${ESP_MATTER_PATH}/components" ${extra_components_dirs_append})

project(xiao_esp32c6_wifi_sensor)

idf_build_set_property(
CXX_COMPILE_OPTIONS
"-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H;-Wno-overloaded-virtual" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND)
# For RISCV chips, project_include.cmake sets -Wno-format, but does not clear
# various flags that depend on -Wformat
idf_build_set_property(COMPILE_OPTIONS
"-Wno-format-nonliteral;-Wno-format-security" APPEND)
82 changes: 63 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
- [Hardware](#hardware)
- [Software](#software)
- [ZigBee](#zigbee)
- [Matter over Thread](#matter-over-thread)
- [Contributing](#contributing)
- [License](#license)
- [TODO](#todo)

## Introduction

The Smart IoT Sensor is a power-efficient device built using the [XIAO ESP32C6](https://wiki.seeedstudio.com/xiao_esp32c6_getting_started/) tiny board. It integrates Wi-Fi connectivity, MQTT messaging, environmental sensing with BME280/BME680 sensors, and robust power management, making it an ideal solution for smart home and IoT applications.
The Smart IoT Sensor is a power-efficient device built using the [XIAO ESP32C6](https://wiki.seeedstudio.com/xiao_esp32c6_getting_started/) tiny board. It integrates Wi-Fi connectivity, MQTT messaging, ZigBee, Matter over Thread, environmental sensing with BME280/BME680 sensors, and robust power management, making it an ideal solution for smart home and IoT applications.

![introduction.jpg](assets/introduction.jpg)

Expand All @@ -33,6 +34,7 @@ The Smart IoT Sensor is a power-efficient device built using the [XIAO ESP32C6](
- **Power Management**: Efficiently manages power using LiPo batteries with built-in charge management.
- **Deep Sleep Mode**: Extends battery life by enabling deep sleep between data transmissions.
- **ZigBee Connectivity**: Seamless integration with ZigBee networks. Supports standard ZigBee clusters, easily pair your sensor with ZigBee coordinators like Home Assistant.
- **Matter over Thread Connectivity**: Implements Matter protocol over Thread to enable seamless interoperability with other Matter-compliant devices. Supports smart home ecosystems like Apple HomeKit, Google Home, and Amazon Alexa.
- **Optional Features**:
- Battery voltage monitoring
- Connection duration tracking
Expand All @@ -49,18 +51,20 @@ The sensor publishes data to an MQTT broker in the following JSON format:
```json
{
"ID": "7i29r9k9ltaxmbev",
"RSSI": -54,
"battery_voltage": 4.13,
"temperature": "24.28",
"humidity": "29.32",
"pressure": "999.54",
"connection_duration_ms": 1672
"RSSI": -61,
"battery_voltage": 3.96,
"battery_charge": 76,
"temperature": 4.72,
"humidity": 67.85,
"pressure": 1006.84,
"connection_duration_ms": 1411
}
```

- **ID**: Unique identifier of the sensor
- **RSSI**: Wi-Fi signal strength in dBm
- **battery_voltage**: Current battery voltage
- **battery_charge**: Current battery charge percentage
- **temperature**: Temperature reading from the BME sensor
- **humidity**: Humidity reading from the BME sensor
- **pressure**: Pressure reading from the BME sensor
Expand Down Expand Up @@ -248,9 +252,15 @@ Follow these steps to set up your Smart IoT Sensor:
1. **Clone the Repository**

```bash
git clone https://github.com/BegoonLab/xiao-esp32c6-wifi-sensor
git clone --depth 1 https://github.com/BegoonLab/xiao-esp32c6-wifi-sensor
```

```bash
cd xiao-esp32c6-wifi-sensor
git submodule update --init --recursive
```

```bash
python scripts/install.py
```

2. **Install Dependencies**
Expand Down Expand Up @@ -301,18 +311,21 @@ Follow these steps to set up your Smart IoT Sensor:

### Dependencies

- **ESP-IDF**: [Official development framework](https://docs.espressif.com/projects/esp-idf/en/v5.3.1/esp32/get-started/index.html#software) for Espressif chips.
- **Docker**: [Install docker](https://docs.docker.com/engine/install/).

### Building the Firmware

1. **Install ESP-IDF**

Follow the [ESP-IDF Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/v5.3.1/esp32/get-started/index.html) to set up the development environment.

1. **Build dockerized environment**
```bash
docker build ./ci/docker/ -t esp_idf_xiao_esp32c6_sensor:latest
```
2. **Configure the Project**

```bash
idf.py menuconfig
docker run --rm -it \
-v $PWD:/opt/esp/project \
-w /opt/esp/project \
esp_idf_xiao_esp32c6_sensor:latest idf.py menuconfig
```

- Set Wi-Fi credentials
Expand All @@ -322,30 +335,49 @@ Follow these steps to set up your Smart IoT Sensor:
3. **Build and Flash**

```bash
idf.py build
docker run --rm -t \
-v $PWD:/opt/esp/project \
-w /opt/esp/project \
esp_idf_xiao_esp32c6_sensor:latest idf.py build
```

```bash
docker run --device=<TARGET_PORT> \
--rm -v $PWD:/opt/esp/project \
-w /opt/esp/project \
-it esp_idf_xiao_esp32c6_sensor:latest \
idf.py -p <TARGET_PORT> flash
```

When a sensor misbehaves, it's helpful to output logs to diagnose the issue. By default, logging is disabled. To enable it, follow these steps:

1. Open the configuration menu:
```bash
idf.py menuconfig
docker run --rm -it \
-v $PWD:/opt/esp/project \
-w /opt/esp/project \
esp_idf_xiao_esp32c6_sensor:latest idf.py menuconfig
```
2. Navigate to:
`Component config` → `Log output` → `Default log verbosity`.
3. Set the verbosity level to `Info`.
4. Save the changes, and then execute the following command to build, flash, and monitor:
```bash
idf.py -p <TARGET_PORT> build flash monitor
docker run --device=<TARGET_PORT> \
--rm -v $PWD:/opt/esp/project \
-w /opt/esp/project \
-it esp_idf_xiao_esp32c6_sensor:latest idf.py -p <TARGET_PORT> build flash monitor
```

## ZigBee

ZigBee can be activated in the menu:

```bash
idf.py menuconfig
docker run --rm -it \
-v $PWD:/opt/esp/project \
-w /opt/esp/project \
esp_idf_xiao_esp32c6_sensor:latest idf.py menuconfig
```

Navigate to `XIAO Sensor Configuration` → `Select Sensor Connection Type` → `ZigBee`.
Expand All @@ -360,6 +392,18 @@ To add the sensor to Home Assistant: go to `Settings` → `Devices & Services`

_Note_: The SGP41 sensor is not currently supported because the ZigBee protocol does not include VOC and NOx clusters in its specification.

## Matter over Thread

Pairing options:

- Using manual code: `34970112332`
- Using QR code: `MT:Y.K9042C00KA0648G00`
- Or scan a QR code bellow:

<img alt="SensorXIAO_Matter_Pairing_QR.png" src="assets/SensorXIAO_Matter_Pairing_QR.png" width="100"/>

For production use case see the information [here](https://docs.espressif.com/projects/esp-matter/en/latest/esp32c6/production.html#the-esp-matter-mfg-tool-example).

## Contributing

Contributions are welcome! Please follow these steps:
Expand Down
Binary file added assets/SensorXIAO_Matter_Pairing_QR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions ci/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ARG IDF_VERSION="v5.3.1"
ARG IDF_INSTALL_TARGETS="esp32c6"
ARG DEBIAN_FRONTEND=noninteractive

FROM espressif/idf:${IDF_VERSION} AS esp-idf

ARG ESP_MATTER_CLONE_URL=https://github.com/espressif/esp-matter.git
ARG ESP_MATTER_CHECKOUT_REF=release/v1.4

RUN : \
&& apt-get update \
&& DEBIAN_FRONTEND=${DEBIAN_FRONTEND} apt-get install -fy --no-install-recommends \
libgirepository1.0-dev \
libssl-dev \
pkg-config \
python3 \
python3-pip \
&& apt-get clean \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& : # last line

WORKDIR /opt/esp
ENV ESP_MATTER_PATH=/opt/esp/esp-matter

RUN set -x \
&& mkdir -p $ESP_MATTER_PATH \
&& cd $ESP_MATTER_PATH \
&& git init \
&& git remote add origin $ESP_MATTER_CLONE_URL \
&& git fetch origin --depth=1 ${ESP_MATTER_CHECKOUT_REF} \
&& git checkout FETCH_HEAD \
&& git submodule update --init --depth 1 \
&& cd ./connectedhomeip/connectedhomeip \
&& ./scripts/checkout_submodules.py --platform esp32 linux --shallow \
&& cd ../.. \
&& ./install.sh \
&& : # last line

RUN set -x \
&& git config --global --add safe.directory /opt/esp/project \
&& git config --global --add safe.directory /opt/esp/idf/components/openthread/openthread \
&& mkdir -p /.cache/Espressif/ComponentManager \
&& chmod -R 755 /.cache/Espressif/ComponentManager \
&& : # last line

COPY entrypoint.sh /opt/esp/entrypoint.sh
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
CMD [ "/bin/bash" ]

WORKDIR /opt/esp/esp-matter
Loading
Loading