Skip to content
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

ESP Matter + Arduino as IDF Component Light example #10290

Merged
merged 48 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
45261f9
feat(matter): partition file for matter
SuGlider Sep 4, 2024
2d5ed93
feat(matter): matter light source code
SuGlider Sep 4, 2024
8c39ce0
feat(matter): adds sdkconfig and CMake files
SuGlider Sep 4, 2024
4f0f2d0
fix(matter): wrong folder name
SuGlider Sep 4, 2024
293f066
feat(matter): include example into registry
SuGlider Sep 4, 2024
a8df9ec
Merge branch 'espressif:master' into esp_matter_light_example
SuGlider Sep 12, 2024
2951f6a
fix(matter): error with type in wrong place
SuGlider Sep 12, 2024
e86952f
Merge branch 'espressif:master' into esp_matter_light_example
SuGlider Sep 14, 2024
37ed1d5
feat(matter): add readme documentation
SuGlider Sep 14, 2024
d418363
feat(matter): remove soc with no wifi or no ble
SuGlider Sep 14, 2024
04391c9
feat(matter): adjust all sdkconfig files
SuGlider Sep 14, 2024
196f63d
feat(matter): improve code and led status
SuGlider Sep 14, 2024
63c8e83
feat(matter): add button and led gpio with kconfig
SuGlider Sep 14, 2024
6fe9d26
fix(matter): remove commented lines
SuGlider Sep 14, 2024
1be6b0e
fix(matter): remove commented lines
SuGlider Sep 14, 2024
365bb07
Merge branch 'master' into esp_matter_light_example
SuGlider Sep 16, 2024
b392e8a
feat(matter): added a 2.4GHz SSID note
SuGlider Sep 16, 2024
f30ad99
feat(matter): arduino managed comonent version
SuGlider Sep 16, 2024
bae7b60
Merge branch 'master' into esp_matter_light_example
SuGlider Sep 17, 2024
fe50297
feat(matter): adds information about google
SuGlider Sep 17, 2024
2c18489
feat(matter): arduino component version
SuGlider Sep 17, 2024
ed71437
Merge branch 'master' into esp_matter_light_example
SuGlider Sep 17, 2024
2dd56d1
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] Sep 18, 2024
cafb78d
Merge branch 'master' into esp_matter_light_example
SuGlider Sep 18, 2024
9f1c706
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
6b56195
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
40ead46
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
e361e75
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
14eee60
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
d46fafc
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
ea5f261
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
4d576d4
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
99dc865
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
91a06ee
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
7efd65e
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
e7623e2
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
fd02781
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
a9527de
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
dc90ee8
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
27383e0
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
bdf04b4
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
13a95f8
fix(typo): typo and commentaries
SuGlider Sep 18, 2024
7713e03
fix(matter): spell check ignore for CI
SuGlider Sep 18, 2024
9b55b76
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] Sep 18, 2024
5b5a2a8
fix(matter): spell check ignore for CI
SuGlider Sep 18, 2024
ca63443
fix(matter): spell check ignore for CI
SuGlider Sep 18, 2024
9db98d3
fix(matter): spell check ignore for CI
SuGlider Sep 18, 2024
fef5da3
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] Sep 18, 2024
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
1 change: 1 addition & 0 deletions idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ dependencies:
examples:
- path: ./idf_component_examples/hello_world
- path: ./idf_component_examples/hw_cdc_hello_world
- path: ./idf_component_examples/esp_matter_light
28 changes: 28 additions & 0 deletions idf_component_examples/esp_matter_light/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

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

# This should be done before using the IDF_TARGET variable.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project(arduino_managed_component_light)

# WARNING: This is just an example for using key for decrypting the encrypted OTA image
# Please do not use it as is.
if(CONFIG_ENABLE_ENCRYPTED_OTA)
target_add_binary_data(light.elf "esp_image_encryption_key.pem" TEXT)
endif()

if(CONFIG_IDF_TARGET_ESP32C2)
include(relinker)
endif()

idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H" 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)

88 changes: 88 additions & 0 deletions idf_component_examples/esp_matter_light/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
| Supported Targets | ESP32-S3 | ESP32-C3 | ESP32-C6 |
| ----------------- | -------- | -------- | -------- |


# Managed Component Light

This example is configured by default to work with the ESP32-S3, which has the RGB LED GPIO set as pin 48 and the BOOT button on GPIO 0.

