Skip to content

Commit 565150b

Browse files
authored
Merge branch 'master' into feat/zigbee-electrical-meas
2 parents b50d3fb + 6c3528a commit 565150b

34 files changed

+2196
-236
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
302302
libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp
303303
libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp
304304
libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp
305+
libraries/Zigbee/src/ep/ZigbeeBinary.cpp
306+
libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp
305307
)
306308

307309
set(ARDUINO_LIBRARY_BLE_SRCS

boards.txt

Lines changed: 301 additions & 95 deletions
Large diffs are not rendered by default.

libraries/ESP_SR/src/esp32-hal-sr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static void audio_feed_task(void *arg) {
192192

193193
/* Feed samples of an audio stream to the AFE_SR */
194194
g_sr_data->afe_handle->feed(g_sr_data->afe_data, audio_buffer);
195+
vTaskDelay(2);
195196
}
196197
vTaskDelete(NULL);
197198
}

libraries/Zigbee/examples/Zigbee_Analog_Input_Output/Zigbee_Analog_Input_Output.ino

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ uint8_t analogPin = A0;
3939
uint8_t button = BOOT_PIN;
4040

4141
ZigbeeAnalog zbAnalogDevice = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER);
42+
ZigbeeAnalog zbAnalogTemp = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER + 1);
43+
ZigbeeAnalog zbAnalogFan = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER + 2);
44+
ZigbeeAnalog zbAnalogPercent = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER + 3);
4245

