-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[esp32] Add lighting example (#13174)
* [esp32] Add lighting example * [esp32] Enable light example compilation in CI
- Loading branch information
Showing
22 changed files
with
1,143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/build/ | ||
/sdkconfig | ||
/sdkconfig.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# | ||
# Copyright (c) 2021 Project CHIP Authors | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# 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) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake) | ||
|
||
set(EXTRA_COMPONENT_DIRS | ||
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components" | ||
"${CMAKE_CURRENT_LIST_DIR}/../../common/QRCode" | ||
"${IDF_PATH}/examples/common_components" | ||
) | ||
|
||
project(chip-lighting-app) | ||
|
||
# C++17 is required for RPC build. | ||
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) | ||
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) | ||
|
||
flashing_script() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Matter ESP32 Lighting Example | ||
|
||
This example demonstrates the Matter Lighting application on ESP platforms. | ||
|
||
--- | ||
|
||
- [Matter ESP32 Lighting Example](#matter-esp32-lighting-example) | ||
- [Supported Devices](#supported-devices) | ||
- [Building the Example Application](#building-the-example-application) | ||
- [Commissioning over BLE using chip-tool](#commissioning-over-ble-using-chip-tool) | ||
- [Cluster Control](#cluster-control) | ||
|
||
--- | ||
|
||
## Supported Devices | ||
|
||
The demo application is intended to work on following categories of ESP32 | ||
devices: | ||
|
||
- [ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview) | ||
- [ESP32-WROVER-KIT_V4.1](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview) | ||
- [ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html). | ||
- [ESP32S3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitm-1.html). | ||
|
||
## Building the Example Application | ||
|
||
Building the example application requires the use of the Espressif IoT | ||
Development Framework ([ESP-IDF](https://github.com/espressif/esp-idf)). | ||
|
||
The VSCode devcontainer has these components pre-installed, so you can skip this | ||
step. To install these components manually, follow these steps: | ||
|
||
- Clone the Espressif ESP-IDF and checkout | ||
[v4.4-beta1 pre-release](https://github.com/espressif/esp-idf/releases/tag/v4.4-beta1) | ||
|
||
$ mkdir ${HOME}/tools | ||
$ cd ${HOME}/tools | ||
$ git clone https://github.com/espressif/esp-idf.git | ||
$ cd esp-idf | ||
$ git checkout v4.4-beta1 | ||
$ git submodule update --init | ||
$ ./install.sh | ||
|
||
- Install ninja-build | ||
|
||
$ sudo apt-get install ninja-build | ||
|
||
Currently building in VSCode _and_ deploying from native is not supported, so | ||
make sure the IDF_PATH has been exported(See the manual setup steps above). | ||
|
||
- Setting up the environment | ||
|
||
$ cd ${HOME}/tools/esp-idf | ||
$ ./install.sh | ||
$ . ./export.sh | ||
$ cd {path-to-connectedhomeip} | ||
|
||
To download and install packages. | ||
|
||
$ source ./scripts/bootstrap.sh | ||
$ source ./scripts/activate.sh | ||
|
||
If packages are already installed then simply activate them. | ||
|
||
$ source ./scripts/activate.sh | ||
|
||
- Target Set | ||
|
||
$ idf.py set-target esp32 | ||
or | ||
$ idf.py set-target esp32c3 | ||
or | ||
$ idf.py set-target esp32s3 | ||
|
||
- To build the demo application. | ||
|
||
$ idf.py build | ||
|
||
- After building the application, to flash it outside of VSCode, connect your | ||
device via USB. Then run the following command to flash the demo application | ||
onto the device and then monitor its output. If necessary, replace | ||
`/dev/tty.SLAB_USBtoUART`(MacOS) with the correct USB device name for your | ||
system(like `/dev/ttyUSB0` on Linux). Note that sometimes you might have to | ||
press and hold the `boot` button on the device while it's trying to connect | ||
before flashing. | ||
|
||
$ idf.py -p /dev/tty.SLAB_USBtoUART flash monitor | ||
|
||
Note: Some users might have to install the | ||
[VCP driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) | ||
before the device shows up on `/dev/tty`. | ||
|
||
- Quit the monitor by hitting `Ctrl+]`. | ||
|
||
Note: You can see a menu of various monitor commands by hitting | ||
`Ctrl+t Ctrl+h` while the monitor is running. | ||
|
||
- If desired, the monitor can be run again like so: | ||
|
||
$ idf.py -p /dev/tty.SLAB_USBtoUART monitor | ||
|
||
## Commissioning over BLE using chip-tool | ||
|
||
- Please build the standalone chip-tool as described [here](../../chip-tool) | ||
- Commissioning the Lighting device | ||
|
||
$ ./out/debug/chip-tool pairing ble-wifi 12345 <ssid> <passphrase> 20202021 3840 | ||
|
||
## Cluster Control | ||
|
||
- After successful commissioning, use the OnOff cluster command to control the | ||
OnOff attribute. This allows you to toggle a parameter implemented by the | ||
device to be On or Off. | ||
|
||
$ ./out/debug/chip-tool onoff on 12345 1 | ||
|
||
- On | ||
[ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html) | ||
or | ||
[ESP32S3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitm-1.html) | ||
board, there is an on-board RGB-LED. Use ColorControl cluster command to | ||
control the color attributes: | ||
|
||
$ ./out/debug/chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 12345 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* This file implements the CHIP Device Interface that is used by | ||
* applications to interact with the CHIP stack | ||
* | ||
*/ | ||
|
||
#include <stdlib.h> | ||
|
||
#include "CHIPDeviceManager.h" | ||
#include <app/ConcreteAttributePath.h> | ||
#include <app/util/basic-types.h> | ||
#include <lib/support/CHIPMem.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/ErrorStr.h> | ||
#include <setup_payload/SetupPayload.h> | ||
|
||
using namespace ::chip; | ||
|
||
namespace chip { | ||
|
||
namespace DeviceManager { | ||
|
||
using namespace ::chip::DeviceLayer; | ||
|
||
void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) | ||
{ | ||
CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg); | ||
if (cb != nullptr) | ||
{ | ||
cb->DeviceEventCallback(event, reinterpret_cast<intptr_t>(cb)); | ||
} | ||
} | ||
|
||
CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) | ||
{ | ||
CHIP_ERROR err; | ||
mCB = cb; | ||
RendezvousInformationFlags flags = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE); | ||
|
||
// Initialize the CHIP stack. | ||
err = PlatformMgr().InitChipStack(); | ||
SuccessOrExit(err); | ||
|
||
if (flags.Has(RendezvousInformationFlag::kBLE)) | ||
{ | ||
ConnectivityMgr().SetBLEAdvertisingEnabled(true); | ||
} | ||
else if (flags.Has(RendezvousInformationFlag::kSoftAP)) | ||
{ | ||
// TODO(cecille): Fix for the case where BLE and SoftAP are both enabled.` | ||
ConnectivityMgr().SetBLEAdvertisingEnabled(false); | ||
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled); | ||
} | ||
else | ||
{ | ||
// If rendezvous is bypassed, enable SoftAP so that the device can still | ||
// be communicated with via its SoftAP as needed. | ||
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled); | ||
} | ||
|
||
err = Platform::MemoryInit(); | ||
SuccessOrExit(err); | ||
|
||
// Register a function to receive events from the CHIP device layer. Note that calls to | ||
// this function will happen on the CHIP event loop thread, not the app_main thread. | ||
PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb)); | ||
|
||
// Start a task to run the CHIP Device event loop. | ||
err = PlatformMgr().StartEventLoopTask(); | ||
SuccessOrExit(err); | ||
|
||
exit: | ||
return err; | ||
} | ||
} // namespace DeviceManager | ||
} // namespace chip | ||
|
||
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type, | ||
uint16_t size, uint8_t * value) | ||
{ | ||
chip::DeviceManager::CHIPDeviceManagerCallbacks * cb = | ||
chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks(); | ||
if (cb != nullptr) | ||
{ | ||
cb->PostAttributeChangeCallback(attributePath.mEndpointId, attributePath.mClusterId, attributePath.mAttributeId, mask, type, | ||
size, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# | ||
# Copyright (c) 2021 Project CHIP Authors | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) | ||
|
||
idf_component_register(PRIV_INCLUDE_DIRS | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format" | ||
"${CMAKE_CURRENT_LIST_DIR}/include" | ||
SRC_DIRS | ||
"${CMAKE_CURRENT_LIST_DIR}" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app/zap-generated" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/administrator-commissioning-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/basic" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/bindings" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/descriptor" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/diagnostic-logs-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/color-control-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ethernet-network-diagnostics-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/fixed-label-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-commissioning-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-diagnostics-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/identify-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/level-control" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning-old" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/occupancy-sensor-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/on-off-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/software-diagnostics-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/switch-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thread-network-diagnostics-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/user-label-server" | ||
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wifi-network-diagnostics-server" | ||
PRIV_REQUIRES chip QRCode bt led_strip) | ||
|
||
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) | ||
target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H") |
Oops, something went wrong.