This example creates a Color Temperature Light device using the esp_matter component downloaded from the [Espressif Component Registry](https://components.espressif.com/) instead of an extra component locally, so the example can work without setting up the esp-matter environment.

See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware.

The code is based on the Arduino API and uses Arduino as an IDF Component.

## How to use it

Once the device runs for the first time, it must be commissioned to the Matter Fabric of the available Matter Environment.
Possible Matter Environments are:
- Amazon Alexa
- Google Home Assistant
- Apple Home
- Open Source Home Assistant

There is no QR Code to be used when the Smartphone APP wants to add the Matter Device.
Please enter the code manually: `34970112332`

The devboard has a built-in LED that will be used as the Matter Light.
The default setting of the code uses pin 48 for the ESP32-S3.
Please change it in `main/matter_accessory_driver.h` or in the `sdkconfig.defaults.<SOC>` file.

## LED Status and Factory Mode

The WS2812b built-in LED will turn purple as soon as the device is flashed and runs for the first time.
The purple color indicates that the Matter Accessory has not been commissioned yet.
After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection.

Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment.
Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID.

The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset.

The Matter Smartphone APP will control the light state (ON/OFF), temperature (Warm/Cold White), and brightness.

## On Board Light toggle button

The built-in BOOT button will toggle On/Off and replicate the new state to the Matter Environment, making it visible in the Matter Smartphone APP as well.

## Returning to the Factory State

Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP.

## Building the Application using WiFi and Matter

Use ESP-IDF 5.1.4 from https://github.com/espressif/esp-idf/tree/release/v5.1
This example has been tested with Arduino Core 3.0.4

The project will download all necessary components, inluding the Arduino Core.
Run `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.<SOC>.idf" -p <PORT> flash monitor`

Example for ESP32-S3/Linux|MacOS:
`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32s3" -p /dev/ttyACM0 flash monitor`
Example for ESP32-C3/Windows:
`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor`

It may be necessary to delete some folders and files before running `idf.py`
Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock`
Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock`

There is a configuration file for these SoC: esp32s3, esp32c3, esp32c6.
Those are the tested devices that have a WS2812 RGB LED and can run BLE, WiFi and Matter.

In case it is necessary to change the Button Pin or the REG LED Pin, please use the `menuconfig`
`idf.py menuconfig` and change the Menu Option `Light Matter Accessory`

## Using OpenThread with Matter

This is possible with the ESP32-C6.
It is neessasy to have a Thread Border Routed in the Matter Environment. Check you matter hardware provider.
In order to build the application that will use Thread Networking instead of WiFi, please execute:

Example for ESP32-S3/Linux|MacOS:
`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor`
Example for ESP32-C3/Windows:
`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor`

It may be necessary to delete some folders and files before running `idf.py`
Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock`
Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock`
5 changes: 5 additions & 0 deletions idf_component_examples/esp_matter_light/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS ".")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
102 changes: 102 additions & 0 deletions idf_component_examples/esp_matter_light/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
menu "Light Matter Accessory"
menu "On Board Light ON/OFF Button"
config BUTTON_PIN
int
prompt "Button 1 GPIO"
default ENV_GPIO_BOOT_BUTTON
range -1 ENV_GPIO_IN_RANGE_MAX
help
The GPIO pin for button that will be used to turn on/off the Matter Light. It shall be connected to a push button. It can use the BOOT button of the development board.
endmenu


menu "LEDs"
config WS2812_PIN
int
prompt "WS2812 RGB LED GPIO"
default ENV_GPIO_RGB_LED
range -1 ENV_GPIO_OUT_RANGE_MAX
help
The GPIO pin for the Matter Light that will be driven by RMT. It shall be connected to one single WS2812 RGB LED.
endmenu

# TARGET CONFIGURATION
if IDF_TARGET_ESP32C3
config ENV_GPIO_RANGE_MIN
int
default 0

config ENV_GPIO_RANGE_MAX
int
default 19
# GPIOs 20/21 are always used by UART in examples

config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX

config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX

config ENV_GPIO_BOOT_BUTTON
int
default 9

config ENV_GPIO_RGB_LED
int
default 8
endif
if IDF_TARGET_ESP32C6
config ENV_GPIO_RANGE_MIN
int
default 0

config ENV_GPIO_RANGE_MAX
int
default 30
# GPIOs 16/17 are always used by UART in examples

config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX

config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX

config ENV_GPIO_BOOT_BUTTON
int
default 9

config ENV_GPIO_RGB_LED
int
default 8
endif
if IDF_TARGET_ESP32S3
config ENV_GPIO_RANGE_MIN
int
default 0

config ENV_GPIO_RANGE_MAX
int
default 48

config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX

config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX

config ENV_GPIO_BOOT_BUTTON
int
default 0

config ENV_GPIO_RGB_LED
int
default 48
endif

endmenu
Loading