feat(Zigbee): Add Zigbee Dimmable light example
Add example for a dimmable light. Based on a copy of color dimmable light example.
This commit is contained in:
parent
a44e45795c
commit
aa0c3da729
3 changed files with 184 additions and 0 deletions
68
libraries/Zigbee/examples/Zigbee_Dimmable_Light/README.md
Normal file
68
libraries/Zigbee/examples/Zigbee_Dimmable_Light/README.md
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# Arduino-ESP32 Zigbee Dimmable Light Example
|
||||
|
||||
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) dimmable light.
|
||||
|
||||
# Supported Targets
|
||||
|
||||
Currently, this example supports the following targets.
|
||||
|
||||
| Supported Targets | ESP32-C6 | ESP32-H2 |
|
||||
| ----------------- | -------- | -------- |
|
||||
|
||||
## Hardware Required
|
||||
|
||||
* A USB cable for power supply and programming
|
||||
* Board (ESP32-H2 or ESP32-C6) as Zigbee end device and upload the Zigbee_Dimmable_Light example
|
||||
* Zigbee network / coordinator (Other board with switch examples or Zigbee2mqtt or ZigbeeHomeAssistant like application)
|
||||
|
||||
### Configure the Project
|
||||
|
||||
Set the LED GPIO by changing the `LED_PIN` definition. By default, the LED_PIN is `RGB_BUILTIN`.
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
|
||||
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the End device flashed with this example is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator.
|
||||
You can do the following:
|
||||
|
||||
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
|
||||
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.
|
||||
|
||||
By default, the coordinator network is closed after rebooting or flashing new firmware.
|
||||
To open the network you have 2 options:
|
||||
|
||||
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
|
||||
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
|
||||
|
||||
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
|
||||
|
||||
* **LED not blinking:** Check the wiring connection and the IO selection.
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
|
||||
|
||||
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Official ESP32 Forum: [Link](https://esp32.com)
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
|
||||
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @brief This example demonstrates Zigbee Dimmable light bulb.
|
||||
*
|
||||
* The example demonstrates how to use Zigbee library to create an end device with
|
||||
* dimmable light end point.
|
||||
* The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator.
|
||||
*
|
||||
* Proper Zigbee mode must be selected in Tools->Zigbee mode
|
||||
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
|
||||
*
|
||||
* Please check the README.md for instructions and more detailed description.
|
||||
*
|
||||
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
|
||||
*/
|
||||
|
||||
#ifndef ZIGBEE_MODE_ED
|
||||
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
|
||||
#endif
|
||||
|
||||
#include "Zigbee.h"
|
||||
|
||||
#define LED_PIN RGB_BUILTIN
|
||||
#define BUTTON_PIN 9 // C6/H2 Boot button
|
||||
#define ZIGBEE_LIGHT_ENDPOINT 10
|
||||
|
||||
ZigbeeDimmableLight zbDimmableLight = ZigbeeDimmableLight(ZIGBEE_LIGHT_ENDPOINT);
|
||||
|
||||
/********************* LED functions **************************/
|
||||
void setLight(bool state, uint8_t level)
|
||||
{
|
||||
rgbLedWrite(LED_PIN, level, level, level);
|
||||
}
|
||||
|
||||
// Create a task on identify call to handle the identify function
|
||||
void identify(uint16_t time)
|
||||
{
|
||||
static uint8_t blink = 1;
|
||||
log_d("Identify called for %d seconds", time);
|
||||
if (time == 0)
|
||||
{
|
||||
// If identify time is 0, stop blinking and restore light as it was used for identify
|
||||
zbDimmableLight.restoreLight();
|
||||
return;
|
||||
}
|
||||
rgbLedWrite(LED_PIN, 255 * blink, 255 * blink, 255 * blink);
|
||||
blink = !blink;
|
||||
}
|
||||
|
||||
/********************* Arduino functions **************************/
|
||||
void setup()
|
||||
{
|
||||
// Init RMT and leave light OFF
|
||||
rgbLedWrite(LED_PIN, 0, 0, 0);
|
||||
|
||||
// Init button for factory reset
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
|
||||
// Set callback function for light change
|
||||
zbDimmableLight.onLightChange(setLight);
|
||||
|
||||
// Optional: Set callback function for device identify
|
||||
zbDimmableLight.onIdentify(identify);
|
||||
|
||||
// Optional: Set Zigbee device name and model
|
||||
zbDimmableLight.setManufacturerAndModel("Espressif", "ZBLightBulb");
|
||||
|
||||
// Add endpoint to Zigbee Core
|
||||
log_d("Adding ZigbeeLight endpoint to Zigbee Core");
|
||||
Zigbee.addEndpoint(&zbDimmableLight);
|
||||
|
||||
// When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
|
||||
log_d("Calling Zigbee.begin()");
|
||||
Zigbee.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Checking button for factory reset
|
||||
if (digitalRead(BUTTON_PIN) == LOW)
|
||||
{ // Push button pressed
|
||||
// Key debounce handling
|
||||
delay(100);
|
||||
int startTime = millis();
|
||||
while (digitalRead(BUTTON_PIN) == LOW)
|
||||
{
|
||||
delay(50);
|
||||
if ((millis() - startTime) > 3000)
|
||||
{
|
||||
// If key pressed for more than 3secs, factory reset Zigbee and reboot
|
||||
Serial.printf("Resetting Zigbee to factory settings, reboot.\n");
|
||||
Zigbee.factoryReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
6
libraries/Zigbee/examples/Zigbee_Dimmable_Light/ci.json
Normal file
6
libraries/Zigbee/examples/Zigbee_Dimmable_Light/ci.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
|
||||
"requires": [
|
||||
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in a new issue