arduino-esp32/idf_component_examples/esp_matter_light
Rodrigo Garcia 8d772d5e89
ESP Matter + Arduino as IDF Component Light example (#10290)
* feat(matter): partition file for matter

The declaration includes a partition for keys and SSL certificates.

* feat(matter): matter light source code

Adds necessary Matter + Arduino source code that will create a Matter compatible Light.

* feat(matter): adds sdkconfig  and CMake files

Adds target sdkconfig files and the CMakeLists.txt in orde to build the application using Arduino+Matter as IDF component

* fix(matter): wrong folder name

* feat(matter): include example into registry

* fix(matter): error with type in wrong place

A declaration was incorrect due to a typo error. Sintax was corrected by deleting `BuiltInLED`.

* feat(matter): add readme documentation

* feat(matter): remove soc with no wifi or no ble

* feat(matter): adjust all sdkconfig files

* feat(matter): improve code and led status

* feat(matter): add button and led gpio with kconfig

* fix(matter): remove commented lines

* fix(matter): remove commented lines

* feat(matter): added a 2.4GHz SSID note 

Both the ESP32 device and the Smartphone running the Matter APP shall be in the same WiFi Network in order to achieve a successful commissioning process.

* feat(matter): arduino managed comonent version

Preparing the Arduino Managed Component to use Core version 3.0.5 or higher.

* feat(matter): adds information about google

Goggle Home Assistant requires special configurtation in order to allow the Light to show up in the GHA APP.

* feat(matter): arduino component version

Set final Arduino Managed Component to 3.0.5 necessary because of -DESP32=ESP32, in order to compile the project.

* ci(pre-commit): Apply automatic fixes

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(typo): typo and commentaries

* fix(matter): spell check ignore for CI

* ci(pre-commit): Apply automatic fixes

* fix(matter): spell check ignore for CI

* fix(matter): spell check ignore for CI

* fix(matter): spell check ignore for CI

* ci(pre-commit): Apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2024-09-18 14:51:46 +03:00
..
main ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
CMakeLists.txt ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
partitions.csv ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
README.md ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
sdkconfig.defaults.c6_thread ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
sdkconfig.defaults.esp32c3 ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
sdkconfig.defaults.esp32c6 ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00
sdkconfig.defaults.esp32s3 ESP Matter + Arduino as IDF Component Light example (#10290) 2024-09-18 14:51:46 +03:00

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 instead of an extra component locally, so the example can work without setting up the esp-matter environment.

See the docs 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

(*) Google Home Assistant requires the user to set up a Matter Light using the Google Home Developer Console. It is necessary to create a Matter Light device with VID = 0xFFF1 and PID = 0x8000. Otherwise, the Light won't show up in the GHA APP. This action is necessary because the Firmware uses Testing credentials and Google requires the user to create the testing device before using it.

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 Wi-Fi connection.

Once it connects to the Wi-Fi 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 Wi-Fi using an ESP32 device will connect to a 2.4 GHz Wi-Fi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID.

The Matter and Wi-Fi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and Wi-Fi 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 Wi-Fi 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 Wi-Fi 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, including 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, Wi-Fi 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 Wi-Fi, 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