Skip to content

Commit 704c5ee

Browse files
authored
Merge branch 'master' into release/v3.3.x
2 parents 30255d7 + 7575fa0 commit 704c5ee

File tree

37 files changed

+404
-41
lines changed

37 files changed

+404
-41
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
297297
libraries/Zigbee/src/ep/ZigbeeVibrationSensor.cpp
298298
libraries/Zigbee/src/ep/ZigbeeAnalog.cpp
299299
libraries/Zigbee/src/ep/ZigbeeRangeExtender.cpp
300+
libraries/Zigbee/src/ep/ZigbeeGateway.cpp
300301
)
301302

302303
set(ARDUINO_LIBRARY_BLE_SRCS

boards.txt

+12
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,9 @@ esp32s3.menu.PartitionScheme.esp_sr_16.build.partitions=esp_sr_16
11581158
esp32s3.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs
11591159
esp32s3.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr
11601160
esp32s3.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720
1161+
esp32s3.menu.PartitionScheme.zigbee_zczr_8MB=Zigbee ZCZR 8MB with spiffs
1162+
esp32s3.menu.PartitionScheme.zigbee_zczr_8MB.build.partitions=zigbee_zczr_8MB
1163+
esp32s3.menu.PartitionScheme.zigbee_zczr_8MB.upload.maximum_size=3407872
11611164
esp32s3.menu.PartitionScheme.custom=Custom
11621165
esp32s3.menu.PartitionScheme.custom.build.partitions=
11631166
esp32s3.menu.PartitionScheme.custom.upload.maximum_size=16777216
@@ -1319,6 +1322,9 @@ esp32c3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480
13191322
esp32c3.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs
13201323
esp32c3.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr
13211324
esp32c3.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720
1325+
esp32c3.menu.PartitionScheme.zigbee_zczr_8MB=Zigbee ZCZR 8MB with spiffs
1326+
esp32c3.menu.PartitionScheme.zigbee_zczr_8MB.build.partitions=zigbee_zczr_8MB
1327+
esp32c3.menu.PartitionScheme.zigbee_zczr_8MB.upload.maximum_size=3407872
13221328
esp32c3.menu.PartitionScheme.custom=Custom
13231329
esp32c3.menu.PartitionScheme.custom.build.partitions=
13241330
esp32c3.menu.PartitionScheme.custom.upload.maximum_size=16777216
@@ -1524,6 +1530,9 @@ esp32s2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480
15241530
esp32s2.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs
15251531
esp32s2.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr
15261532
esp32s2.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720
1533+
esp32s2.menu.PartitionScheme.zigbee_zczr_8MB=Zigbee ZCZR 8MB with spiffs
1534+
esp32s2.menu.PartitionScheme.zigbee_zczr_8MB.build.partitions=zigbee_zczr_8MB
1535+
esp32s2.menu.PartitionScheme.zigbee_zczr_8MB.upload.maximum_size=3407872
15271536
esp32s2.menu.PartitionScheme.custom=Custom
15281537
esp32s2.menu.PartitionScheme.custom.build.partitions=
15291538
esp32s2.menu.PartitionScheme.custom.upload.maximum_size=16777216
@@ -1704,6 +1713,9 @@ esp32.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480
17041713
esp32.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs
17051714
esp32.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr
17061715
esp32.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720
1716+
esp32.menu.PartitionScheme.zigbee_zczr_8MB=Zigbee ZCZR 8MB with spiffs
1717+
esp32.menu.PartitionScheme.zigbee_zczr_8MB.build.partitions=zigbee_zczr_8MB
1718+
esp32.menu.PartitionScheme.zigbee_zczr_8MB.upload.maximum_size=3407872
17071719
esp32.menu.PartitionScheme.custom=Custom
17081720
esp32.menu.PartitionScheme.custom.build.partitions=
17091721
esp32.menu.PartitionScheme.custom.upload.maximum_size=16777216

cores/esp32/HardwareSerial.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111
#include "driver/uart.h"
1212
#include "freertos/queue.h"
1313

14-
#ifndef ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE
15-
#define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048
16-
#endif
17-
18-
#ifndef ARDUINO_SERIAL_EVENT_TASK_PRIORITY
19-
#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES - 1)
20-
#endif
21-
22-
#ifndef ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE
23-
#define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1
24-
#endif
25-
2614
#if (SOC_UART_LP_NUM >= 1)
2715
#define UART_HW_FIFO_LEN(uart_num) ((uart_num < SOC_UART_HP_NUM) ? SOC_UART_FIFO_LEN : SOC_LP_UART_FIFO_LEN)
2816
#else

cores/esp32/HardwareSerial.h

+12
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,27 @@ typedef enum {
9797
} hardwareSerial_error_t;
9898

9999
#ifndef ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE
100+
#ifndef CONFIG_ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE
100101
#define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048
102+
#else
103+
#define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE CONFIG_ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE
104+
#endif
101105
#endif
102106

103107
#ifndef ARDUINO_SERIAL_EVENT_TASK_PRIORITY
108+
#ifndef CONFIG_ARDUINO_SERIAL_EVENT_TASK_PRIORITY
104109
#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES - 1)
110+
#else
111+
#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY CONFIG_ARDUINO_SERIAL_EVENT_TASK_PRIORITY
112+
#endif
105113
#endif
106114

107115
#ifndef ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE
116+
#ifndef CONFIG_ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE
108117
#define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1
118+
#else
119+
#define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE CONFIG_ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE
120+
#endif
109121
#endif
110122

111123
// UART0 pins are defined by default by the bootloader.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_ZB_ENABLED=y"
55
]
66
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Arduino-ESP32 Zigbee Gateway Example
2+
3+
This example shows how to configure Zigbee Gateway device, running on SoCs without native IEEE 802.15.4.
4+
5+
# Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 |
10+
| ----------------- | ----- | -------- | -------- | -------- |
11+
12+
## Hardware Required
13+
14+
* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee Radio Co-processor loaded with [ot_rcp example](https://github.com/espressif/esp-idf/tree/master/examples/openthread/ot_rcp).
15+
* A USB cable for power supply and programming.
16+
* Choose another board from supported targets as Zigbee coordinator/router and upload the Zigbee_Gateway example.
17+
18+
### Configure the Project
19+
20+
Set the RCP connection (UART) by changing the `GATEWAY_RCP_UART_PORT`, `GATEWAY_RCP_RX_PIN` and `GATEWAY_RCP_TX_PIN` definition.
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 Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`.
28+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`.
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+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
35+
36+
By default, the coordinator network is closed after rebooting or flashing new firmware.
37+
To open the network you have 2 options:
38+
39+
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
40+
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
41+
42+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
43+
44+
* **LED not blinking:** Check the wiring connection and the IO selection.
45+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
46+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
47+
48+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
49+
50+
## Contribute
51+
52+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
53+
54+
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!
55+
56+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
57+
58+
## Resources
59+
60+
* Official ESP32 Forum: [Link](https://esp32.com)
61+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
62+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
63+
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
64+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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 Gateway functionality.
17+
*
18+
* The example demonstrates how to use Zigbee library on ESP32s to create a Zigbee Gateway, updating the time from NTP server.
19+
* The Gateway is able to communicate with Zigbee end devices and send/receive data to/from them.
20+
* The Gateway is also able to communicate with the cloud or other devices over Wi-Fi / BLE.
21+
*
22+
* Proper Zigbee mode must be selected in Tools->Zigbee mode->Zigbee ZCZR (coordinator/router)
23+
* and also the correct partition scheme must be selected in Tools->Partition Scheme->Zigbee ZCZR
24+
*
25+
* Please check the README.md for instructions and more detailed description.
26+
*
27+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
28+
*/
29+
30+
#ifndef ZIGBEE_MODE_ZCZR
31+
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
32+
#endif
33+
34+
#include "Zigbee.h"
35+
#include <WiFi.h>
36+
#include "time.h"
37+
#include "esp_sntp.h"
38+
39+
/* Zigbee gateway configuration */
40+
#define GATEWAY_ENDPOINT_NUMBER 1
41+
#define GATEWAY_RCP_UART_PORT UART_NUM_1 // UART 0 is used for Serial communication
42+
#define GATEWAY_RCP_RX_PIN 4
43+
#define GATEWAY_RCP_TX_PIN 5
44+
45+
ZigbeeGateway zbGateway = ZigbeeGateway(GATEWAY_ENDPOINT_NUMBER);
46+
47+
/* Wi-Fi credentials */
48+
const char *ssid = "your-ssid";
49+
const char *password = "your-password";
50+
51+
/* NTP server configuration */
52+
const char *ntpServer1 = "pool.ntp.org";
53+
const char *ntpServer2 = "time.nist.gov";
54+
const long gmtOffset_sec = 3600;
55+
const int daylightOffset_sec = 3600;
56+
const char *time_zone = "CET-1CEST,M3.5.0,M10.5.0/3"; // TimeZone rule for Europe/Rome including daylight adjustment rules (optional)
57+
58+
/* Time structure */
59+
struct tm timeinfo;
60+
61+
/********************* Arduino functions **************************/
62+
void setup() {
63+
Serial.begin(115200);
64+
65+
// Initialize Wi-Fi and connect to AP
66+
WiFi.begin(ssid, password);
67+
esp_sntp_servermode_dhcp(1); // (optional)
68+
69+
Serial.print("Connecting to WiFi");
70+
71+
while (WiFi.status() != WL_CONNECTED) {
72+
delay(500);
73+
Serial.print(".");
74+
}
75+
Serial.println("WiFi connected");
76+
77+
// Initialize Zigbee and Begin Zigbee stack
78+
// Optional: set Zigbee device name and model
79+
zbGateway.setManufacturerAndModel("Espressif", "ZigbeeGateway");
80+
zbGateway.addTimeCluster(timeinfo, gmtOffset_sec);
81+
82+
// Add endpoint to Zigbee Core
83+
Serial.println("Adding Zigbee Gateway endpoint");
84+
Zigbee.addEndpoint(&zbGateway);
85+
86+
// Optional: Open network for 180 seconds after boot
87+
Zigbee.setRebootOpenNetwork(180);
88+
89+
// Set custom radio configuration for RCP communication
90+
esp_zb_radio_config_t radio_config = ZIGBEE_DEFAULT_UART_RCP_RADIO_CONFIG();
91+
radio_config.radio_uart_config.port = GATEWAY_RCP_UART_PORT;
92+
radio_config.radio_uart_config.rx_pin = (gpio_num_t)GATEWAY_RCP_RX_PIN;
93+
radio_config.radio_uart_config.tx_pin = (gpio_num_t)GATEWAY_RCP_TX_PIN;
94+
95+
Zigbee.setRadioConfig(radio_config);
96+
97+
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR or ZIGBEE_ROUTER mode
98+
if (!Zigbee.begin(ZIGBEE_COORDINATOR)) {
99+
Serial.println("Zigbee failed to start!");
100+
Serial.println("Rebooting...");
101+
ESP.restart();
102+
}
103+
104+
// set notification call-back function
105+
sntp_set_time_sync_notification_cb(timeavailable);
106+
sntp_set_sync_interval(30000); // sync every 30 seconds
107+
108+
// config time zone and NTP servers
109+
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);
110+
}
111+
112+
void loop() {
113+
// Nothing to do here in this example
114+
}
115+
116+
void printLocalTime() {
117+
if (!getLocalTime(&timeinfo)) {
118+
Serial.println("No time available (yet)");
119+
return;
120+
}
121+
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
122+
zbGateway.setTime(timeinfo);
123+
Serial.println("Time updated in Zigbee Gateway");
124+
}
125+
126+
// Callback function (gets called when time adjusts via NTP)
127+
void timeavailable(struct timeval *t) {
128+
Serial.println("Got time adjustment from NTP!");
129+
printLocalTime();
130+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"fqbn_append": "PartitionScheme=zigbee_zczr_8MB,ZigbeeMode=zczr",
3+
"requires": [
4+
"CONFIG_ZB_ENABLED=y"
5+
],
6+
"targets": {
7+
"esp32c6": false,
8+
"esp32h2": false
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_ZB_ENABLED=y"
55
]
66
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
33
"requires": [
4-
"CONFIG_SOC_IEEE802154_SUPPORTED=y"
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
56
]
67
}

0 commit comments

Comments
 (0)