4346
void onAnalogOutputChange(float analog_output) {
4447
Serial.printf("Received analog output change: %.1f\r\n", analog_output);
@@ -57,15 +60,43 @@ void setup() {
5760
// Optional: set Zigbee device name and model
5861
zbAnalogDevice.setManufacturerAndModel("Espressif", "ZigbeeAnalogDevice");
5962

60-
// Add analog clusters to Zigbee Analog according your needs
63+
// Set up analog input
6164
zbAnalogDevice.addAnalogInput();
65+
zbAnalogDevice.setAnalogInputApplication(ESP_ZB_ZCL_AI_POWER_IN_WATTS_CONSUMPTION);
66+
zbAnalogDevice.setAnalogInputDescription("Power Consumption (Watts)");
67+
zbAnalogDevice.setAnalogInputResolution(0.01);
68+
69+
// Set up analog output
6270
zbAnalogDevice.addAnalogOutput();
71+
zbAnalogDevice.setAnalogOutputApplication(ESP_ZB_ZCL_AI_RPM_OTHER);
72+
zbAnalogDevice.setAnalogOutputDescription("Fan Speed (RPM)");
6373

6474
// If analog output cluster is added, set callback function for analog output change
6575
zbAnalogDevice.onAnalogOutputChange(onAnalogOutputChange);
6676

77+
// Set up analog input
78+
zbAnalogTemp.addAnalogInput();
79+
zbAnalogTemp.setAnalogInputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER);
80+
zbAnalogTemp.setAnalogInputDescription("Temperature");
81+
zbAnalogTemp.setAnalogInputResolution(0.1);
82+
83+
// Set up analog input
84+
zbAnalogFan.addAnalogInput();
85+
zbAnalogFan.setAnalogInputApplication(ESP_ZB_ZCL_AI_RPM_OTHER);
86+
zbAnalogFan.setAnalogInputDescription("RPM");
87+
zbAnalogFan.setAnalogInputResolution(1);
88+
89+
// Set up analog input
90+
zbAnalogPercent.addAnalogInput();
91+
zbAnalogPercent.setAnalogInputApplication(ESP_ZB_ZCL_AI_PERCENTAGE_OTHER);
92+
zbAnalogPercent.setAnalogInputDescription("Percentage");
93+
zbAnalogPercent.setAnalogInputResolution(0.01);
94+
6795
// Add endpoints to Zigbee Core
6896
Zigbee.addEndpoint(&zbAnalogDevice);
97+
Zigbee.addEndpoint(&zbAnalogTemp);
98+
Zigbee.addEndpoint(&zbAnalogFan);
99+
Zigbee.addEndpoint(&zbAnalogPercent);
69100

70101
Serial.println("Starting Zigbee...");
71102
// When all EPs are registered, start Zigbee in End Device mode
@@ -95,9 +126,15 @@ void loop() {
95126
float analog = (float)analogRead(analogPin);
96127
Serial.printf("Updating analog input to %.1f\r\n", analog);
97128
zbAnalogDevice.setAnalogInput(analog);
129+
zbAnalogTemp.setAnalogInput(analog / 100);
130+
zbAnalogFan.setAnalogInput(analog);
131+
zbAnalogPercent.setAnalogInput(analog / 10);
98132

99133
// Analog input supports reporting
100134
zbAnalogDevice.reportAnalogInput();
135+
zbAnalogTemp.reportAnalogInput();
136+
zbAnalogFan.reportAnalogInput();
137+
zbAnalogPercent.reportAnalogInput();
101138
}
102139

103140
// Checking button for factory reset and reporting
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Arduino-ESP32 Zigbee Binary Input Example
2+
3+
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) binary input device with two different applications: HVAC fan status and security zone armed status.
4+
5+
# Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets | ESP32-C6 | ESP32-H2 |
10+
| ----------------- | -------- | -------- |
11+
12+
## Binary Input Functions
13+
14+
* The example implements two binary inputs:
15+
- HVAC Fan Status: Reports the current state of a fan
16+
- Security Zone Armed: Reports the armed state of a security zone
17+
* By clicking the button (BOOT) on this board, it will toggle both binary inputs and immediately send a report of their states to the network.
18+
* Holding the button for more than 3 seconds will trigger a factory reset of the Zigbee device.
19+
20+
## Hardware Required
21+
22+
* A USB cable for power supply and programming
23+
24+
### Configure the Project
25+
26+
The example uses the following default pins:
27+
* Button: `BOOT_PIN` (BOOT button on ESP32-C6 and ESP32-H2)
28+
29+
#### Using Arduino IDE
30+
31+
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
32+
33+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
34+
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
35+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
36+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
37+
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`.
38+
39+
## Troubleshooting
40+
41+
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.
42+
You can do the following:
43+
44+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
45+
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.
46+
47+
By default, the coordinator network is closed after rebooting or flashing new firmware.
48+
To open the network you have 2 options:
49+
50+
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
51+
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
52+
53+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
54+
55+
* **LED not blinking:** Check the wiring connection and the IO selection.
56+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
57+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
58+
59+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
60+
61+
## Contribute
62+
63+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
64+
65+
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!
66+
67+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
68+
69+
## Resources
70+
71+
* Official ESP32 Forum: [Link](https://esp32.com)
72+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
73+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
74+
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
75+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 Zigbee binary input device.
17+
*
18+
* The example demonstrates how to use Zigbee library to create an end device binary sensor device.
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_ED
29+
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
30+
#endif
31+
32+
#include "Zigbee.h"
33+
34+
/* Zigbee binary sensor device configuration */
35+
#define BINARY_DEVICE_ENDPOINT_NUMBER 1
36+
37+
uint8_t binaryPin = A0;
38+
uint8_t button = BOOT_PIN;
39+
40+
ZigbeeBinary zbBinaryFan = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER);
41+
ZigbeeBinary zbBinaryZone = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER + 1);
42+
43+
bool binaryStatus = false;
44+
45+
void setup() {
46+
Serial.begin(115200);
47+
Serial.println("Starting...");
48+
49+
// Init button switch
50+
pinMode(button, INPUT_PULLUP);
51+
52+
// Set analog resolution to 10 bits
53+
analogReadResolution(10);
54+
55+
// Optional: set Zigbee device name and model
56+
zbBinaryFan.setManufacturerAndModel("Espressif", "ZigbeeBinarySensor");
57+
58+
// Set up binary fan status input (HVAC)
59+
zbBinaryFan.addBinaryInput();
60+
zbBinaryFan.setBinaryInputApplication(BINARY_INPUT_APPLICATION_TYPE_HVAC_FAN_STATUS);
61+
zbBinaryFan.setBinaryInputDescription("Fan Status");
62+
63+
// Set up binary zone armed input (Security)
64+
zbBinaryZone.addBinaryInput();
65+
zbBinaryZone.setBinaryInputApplication(BINARY_INPUT_APPLICATION_TYPE_SECURITY_ZONE_ARMED);
66+
zbBinaryZone.setBinaryInputDescription("Zone Armed");
67+
68+
// Add endpoints to Zigbee Core
69+
Zigbee.addEndpoint(&zbBinaryFan);
70+
Zigbee.addEndpoint(&zbBinaryZone);
71+
72+
Serial.println("Starting Zigbee...");
73+
// When all EPs are registered, start Zigbee in End Device mode
74+
if (!Zigbee.begin()) {
75+
Serial.println("Zigbee failed to start!");
76+
Serial.println("Rebooting...");
77+
ESP.restart();
78+
} else {
79+
Serial.println("Zigbee started successfully!");
80+
}
81+
Serial.println("Connecting to network");
82+
while (!Zigbee.connected()) {
83+
Serial.print(".");
84+
delay(100);
85+
}
86+
Serial.println("Connected");
87+
}
88+
89+
void loop() {
90+
// Checking button for factory reset and reporting
91+
if (digitalRead(button) == LOW) { // Push button pressed
92+
// Key debounce handling
93+
delay(100);
94+
int startTime = millis();
95+
while (digitalRead(button) == LOW) {
96+
delay(50);
97+
if ((millis() - startTime) > 3000) {
98+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
99+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
100+
delay(1000);
101+
Zigbee.factoryReset();
102+
}
103+
}
104+
// Toggle binary input
105+
binaryStatus = !binaryStatus;
106+
zbBinaryFan.setBinaryInput(binaryStatus);
107+
zbBinaryZone.setBinaryInput(binaryStatus);
108+
zbBinaryFan.reportBinaryInput();
109+
zbBinaryZone.reportBinaryInput();
110+
}
111+
delay(100);
112+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
3+
"requires": [
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
6+
]
7+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Arduino-ESP32 Zigbee Multi-Switch Example
2+
3+
This example demonstrates how to configure a Zigbee device as a multi-switch controller that can control up to three different Zigbee lights independently. The switch can operate in either coordinator or router mode, making it compatible with Home Assistant integration.
4+
5+
# Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets | ESP32-C6 | ESP32-H2 |
10+
| ----------------- | -------- | -------- |
11+
12+
## Hardware Required
13+
14+
* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee multi-switch controller
15+
* One or more Zigbee light devices (loaded with Zigbee_On_Off_Light example)
16+
* A USB cable for power supply and programming
17+
18+
### Configure the Project
19+
20+
The example uses the BOOT button (pin 9) on ESP32-C6 and ESP32-H2 as the physical switch input. The switch can be configured to operate in two modes:
21+
22+
1. **Coordinator Mode**: For running your own Zigbee network
23+
2. **Router Mode**: For Home Assistant integration
24+
25+
#### Using Arduino IDE
26+
27+
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
28+
29+
* Before Compile/Verify, select the correct board: `Tools -> Board`
30+
* Select the Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`
31+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
32+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port
33+
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`
34+
35+
## Features
36+
37+
The multi-switch example provides the following functionality:
38+
39+
1. **Light Configuration**
40+
- Configure up to 3 different lights using their endpoint and IEEE address
41+
- Configuration is stored in NVS (Non-Volatile Storage) and persists after power loss
42+
- Remove configured lights when needed
43+
44+
2. **Control Commands**
45+
- Control all bound lights simultaneously:
46+
- Turn all bound lights ON
47+
- Turn all bound lights OFF
48+
- Toggle all bound lights
49+
- Control individual lights (1-3):
50+
- Turn light ON
51+
- Turn light OFF
52+
- Toggle light
53+
54+
3. **Network Management**
55+
- Factory reset capability
56+
- Open network for device joining
57+
- View bound devices and current light configurations
58+
59+
## Serial Commands
60+
61+
The example accepts the following commands through the serial interface:
62+
63+
* `config` - Configure a new light (requires light number, endpoint, and IEEE address)
64+
* `remove` - Remove a configured light
65+
* `on` - Turn all bound lights ON
66+
* `off` - Turn all bound lights OFF
67+
* `toggle` - Toggle all bound lights
68+
* `1on`, `2on`, `3on` - Turn individual light ON
69+
* `1off`, `2off`, `3off` - Turn individual light OFF
70+
* `1toggle`, `2toggle`, `3toggle` - Toggle individual light
71+
* `freset` - Perform factory reset
72+
* `open_network` - Open network for device joining (only for coordinator role)
73+
74+
## Troubleshooting
75+
76+
If the End device flashed with the example `Zigbee_On_Off_Light` 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.
77+
You can do the following:
78+
79+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`
80+
* In the `Zigbee_On_Off_Light` example sketch call `Zigbee.factoryReset()`
81+
82+
By default, the coordinator network is closed after rebooting or flashing new firmware.
83+
To open the network you have 2 options:
84+
85+
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time)` before calling `Zigbee.begin()`
86+
* In application you can anytime call `Zigbee.openNetwork(time)` to open the network for devices to join
87+
88+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
89+
90+
* **LED not blinking:** Check the wiring connection and the IO selection
91+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed
92+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation
93+
94+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
95+
96+
## Contribute
97+
98+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
99+
100+
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!
101+
102+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
103+
104+
## Resources
105+
106+
* Official ESP32 Forum: [Link](https://esp32.com)
107+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
108+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
109+
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
110+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)

0 commit comments

Comments
 (0)