diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f17402c --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/.trunk/configs/.hadolint.yaml b/.trunk/configs/.hadolint.yaml new file mode 100644 index 0000000..98bf0cd --- /dev/null +++ b/.trunk/configs/.hadolint.yaml @@ -0,0 +1,4 @@ +# Following source doesn't work in most setups +ignored: + - SC1090 + - SC1091 diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc new file mode 100644 index 0000000..8c7b1ad --- /dev/null +++ b/.trunk/configs/.shellcheckrc @@ -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 diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 766e798..c617f0a 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -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: + - go@1.21.0 - node@18.20.5 - python@3.10.8 # This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) lint: enabled: + - actionlint@1.7.7 + - hadolint@2.12.1-beta + - shellcheck@0.10.0 + - shfmt@3.6.0 - taplo@0.9.3 - clang-format@16.0.3 - cmake-format@0.6.13 - clang-tidy@16.0.3 - - bandit@1.8.0 - - black@24.10.0 - - checkov@3.2.344 + - bandit@1.8.2 + - black@25.1.0 + - checkov@3.2.358 - git-diff-check - - isort@5.13.2 - - markdownlint@0.43.0 + - isort@6.0.0 + - markdownlint@0.44.0 - oxipng@9.1.3 - prettier@3.4.2 - - ruff@0.8.4 - - trufflehog@3.88.0 + - ruff@0.9.3 + - trufflehog@3.88.3 - yamllint@1.35.1 ignore: - linters: [ALL] @@ -40,6 +45,7 @@ lint: - venv/** - cmake-*/** - vendor/** + - ci/docker/Dockerfile actions: enabled: - trunk-announce diff --git a/CMakeLists.txt b/CMakeLists.txt index bc626d2..1d17f50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index fc6e3cd..15fdd23 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 @@ -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** @@ -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 @@ -322,7 +335,17 @@ 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= \ + --rm -v $PWD:/opt/esp/project \ + -w /opt/esp/project \ + -it esp_idf_xiao_esp32c6_sensor:latest \ idf.py -p flash ``` @@ -330,14 +353,20 @@ When a sensor misbehaves, it's helpful to output logs to diagnose the issue. By 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 build flash monitor + docker run --device= \ + --rm -v $PWD:/opt/esp/project \ + -w /opt/esp/project \ + -it esp_idf_xiao_esp32c6_sensor:latest idf.py -p build flash monitor ``` ## ZigBee @@ -345,7 +374,10 @@ When a sensor misbehaves, it's helpful to output logs to diagnose the issue. By 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`. @@ -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: + + SensorXIAO_Matter_Pairing_QR.png + +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: diff --git a/assets/SensorXIAO_Matter_Pairing_QR.png b/assets/SensorXIAO_Matter_Pairing_QR.png new file mode 100644 index 0000000..a783ae6 Binary files /dev/null and b/assets/SensorXIAO_Matter_Pairing_QR.png differ diff --git a/ci/docker/Dockerfile b/ci/docker/Dockerfile new file mode 100644 index 0000000..2cd193c --- /dev/null +++ b/ci/docker/Dockerfile @@ -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 \ No newline at end of file diff --git a/ci/docker/entrypoint.sh b/ci/docker/entrypoint.sh new file mode 100755 index 0000000..fe9532b --- /dev/null +++ b/ci/docker/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +source "${IDF_PATH}"/export.sh +source "${ESP_MATTER_PATH}"/export.sh + +exec "$@" diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 0234487..f209187 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,3 +1,10 @@ +idf_build_get_property(matter_enabled + CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD) + +if(${matter_enabled}) + set(PRIV_INCLUDE_DIRS_LIST "${ESP_MATTER_PATH}/examples/common/utils") +endif() + idf_component_register( SRCS "main.c" @@ -13,6 +20,7 @@ idf_component_register( "sensor_sgp.c" "sensor_sleep.c" "sensor_i2c.c" + "sensor_matter.cpp" "sensor_data.c" "../vendor/embedded-i2c-sgp41/sgp41_i2c.c" "../vendor/embedded-i2c-sgp41/sensirion_i2c.c" @@ -25,4 +33,11 @@ idf_component_register( "../vendor/embedded-i2c-sgp41" "../vendor/gas-index-algorithm/sensirion_gas_index_algorithm" "../vendor/boschsensortec/BME280_SensorAPI" - "../vendor/boschsensortec/BME68x_SensorAPI") + "../vendor/boschsensortec/BME68x_SensorAPI" + PRIV_INCLUDE_DIRS + ${PRIV_INCLUDE_DIRS_LIST}) + +if(${matter_enabled}) + set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) + target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") +endif() diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index b9190dd..e23ede7 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -6,6 +6,7 @@ menu "XIAO Sensor Configuration" Choose the type of sensor connection to use. - **WiFi + MQTT**: WiFi and MQTT. - **ZigBee**: ZigBee. + - **Matter over Thread**: Matter over Thread. config SENSOR_CONNECTION_WIFI_MQTT bool "WiFi + MQTT" @@ -17,6 +18,11 @@ menu "XIAO Sensor Configuration" help Enable ZigBee connection. + config SENSOR_CONNECTION_MATTER_OVER_THREAD + bool "Matter over Thread" + help + Enable Matter over Thread connection. + endchoice menu "Wi-Fi Configuration" depends on SENSOR_CONNECTION_WIFI_MQTT @@ -239,6 +245,22 @@ menu "XIAO Sensor Configuration" Use an external antenna for ZigBee connectivity. endmenu + menu "Matter over Thread Configuration" + depends on SENSOR_CONNECTION_MATTER_OVER_THREAD + config SENSOR_ID + string "Sensor ID" + default "" + help + Unique identifier for the sensor. + + If left empty, the device's MAC address will be used as the Sensor ID. + + config MATTER_OVER_THREAD_ANTENNA_EXTERNAL + bool "External Antenna" + help + Use an external antenna for ZigBee connectivity. + endmenu + menu "Sensor Configuration" config SENSOR_BME680 bool "BME680" diff --git a/main/idf_component.yml b/main/idf_component.yml index aca77ce..4e1b3b5 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -1,7 +1,13 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "~1.5.0" - espressif/esp-zigbee-lib: "~1.5.0" + espressif/button: =2.5.0 + espressif/esp_diag_data_store: ==1.0.2 + espressif/esp_secure_cert_mgr: "*" + espressif/esp-zboss-lib: ~1.5.0 + espressif/esp-zigbee-lib: ~1.5.0 ## Required IDF version idf: version: ">=5.3.1" + espressif/json_parser: "*" + espressif/json_generator: "*" + espressif/mdns: "*" diff --git a/main/main.c b/main/main.c index 7e864da..759810a 100644 --- a/main/main.c +++ b/main/main.c @@ -48,6 +48,20 @@ #include "sensor_sgp.h" #endif +#ifdef CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD + +#ifdef __cplusplus +extern "C" { +#endif + +#include "sensor_matter.h" + +#ifdef __cplusplus +} +#endif + +#endif + static const char *TAG = "sensor_main"; char sensor_id[SENSOR_ID_MAX_LEN] = {0}; @@ -55,11 +69,12 @@ SensorData sensor_data; void app_main(void) { init_sensor_data(&sensor_data); + ESP_LOGI(TAG, "FW version: %s", GIT_COMMIT_HASH); + #ifdef CONFIG_ENABLE_BATTERY_CHECK init_adc(); check_battery(&sensor_data); ESP_LOGI(TAG, "Battery Voltage: %.2f V", sensor_data.battery.voltage); - ESP_LOGI(TAG, "FW version: %s", GIT_COMMIT_HASH); deinit_adc(); #endif @@ -96,4 +111,9 @@ void app_main(void) { init_zb(); start_zb(); #endif -} \ No newline at end of file + +#ifdef CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD + init_matter(); + start_matter(); +#endif +} diff --git a/main/sensor_bme.c b/main/sensor_bme.c index fbcce54..41498ff 100644 --- a/main/sensor_bme.c +++ b/main/sensor_bme.c @@ -40,6 +40,7 @@ static i2c_master_dev_handle_t bme280_i2c_handle; #endif void bme280_init_after_sleep() { +#ifdef CONFIG_SENSOR_BME280 int8_t rslt = bme280_init(&dev); bme280_error_codes_print_result("bme280_init", rslt); @@ -60,6 +61,7 @@ void bme280_init_after_sleep() { rslt = bme280_set_sensor_settings(BME280_SEL_ALL_SETTINGS, &settings, &dev); bme280_error_codes_print_result("bme280_set_sensor_settings", rslt); +#endif } void init_bme(void) { diff --git a/main/sensor_gpio.c b/main/sensor_gpio.c index bacd2db..bee142c 100644 --- a/main/sensor_gpio.c +++ b/main/sensor_gpio.c @@ -16,11 +16,14 @@ void init_gpio(void) { #if defined(CONFIG_WIFI_ANTENNA_EXTERNAL) || \ - defined(CONFIG_ZIGBEE_ANTENNA_EXTERNAL) + defined(CONFIG_ZIGBEE_ANTENNA_EXTERNAL) || \ + defined(CONFIG_MATTER_OVER_THREAD_ANTENNA_EXTERNAL) gpio_reset_pin(GPIO_NUM_3); gpio_set_direction(GPIO_NUM_3, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_3, LOW); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_reset_pin(GPIO_NUM_14); gpio_set_direction(GPIO_NUM_14, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_14, HIGH); diff --git a/main/sensor_gpio.h b/main/sensor_gpio.h index 9d47646..a415432 100644 --- a/main/sensor_gpio.h +++ b/main/sensor_gpio.h @@ -12,5 +12,6 @@ #pragma once #include "driver/gpio.h" +#include "freertos/FreeRTOS.h" void init_gpio(void); \ No newline at end of file diff --git a/main/sensor_i2c.c b/main/sensor_i2c.c index a25071a..2549ca7 100644 --- a/main/sensor_i2c.c +++ b/main/sensor_i2c.c @@ -15,6 +15,7 @@ static i2c_master_bus_handle_t bus_handle; void init_i2c(void) { +#ifdef MASTER_I2C_PORT i2c_master_bus_config_t i2c_mst_config = { .clk_source = I2C_CLK_SRC_DEFAULT, .i2c_port = MASTER_I2C_PORT, @@ -24,6 +25,7 @@ void init_i2c(void) { }; ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle)); +#endif } // Get or create a device handle for the given address @@ -46,4 +48,8 @@ void release_i2c_device(i2c_master_dev_handle_t dev_handle) { ESP_ERROR_CHECK(i2c_master_bus_rm_device(dev_handle)); } -void deinit_i2c(void) { ESP_ERROR_CHECK(i2c_del_master_bus(bus_handle)); } \ No newline at end of file +void deinit_i2c(void) { +#ifdef MASTER_I2C_PORT + ESP_ERROR_CHECK(i2c_del_master_bus(bus_handle)); +#endif +} \ No newline at end of file diff --git a/main/sensor_matter.cpp b/main/sensor_matter.cpp new file mode 100644 index 0000000..584079f --- /dev/null +++ b/main/sensor_matter.cpp @@ -0,0 +1,223 @@ +/** + * @file sensor_matter.cpp + * @author Alexander Begoon + * @date 03 January 2025 + * @brief //TODO + * + * @details //TODO + * + * @copyright Copyright (c) 2024 BegoonLab. + * All rights reserved. + */ + +#ifdef CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD + +#include "sensor_matter.h" +#include "esp_matter.h" +#include "esp_matter_ota.h" +#include "sensor_openthread.h" +#include +#include +#include + +static const char *TAG = "sensor_matter"; + +using namespace esp_matter; +using namespace esp_matter::attribute; +using namespace esp_matter::endpoint; +using namespace chip::app::Clusters; + +static void open_commissioning_window_if_necessary() { + VerifyOrReturn(chip::Server::GetInstance().GetFabricTable().FabricCount() == + 0); + + chip::CommissioningWindowManager &commissionMgr = + chip::Server::GetInstance().GetCommissioningWindowManager(); + VerifyOrReturn(commissionMgr.IsCommissioningWindowOpen() == false); + + // After removing last fabric, this example does not remove the Wi-Fi + // credentials and still has IP connectivity so, only advertising on DNS-SD. + CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow( + chip::System::Clock::Seconds16(300), + chip::CommissioningWindowAdvertisement::kAllSupported); + if (err != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to open commissioning window, err:%s", + err.AsString()); + } +} + +static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { + switch (event->Type) { + case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: + ESP_LOGI(TAG, "Commissioning complete"); + break; + + case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired: + ESP_LOGI(TAG, "Commissioning failed, fail safe timer expired"); + break; + + case chip::DeviceLayer::DeviceEventType::kFabricRemoved: + ESP_LOGI(TAG, "Fabric removed successfully"); + open_commissioning_window_if_necessary(); + break; + + case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized: + ESP_LOGI(TAG, "BLE deinitialized and memory reclaimed"); + break; + + default: + break; + } +} + +esp_err_t start_matter(void) { + /* Matter start */ + esp_err_t err = esp_matter::start(app_event_cb); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to start Matter, err:%d", err); + } + + return err; +} + +// This callback is invoked when clients interact with the Identify Cluster. +// In the callback implementation, an endpoint can identify itself. (e.g., by +// flashing an LED or light). +static esp_err_t app_identification_cb(identification::callback_type_t type, + uint16_t endpoint_id, uint8_t effect_id, + uint8_t effect_variant, + void *priv_data) { + ESP_LOGI(TAG, "Identification callback: type: %u, effect: %u, variant: %u", + type, effect_id, effect_variant); + return ESP_OK; +} + +// This callback is called for every attribute update. The callback +// implementation shall handle the desired attributes and return an appropriate +// error code. If the attribute is not of your interest, please do not return an +// error code and strictly return ESP_OK. +static esp_err_t +app_attribute_update_cb(attribute::callback_type_t type, uint16_t endpoint_id, + uint32_t cluster_id, uint32_t attribute_id, + esp_matter_attr_val_t *val, void *priv_data) { + // Since this is just a sensor and we don't expect any writes on our + // temperature sensor, so, return success. + return ESP_OK; +} + +esp_err_t init_matter(void) { + /* Create a Matter node and add the mandatory Root Node device type on + * endpoint 0 */ + node::config_t node_config; + node_t *node = node::create(&node_config, app_attribute_update_cb, + app_identification_cb); + + if (node == nullptr) { + ESP_LOGE(TAG, "Failed to create Matter node"); + } + + // add temperature sensor device + temperature_sensor::config_t temp_sensor_config; + endpoint_t *temp_sensor_ep = temperature_sensor::create( + node, &temp_sensor_config, ENDPOINT_FLAG_NONE, NULL); + if (temp_sensor_ep == nullptr) { + ESP_LOGE(TAG, "Failed to create temperature_sensor endpoint"); + } + + // add the humidity sensor device + humidity_sensor::config_t humidity_sensor_config; + endpoint_t *humidity_sensor_ep = humidity_sensor::create( + node, &humidity_sensor_config, ENDPOINT_FLAG_NONE, NULL); + if (humidity_sensor_ep == nullptr) { + ESP_LOGE(TAG, "Failed to create humidity_sensor endpoint"); + } + + // add the pressure sensor device + pressure_sensor::config_t pressure_sensor_config; + endpoint_t *pressure_sensor_ep = pressure_sensor::create( + node, &pressure_sensor_config, ENDPOINT_FLAG_NONE, NULL); + if (pressure_sensor_ep == nullptr) { + ESP_LOGE(TAG, "Failed to create pressure_sensor endpoint"); + } + + // Set temperature + double temperature = 21.03; + uint16_t temp_endpoint_id = endpoint::get_id(temp_sensor_ep); + // chip::DeviceLayer::SystemLayer().ScheduleLambda([temp_endpoint_id, + // temperature, temp_sensor_ep]() { + cluster_t *temp_cluster = + cluster::get(temp_sensor_ep, TemperatureMeasurement::Id); + attribute_t *temp_attribute = attribute::get( + temp_cluster, TemperatureMeasurement::Attributes::MeasuredValue::Id); + if (temp_attribute == nullptr) { + ESP_LOGE(TAG, "Failed to get temp_attribute"); + } + + esp_matter_attr_val_t temp_val = esp_matter_invalid(NULL); + attribute::get_val(temp_attribute, &temp_val); + temp_val.val.u16 = static_cast(temperature * 100); + ESP_LOGI(TAG, "temp_endpoint_id %hu", temp_endpoint_id); + ESP_LOGI(TAG, "temp_cluster_id %lu", TemperatureMeasurement::Id); + ESP_LOGI(TAG, "temp_attribute_id %lu", + TemperatureMeasurement::Attributes::MeasuredValue::Id); + attribute::update(temp_endpoint_id, TemperatureMeasurement::Id, + TemperatureMeasurement::Attributes::MeasuredValue::Id, + &temp_val); + // }); + + // Set humidity + double humidity = 47.56; + uint16_t humidity_endpoint_id = endpoint::get_id(humidity_sensor_ep); + // chip::DeviceLayer::SystemLayer().ScheduleLambda([humidity_endpoint_id, + // humidity, humidity_sensor_ep]() { + cluster_t *humidity_cluster = + cluster::get(humidity_sensor_ep, RelativeHumidityMeasurement::Id); + attribute_t *humidity_attribute = attribute::get( + humidity_cluster, + RelativeHumidityMeasurement::Attributes::MeasuredValue::Id); + if (humidity_attribute == nullptr) { + ESP_LOGE(TAG, "Failed to get humidity_attribute"); + } + + esp_matter_attr_val_t humidity_val = esp_matter_invalid(NULL); + attribute::get_val(humidity_attribute, &humidity_val); + humidity_val.val.u16 = static_cast(humidity * 100); + + attribute::update(humidity_endpoint_id, RelativeHumidityMeasurement::Id, + RelativeHumidityMeasurement::Attributes::MeasuredValue::Id, + &humidity_val); + // }); + + // Set pressure + double pressure = 1001.34; + uint16_t pressure_endpoint_id = endpoint::get_id(pressure_sensor_ep); + // chip::DeviceLayer::SystemLayer().ScheduleLambda([pressure_endpoint_id, + // pressure, pressure_sensor_ep]() { + cluster_t *pressure_cluster = + cluster::get(pressure_sensor_ep, PressureMeasurement::Id); + attribute_t *pressure_attribute = attribute::get( + pressure_cluster, PressureMeasurement::Attributes::MeasuredValue::Id); + if (pressure_attribute == nullptr) { + ESP_LOGE(TAG, "Failed to get pressure_attribute"); + } + + esp_matter_attr_val_t pressure_val = esp_matter_invalid(NULL); + attribute::get_val(pressure_attribute, &pressure_val); + pressure_val.val.u16 = static_cast(pressure * 10); + + attribute::update(pressure_endpoint_id, PressureMeasurement::Id, + PressureMeasurement::Attributes::MeasuredValue::Id, + &pressure_val); + // }); + + esp_openthread_platform_config_t config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + set_openthread_platform_config(&config); + + return ESP_OK; +} + +#endif \ No newline at end of file diff --git a/main/sensor_matter.h b/main/sensor_matter.h new file mode 100644 index 0000000..1b621bb --- /dev/null +++ b/main/sensor_matter.h @@ -0,0 +1,28 @@ +/** + * @file sensor_matter.h + * @author Alexander Begoon + * @date 03 January 2025 + * @brief //TODO + * + * @details //TODO + * + * @copyright Copyright (c) 2024 BegoonLab. + * All rights reserved. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "esp_err.h" +#include "esp_log.h" + +esp_err_t init_matter(void); +esp_err_t start_matter(void); +esp_err_t stop_matter(void); + +#ifdef __cplusplus +} +#endif diff --git a/main/sensor_openthread.h b/main/sensor_openthread.h new file mode 100644 index 0000000..7307a8b --- /dev/null +++ b/main/sensor_openthread.h @@ -0,0 +1,32 @@ +/** + * @file sensor_openthread.h + * @author Alexander Begoon + * @date 03 January 2025 + * @brief //TODO + * + * @details //TODO + * + * @copyright Copyright (c) 2024 BegoonLab. + * All rights reserved. + */ + +#pragma once + +#ifdef CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD +#include "esp_openthread_types.h" +#include + +#if SOC_IEEE802154_SUPPORTED +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { .radio_mode = RADIO_MODE_NATIVE, } +#endif + +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ + { .host_connection_mode = HOST_CONNECTION_MODE_NONE, } + +#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ + { \ + .storage_partition_name = "nvs", .netif_queue_size = 10, \ + .task_queue_size = 10, \ + } +#endif // CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD \ No newline at end of file diff --git a/partitions.csv b/partitions.csv index cb78974..42cb75b 100644 --- a/partitions.csv +++ b/partitions.csv @@ -1,7 +1,11 @@ -# Name, Type, SubType, Offset, Size, Flags +# Name, Type, SubType, Offset, Size, Flags # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 0x180000, -zb_storage, data, fat, 0x190000, 0x4000 -zb_fct, data, fat, 0x194000, 0x400 +nvs, data, nvs, 0x9000, 0x6000, +esp_secure_cert, data, 0x3F, 0xF000, 0x2000, encrypted +nvs_keys, data, nvs_keys, 0x11000, 0x1000, encrypted +phy_init, data, phy, 0x12000, 0x1000, +otadata, data, ota, 0x13000, 0x2000, +zb_storage, data, fat, 0x15000, 0x4000, +zb_fct, data, fat, 0x19000, 0x400, +ota_0, app, ota_0, 0x20000, 0x1E0000, +ota_1, app, ota_1, 0x200000, 0x1E0000, diff --git a/sdkconfig.ci.matter b/sdkconfig.ci.matter new file mode 100644 index 0000000..40a9d83 --- /dev/null +++ b/sdkconfig.ci.matter @@ -0,0 +1,151 @@ +CONFIG_IDF_TARGET="esp32c6" +CONFIG_SENSOR_CONNECTION_MATTER_OVER_THREAD=y +CONFIG_SENSOR_BME280=y +CONFIG_ENABLE_BATTERY_CHECK=y + +# +# Partition Table +# +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0x8000 +CONFIG_PARTITION_TABLE_MD5=y +# end of Partition Table + +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +# end of Compiler options + +# +# mbedTLS +# +CONFIG_MBEDTLS_HARDWARE_AES=n +CONFIG_MBEDTLS_HARDWARE_MPI=n +CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_CMAC_C=y +CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +# end of TLS Key Exchange Methods + +CONFIG_MBEDTLS_ECJPAKE_C=y +# end of mbedTLS + +# +# Zboss +# +CONFIG_ZB_ENABLED=y +CONFIG_ZB_ZED=y +# end of Zboss +# end of Component config + +# +# Log output +# +CONFIG_LOG_DEFAULT_LEVEL_NONE=y +# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set +# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set +# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set +# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_LOG_DEFAULT_LEVEL=0 +CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y +# CONFIG_LOG_MAXIMUM_LEVEL_ERROR is not set +# CONFIG_LOG_MAXIMUM_LEVEL_WARN is not set +# CONFIG_LOG_MAXIMUM_LEVEL_INFO is not set +# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set +# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set +CONFIG_LOG_MAXIMUM_LEVEL=0 +# CONFIG_LOG_MASTER_LEVEL is not set +CONFIG_LOG_COLORS=y +CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y +# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set +# end of Log output + +# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set + +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_PERF=y + +# +# PHY +# +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y + +# +# Serial flasher config +# +# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_BORDER_ROUTER=n +CONFIG_OPENTHREAD_DNS64_CLIENT=y +# CONFIG_OPENTHREAD_CLI is not set +# end of OpenThread + +# +# lwIP +# +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_IPV4=y +CONFIG_LWIP_ND6=y +# end of lwIP + +# +# IEEE 802.15.4 +# +CONFIG_IEEE802154_ENABLED=y +# end of IEEE 802.15.4 + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n + +CONFIG_ENABLE_WIFI_AP=n + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +CONFIG_THREAD_NETWORK_ENDPOINT_ID=0 +CONFIG_WIFI_NETWORK_ENDPOINT_ID=2 \ No newline at end of file diff --git a/sdkconfig.ci.wifi b/sdkconfig.ci.wifi new file mode 100644 index 0000000..dd13ee9 --- /dev/null +++ b/sdkconfig.ci.wifi @@ -0,0 +1,151 @@ +CONFIG_IDF_TARGET="esp32c6" +CONFIG_SENSOR_CONNECTION_WIFI_MQTT=y +CONFIG_SENSOR_BME280=y +CONFIG_ENABLE_BATTERY_CHECK=y + +# +# Partition Table +# +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0x8000 +CONFIG_PARTITION_TABLE_MD5=y +# end of Partition Table + +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +# end of Compiler options + +# +# mbedTLS +# +CONFIG_MBEDTLS_HARDWARE_AES=n +CONFIG_MBEDTLS_HARDWARE_MPI=n +CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_CMAC_C=y +CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +# end of TLS Key Exchange Methods + +CONFIG_MBEDTLS_ECJPAKE_C=y +# end of mbedTLS + +# +# Zboss +# +CONFIG_ZB_ENABLED=y +CONFIG_ZB_ZED=y +# end of Zboss +# end of Component config + +# +# Log output +# +CONFIG_LOG_DEFAULT_LEVEL_NONE=y +# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set +# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set +# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set +# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_LOG_DEFAULT_LEVEL=0 +CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y +# CONFIG_LOG_MAXIMUM_LEVEL_ERROR is not set +# CONFIG_LOG_MAXIMUM_LEVEL_WARN is not set +# CONFIG_LOG_MAXIMUM_LEVEL_INFO is not set +# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set +# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set +CONFIG_LOG_MAXIMUM_LEVEL=0 +# CONFIG_LOG_MASTER_LEVEL is not set +CONFIG_LOG_COLORS=y +CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y +# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set +# end of Log output + +# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set + +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_PERF=y + +# +# PHY +# +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y + +# +# Serial flasher config +# +# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_BORDER_ROUTER=n +CONFIG_OPENTHREAD_DNS64_CLIENT=y +# CONFIG_OPENTHREAD_CLI is not set +# end of OpenThread + +# +# lwIP +# +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_IPV4=y +CONFIG_LWIP_ND6=y +# end of lwIP + +# +# IEEE 802.15.4 +# +CONFIG_IEEE802154_ENABLED=y +# end of IEEE 802.15.4 + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n + +CONFIG_ENABLE_WIFI_AP=n + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +CONFIG_THREAD_NETWORK_ENDPOINT_ID=0 +CONFIG_WIFI_NETWORK_ENDPOINT_ID=2 \ No newline at end of file diff --git a/sdkconfig.ci.zigbee b/sdkconfig.ci.zigbee new file mode 100644 index 0000000..1321d5c --- /dev/null +++ b/sdkconfig.ci.zigbee @@ -0,0 +1,151 @@ +CONFIG_IDF_TARGET="esp32c6" +CONFIG_SENSOR_CONNECTION_ZIGBEE=y +CONFIG_SENSOR_BME280=y +CONFIG_ENABLE_BATTERY_CHECK=y + +# +# Partition Table +# +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0x8000 +CONFIG_PARTITION_TABLE_MD5=y +# end of Partition Table + +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +# end of Compiler options + +# +# mbedTLS +# +CONFIG_MBEDTLS_HARDWARE_AES=n +CONFIG_MBEDTLS_HARDWARE_MPI=n +CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_CMAC_C=y +CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +# end of TLS Key Exchange Methods + +CONFIG_MBEDTLS_ECJPAKE_C=y +# end of mbedTLS + +# +# Zboss +# +CONFIG_ZB_ENABLED=y +CONFIG_ZB_ZED=y +# end of Zboss +# end of Component config + +# +# Log output +# +CONFIG_LOG_DEFAULT_LEVEL_NONE=y +# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set +# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set +# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set +# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_LOG_DEFAULT_LEVEL=0 +CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y +# CONFIG_LOG_MAXIMUM_LEVEL_ERROR is not set +# CONFIG_LOG_MAXIMUM_LEVEL_WARN is not set +# CONFIG_LOG_MAXIMUM_LEVEL_INFO is not set +# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set +# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set +CONFIG_LOG_MAXIMUM_LEVEL=0 +# CONFIG_LOG_MASTER_LEVEL is not set +CONFIG_LOG_COLORS=y +CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y +# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set +# end of Log output + +# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set + +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_PERF=y + +# +# PHY +# +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y + +# +# Serial flasher config +# +# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_BORDER_ROUTER=n +CONFIG_OPENTHREAD_DNS64_CLIENT=y +# CONFIG_OPENTHREAD_CLI is not set +# end of OpenThread + +# +# lwIP +# +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_IPV4=y +CONFIG_LWIP_ND6=y +# end of lwIP + +# +# IEEE 802.15.4 +# +CONFIG_IEEE802154_ENABLED=y +# end of IEEE 802.15.4 + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n + +CONFIG_ENABLE_WIFI_AP=n + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +CONFIG_THREAD_NETWORK_ENDPOINT_ID=0 +CONFIG_WIFI_NETWORK_ENDPOINT_ID=2 \ No newline at end of file diff --git a/sdkconfig.defaults b/sdkconfig.defaults index ee9f518..853d0df 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -1,3 +1,5 @@ +CONFIG_IDF_TARGET="esp32c6" + # # Partition Table # @@ -8,6 +10,13 @@ CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_MD5=y # end of Partition Table +# +# Compiler options +# +# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +# end of Compiler options + # # mbedTLS # @@ -66,4 +75,74 @@ CONFIG_COMPILER_OPTIMIZATION_PERF=y # # PHY # -CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y \ No newline at end of file +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y + +# +# Serial flasher config +# +# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_BORDER_ROUTER=n +CONFIG_OPENTHREAD_DNS64_CLIENT=y +# CONFIG_OPENTHREAD_CLI is not set +# end of OpenThread + +# +# lwIP +# +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_IPV4=y +CONFIG_LWIP_ND6=y +# end of lwIP + +# +# IEEE 802.15.4 +# +CONFIG_IEEE802154_ENABLED=y +# end of IEEE 802.15.4 + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n + +CONFIG_ENABLE_WIFI_AP=n + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +CONFIG_THREAD_NETWORK_ENDPOINT_ID=0 +CONFIG_WIFI_NETWORK_ENDPOINT_ID=2 \ No newline at end of file