Skip to content

Commit eec2af3

Browse files
P-R-O-C-H-Yme-no-devpre-commit-ci-lite[bot]
authored
feat(zigbee): Add range extender device endpoint (espressif#10970)
* feat(zigbee): Add range extender device endpoint * ci(pre-commit): Apply automatic fixes * fix(example): Fix typo catched by precommit --------- Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 5afafdf commit eec2af3

File tree

7 files changed

+224
-0
lines changed

7 files changed

+224
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
295295
libraries/Zigbee/src/ep/ZigbeeDoorWindowHandle.cpp
296296
libraries/Zigbee/src/ep/ZigbeeWindowCovering.cpp
297297
libraries/Zigbee/src/ep/ZigbeeVibrationSensor.cpp
298+
libraries/Zigbee/src/ep/ZigbeeRangeExtender.cpp
298299
)
299300

300301
set(ARDUINO_LIBRARY_BLE_SRCS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Arduino-ESP32 Zigbee Range Extender (Router) Example
2+
3+
This example shows how to configure the Zigbee Router device and use it as a Home Automation (HA) network range extender.
4+
5+
To see if the communication with your Zigbee network works, use the Serial monitor and watch for output there.
6+
7+
# Supported Targets
8+
9+
Currently, this example supports the following targets.
10+
11+
| Supported Targets | ESP32-C6 | ESP32-H2 |
12+
| ----------------- | -------- | -------- |
13+
14+
## Hardware Required
15+
16+
* A USB cable for power supply and programming
17+
* Board (ESP32-H2 or ESP32-C6) as Zigbee router device and upload the Zigbee_Range_Extender example
18+
* Zigbee network / coordinator (Other board with switch examples or Zigbee2mqtt or ZigbeeHomeAssistant like application)
19+
20+
### Configure the Project
21+
22+
#### Using Arduino IDE
23+
24+
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
25+
26+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
27+
* Select the Coordinator/Router device Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`
28+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs` (select correct size)
29+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
30+
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`.
31+
32+
## Troubleshooting
33+
34+
If the Router device flashed with this example is not connecting to the coordinator, erase the flash of the Router device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator.
35+
You can do the following:
36+
37+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
38+
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.
39+
40+
By default, the coordinator network is closed after rebooting or flashing new firmware.
41+
To open the network you have 2 options:
42+
43+
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
44+
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
45+
46+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
47+
48+
* **LED not blinking:** Check the wiring connection and the IO selection.
49+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
50+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
51+
52+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
53+
54+
## Contribute
55+
56+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
57+
58+
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!
59+
60+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
61+
62+
## Resources
63+
64+
* Official ESP32 Forum: [Link](https://esp32.com)
65+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
66+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
67+
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
68+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright 2025 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @brief This example demonstrates simple Zigbee Range Extender (router).
17+
*
18+
* The example demonstrates how to use Zigbee library to create a Zigbee network ragbe extender (router).
19+
*
20+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
21+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
22+
*
23+
* Please check the README.md for instructions and more detailed description.
24+
*
25+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
26+
*/
27+
28+
#ifndef ZIGBEE_MODE_ZCZR
29+
#error "Zigbee coordinator/router mode is not selected in Tools->Zigbee mode"
30+
#endif
31+
32+
#include "Zigbee.h"
33+
34+
/* Zigbee light bulb configuration */
35+
#define USE_CUSTOM_ZIGBEE_CONFIG 1
36+
#define ZIGBEE_EXTENDER_ENDPOINT 1
37+
uint8_t led = RGB_BUILTIN;
38+
uint8_t button = BOOT_PIN;
39+
40+
ZigbeeRangeExtender zbExtender = ZigbeeRangeExtender(ZIGBEE_EXTENDER_ENDPOINT);
41+
42+
/************************** Identify ******************************/
43+
// Create a task on identify call to handle the identify function
44+
void identify(uint16_t time) {
45+
static uint8_t blink = 1;
46+
log_d("Identify called for %d seconds", time);
47+
if (time == 0) {
48+
digitalWrite(led, LOW);
49+
return;
50+
}
51+
digitalWrite(led, blink);
52+
blink = !blink;
53+
}
54+
55+
/********************* Arduino functions **************************/
56+
void setup() {
57+
Serial.begin(115200);
58+
59+
// Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
60+
pinMode(led, OUTPUT);
61+
digitalWrite(led, LOW);
62+
63+
// Init button for factory reset
64+
pinMode(button, INPUT_PULLUP);
65+
66+
// Optional: Set callback function for device identify
67+
zbExtender.onIdentify(identify);
68+
69+
// Optional: Set Zigbee device name and model
70+
zbExtender.setManufacturerAndModel("Espressif", "ZigbeeRangeExtender");
71+
72+
// Add endpoint to Zigbee Core
73+
Serial.println("Adding Zigbee Extender endpoint to Zigbee Core");
74+
Zigbee.addEndpoint(&zbExtender);
75+
76+
#if USE_CUSTOM_ZIGBEE_CONFIG
77+
// Optional: Create a custom Zigbee configuration for Zigbee Extender
78+
esp_zb_cfg_t zigbeeConfig = ZIGBEE_DEFAULT_ROUTER_CONFIG();
79+
zigbeeConfig.nwk_cfg.zczr_cfg.max_children = 20; // 10 is default
80+
81+
// When all EPs are registered, start Zigbee with custom config
82+
if (!Zigbee.begin(&zigbeeConfig)) {
83+
#else
84+
// When all EPs are registered, start Zigbee as ROUTER device
85+
if (!Zigbee.begin(ZIGBEE_ROUTER)) {
86+
#endif
87+
Serial.println("Zigbee failed to start!");
88+
Serial.println("Rebooting...");
89+
ESP.restart();
90+
}
91+
Serial.println("Connecting to network");
92+
while (!Zigbee.connected()) {
93+
Serial.print(".");
94+
delay(100);
95+
}
96+
Serial.println();
97+
}
98+
99+
void loop() {
100+
// Checking button for factory reset
101+
if (digitalRead(button) == LOW) { // Push button pressed
102+
// Key debounce handling
103+
delay(100);
104+
int startTime = millis();
105+
while (digitalRead(button) == LOW) {
106+
delay(50);
107+
if ((millis() - startTime) > 3000) {
108+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
109+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
110+
delay(1000);
111+
Zigbee.factoryReset();
112+
}
113+
}
114+
}
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr",
3+
"requires": [
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
5+
]
6+
}

libraries/Zigbee/src/Zigbee.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
#include "ep/ZigbeeDoorWindowHandle.h"
2323
#include "ep/ZigbeeWindowCovering.h"
2424
#include "ep/ZigbeeVibrationSensor.h"
25+
#include "ep/ZigbeeRangeExtender.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "ZigbeeRangeExtender.h"
2+
#if SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED
3+
4+
ZigbeeRangeExtender::ZigbeeRangeExtender(uint8_t endpoint) : ZigbeeEP(endpoint) {
5+
_device_id = ESP_ZB_HA_RANGE_EXTENDER_DEVICE_ID;
6+
7+
_cluster_list = esp_zb_zcl_cluster_list_create();
8+
esp_zb_cluster_list_add_basic_cluster(_cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
9+
esp_zb_cluster_list_add_identify_cluster(_cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
10+
esp_zb_cluster_list_add_identify_cluster(_cluster_list, esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE);
11+
12+
_ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_RANGE_EXTENDER_DEVICE_ID, .app_device_version = 0};
13+
}
14+
15+
#endif //SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Class of Zigbee Range Extender endpoint inherited from common EP class */
2+
3+
#pragma once
4+
5+
#include "soc/soc_caps.h"
6+
#include "sdkconfig.h"
7+
#if SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED
8+
9+
#include "ZigbeeEP.h"
10+
#include "ha/esp_zigbee_ha_standard.h"
11+
12+
class ZigbeeRangeExtender : public ZigbeeEP {
13+
public:
14+
ZigbeeRangeExtender(uint8_t endpoint);
15+
~ZigbeeRangeExtender() {}
16+
};
17+
18+
#endif //SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED

0 commit comments

Comments
 (0)