Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2c7578

Browse files
feat(zigbee): Add Fan Control endpoint support (#11559)
* feat(zigbee): Add Fan Control endpoint support* fix(zigbee): Update logs and change device_id* ci(pre-commit): Apply automatic fixes---------Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parentb709a78 commite2c7578

File tree

8 files changed

+393
-12
lines changed

8 files changed

+393
-12
lines changed

‎CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
305305
libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp
306306
libraries/Zigbee/src/ep/ZigbeeBinary.cpp
307307
libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp
308+
libraries/Zigbee/src/ep/ZigbeeFanControl.cpp
308309
)
309310

310311
set(ARDUINO_LIBRARY_BLE_SRCS
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#Arduino-ESP32 Zigbee Fan Control Example
2+
3+
This example demonstrates how to use the Zigbee library to create a router device fan control and use it as a Home Automation (HA) fan control device.
4+
5+
#Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets| ESP32-C6| ESP32-H2|
10+
| -----------------| --------| --------|
11+
12+
##Fan Control Functions
13+
14+
1. Initialize a Zigbee fan control device.
15+
2. Control fan modes (OFF, LOW, MEDIUM, HIGH, ON).
16+
3. Respond to fan control commands from the Zigbee network.
17+
18+
##Hardware Required
19+
20+
* ESP32-H2 or ESP32-C6 development board
21+
* A USB cable for power supply and programming
22+
* RGB LED for visual feedback (built-in on most development boards)
23+
24+
###Configure the Project
25+
26+
In this example the RGB LED is used to indicate the current fan control mode.
27+
The LED colors represent different fan modes:
28+
- OFF: No light
29+
- LOW: Blue
30+
- MEDIUM: Yellow
31+
- HIGH: Red
32+
- ON: White
33+
34+
Set the button GPIO by changing the`button` variable. By default, it's the pin`BOOT_PIN` (BOOT button on ESP32-C6 and ESP32-H2).
35+
36+
####Using Arduino IDE
37+
38+
To get more information about the Espressif boards see[Espressif Development Kits](https://www.espressif.com/en/products/devkits).
39+
40+
* Before Compile/Verify, select the correct board:`Tools -> Board`.
41+
* Select the End device Zigbee mode:`Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`
42+
* Select Partition Scheme for Zigbee:`Tools -> Partition Scheme: Zigbee ZCZR 4MB with spiffs`
43+
* Select the COM port:`Tools -> Port: xxx` where the`xxx` is the detected COM port.
44+
* Optional: Set debug level to verbose to see all logs from Zigbee stack:`Tools -> Core Debug Level: Verbose`.
45+
46+
##Troubleshooting
47+
48+
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.
49+
You can do the following:
50+
51+
* In the Arduino IDE go to the Tools menu and set`Erase All Flash Before Sketch Upload` to`Enabled`.
52+
* Add to the sketch`Zigbee.factoryReset();` to reset the device and Zigbee stack.
53+
54+
By default, the coordinator network is closed after rebooting or flashing new firmware.
55+
To open the network you have 2 options:
56+
57+
* Open network after reboot by setting`Zigbee.setRebootOpenNetwork(time);` before calling`Zigbee.begin();`.
58+
* In application you can anytime call`Zigbee.openNetwork(time);` to open the network for devices to join.
59+
60+
61+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
62+
63+
***LED not blinking:** Check the wiring connection and the IO selection.
64+
***Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
65+
***COM port not detected:** Check the USB cable and the USB to Serial driver installation.
66+
67+
If the error persists, you can ask for help at the official[ESP32 forum](https://esp32.com) or see[Contribute](#contribute).
68+
69+
##Contribute
70+
71+
To know how to contribute to this project, see[How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
72+
73+
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!
74+
75+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
76+
77+
##Resources
78+
79+
* Official ESP32 Forum:[Link](https://esp32.com)
80+
* Arduino-ESP32 Official Repository:[espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
81+
* ESP32-C6 Datasheet:[Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
82+
* ESP32-H2 Datasheet:[Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
83+
* Official ESP-IDF documentation:[ESP-IDF](https://idf.espressif.com)
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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 fan control.
17+
*
18+
* The example demonstrates how to use Zigbee library to create a router device fan control.
19+
* The fan control is a Zigbee router device, which is controlled by a Zigbee coordinator.
20+
*
21+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
22+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
23+
*
24+
* Please check the README.md for instructions and more detailed description.
25+
*
26+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
27+
*/
28+
29+
#ifndef ZIGBEE_MODE_ZCZR
30+
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
31+
#endif
32+
33+
#include"Zigbee.h"
34+
35+
/* Zigbee light bulb configuration*/
36+
#defineZIGBEE_FAN_CONTROL_ENDPOINT1
37+
38+
#ifdef RGB_BUILTIN
39+
uint8_t led = RGB_BUILTIN;// To demonstrate the current fan control mode
40+
#else
41+
uint8_t led =2;
42+
#endif
43+
44+
uint8_t button = BOOT_PIN;
45+
46+
ZigbeeFanControl zbFanControl = ZigbeeFanControl(ZIGBEE_FAN_CONTROL_ENDPOINT);
47+
48+
/********************* fan control callback function **************************/
49+
voidsetFan(ZigbeeFanMode mode) {
50+
switch (mode) {
51+
case FAN_MODE_OFF:
52+
rgbLedWrite(led,0,0,0);// Off
53+
Serial.println("Fan mode: OFF");
54+
break;
55+
case FAN_MODE_LOW:
56+
rgbLedWrite(led,0,0,255);// Blue
57+
Serial.println("Fan mode: LOW");
58+
break;
59+
case FAN_MODE_MEDIUM:
60+
rgbLedWrite(led,255,255,0);// Yellow
61+
Serial.println("Fan mode: MEDIUM");
62+
break;
63+
case FAN_MODE_HIGH:
64+
rgbLedWrite(led,255,0,0);// Red
65+
Serial.println("Fan mode: HIGH");
66+
break;
67+
case FAN_MODE_ON:
68+
rgbLedWrite(led,255,255,255);// White
69+
Serial.println("Fan mode: ON");
70+
break;
71+
default:log_e("Unhandled fan mode: %d", mode);break;
72+
}
73+
}
74+
75+
/********************* Arduino functions **************************/
76+
voidsetup() {
77+
Serial.begin(115200);
78+
79+
// Init LED that will be used to indicate the current fan control mode
80+
rgbLedWrite(led,0,0,0);
81+
82+
// Init button for factory reset
83+
pinMode(button, INPUT_PULLUP);
84+
85+
//Optional: set Zigbee device name and model
86+
zbFanControl.setManufacturerAndModel("Espressif","ZBFanControl");
87+
88+
// Set the fan mode sequence to LOW_MED_HIGH
89+
zbFanControl.setFanModeSequence(FAN_MODE_SEQUENCE_LOW_MED_HIGH);
90+
91+
// Set callback function for fan mode change
92+
zbFanControl.onFanModeChange(setFan);
93+
94+
//Add endpoint to Zigbee Core
95+
Serial.println("Adding ZigbeeFanControl endpoint to Zigbee Core");
96+
Zigbee.addEndpoint(&zbFanControl);
97+
98+
// When all EPs are registered, start Zigbee in ROUTER mode
99+
if (!Zigbee.begin(ZIGBEE_ROUTER)) {
100+
Serial.println("Zigbee failed to start!");
101+
Serial.println("Rebooting...");
102+
ESP.restart();
103+
}
104+
Serial.println("Connecting to network");
105+
while (!Zigbee.connected()) {
106+
Serial.print(".");
107+
delay(100);
108+
}
109+
Serial.println();
110+
}
111+
112+
voidloop() {
113+
// Checking button for factory reset
114+
if (digitalRead(button) == LOW) {// Push button pressed
115+
// Key debounce handling
116+
delay(100);
117+
int startTime =millis();
118+
while (digitalRead(button) == LOW) {
119+
delay(50);
120+
if ((millis() - startTime) >3000) {
121+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
122+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
123+
delay(1000);
124+
Zigbee.factoryReset();
125+
}
126+
}
127+
}
128+
delay(100);
129+
}
Lines changed: 6 additions & 0 deletions
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_ZB_ENABLED=y"
5+
]
6+
}

‎libraries/Zigbee/keywords.txt

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,31 @@ ZigbeeKEYWORD1
1212
ZigbeeEPKEYWORD1
1313

1414
# Endpoint Classes
15-
ZigbeeLightKEYWORD1
16-
ZigbeeSwitchKEYWORD1
17-
ZigbeeColorDimmableLightKEYWORD1
18-
ZigbeeColorDimmerSwitchKEYWORD1
19-
ZigbeeTempSensorKEYWORD1
20-
ZigbeeThermostatKEYWORD1
21-
ZigbeeFlowSensorKEYWORD1
22-
ZigbeePressureSensorKEYWORD1
23-
ZigbeeOccupancySensorKEYWORD1
2415
ZigbeeAnalogKEYWORD1
16+
ZigbeeBinaryKEYWORD1
2517
ZigbeeCarbonDioxideSensorKEYWORD1
18+
ZigbeeColorDimmableLightKEYWORD1
19+
ZigbeeColorDimmerSwitchKEYWORD1
2620
ZigbeeContactSwitchKEYWORD1
21+
ZigbeeDimableLightKEYWORD1
2722
ZigbeeDoorWindowHandleKEYWORD1
23+
ZigbeeElectricalMeasurementKEYWORD1
24+
ZigbeeFanControlKEYWORD1
25+
ZigbeeFlowSensorKEYWORD1
2826
ZigbeeGatewayKEYWORD1
27+
ZigbeeIlluminanceSensorKEYWORD1
28+
ZigbeeLightKEYWORD1
29+
ZigbeeOccupancySensorKEYWORD1
30+
ZigbeePM25SensorKEYWORD1
31+
ZigbeePowerOutletKEYWORD1
32+
ZigbeePressureSensorKEYWORD1
2933
ZigbeeRangeExtenderKEYWORD1
34+
ZigbeeSwitchKEYWORD1
35+
ZigbeeTempSensorKEYWORD1
36+
ZigbeeThermostatKEYWORD1
3037
ZigbeeVibrationSensorKEYWORD1
3138
ZigbeeWindowCoveringKEYWORD1
32-
ZigbeeIlluminanceSensorKEYWORD1
33-
ZigbeePowerOutletKEYWORD1
39+
ZigbeeWindSpeedSensorKEYWORD1
3440

3541
# Other
3642
zigbee_role_tKEYWORD1
@@ -39,6 +45,8 @@ zb_device_params_tKEYWORD1
3945
zigbee_scan_result_tKEYWORD1
4046
zb_power_source_tKEYWORD1
4147
ZigbeeWindowCoveringTypeKEYWORD1
48+
ZigbeeFanModeKEYWORD1
49+
ZigbeeFanModeSequenceKEYWORD1
4250

4351
#######################################
4452
# Methods and Functions (KEYWORD2)
@@ -73,13 +81,21 @@ printBoundDevicesKEYWORD2
7381
getBoundDevicesKEYWORD2
7482
boundKEYWORD2
7583
allowMultipleBindingKEYWORD2
84+
setManualBindingKEYWORD2
7685
setManufacturerAndModelKEYWORD2
7786
setPowerSourceKEYWORD2
7887
setBatteryPercentageKEYWORD2
7988
reportBatteryPercentageKEYWORD2
8089
readManufacturerKEYWORD2
8190
readModelKEYWORD2
8291
onIdentifyKEYWORD2
92+
addTimeClusterKEYWORD2
93+
setTimeKEYWORD2
94+
setTimezoneKEYWORD2
95+
getTimeKEYWORD2
96+
getTimezoneKEYWORD2
97+
addOTAClientKEYWORD2
98+
clearBoundDevicesKEYWORD2
8399

84100
# ZigbeeLight + ZigbeeColorDimmableLight
85101
onLightChangeKEYWORD2
@@ -171,7 +187,7 @@ setTiltedKEYWORD2
171187
# ZigbeeVibrationSensor
172188
setVibrationKEYWORD2
173189

174-
ZigbeeWindowCovering
190+
#ZigbeeWindowCovering
175191
onOpenKEYWORD2
176192
onCloseKEYWORD2
177193
onGoToLiftPercentageKEYWORD2
@@ -186,6 +202,26 @@ setConfigStatusKEYWORD2
186202
setModeKEYWORD2
187203
setLimitsKEYWORD2
188204

205+
# ZigbeeBinary
206+
addBinaryInputKEYWORD2
207+
addBinaryOutputKEYWORD2
208+
onBinaryOutputChangeKEYWORD2
209+
setBinaryInputKEYWORD2
210+
setBinaryOutputKEYWORD2
211+
getBinaryOutputKEYWORD2
212+
reportBinaryInputKEYWORD2
213+
reportBinaryOutputKEYWORD2
214+
setBinaryInputApplicationKEYWORD2
215+
setBinaryInputDescriptionKEYWORD2
216+
setBinaryOutputApplicationKEYWORD2
217+
setBinaryOutputDescriptionKEYWORD2
218+
219+
# ZigbeeFanControl
220+
setFanModeSequenceKEYWORD2
221+
getFanModeKEYWORD2
222+
getFanModeSequenceKEYWORD2
223+
onFanModeChangeKEYWORD2
224+
189225
#######################################
190226
# Constants (LITERAL1)
191227
#######################################

‎libraries/Zigbee/src/Zigbee.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include"ep/ZigbeeLight.h"
1717
//// Controllers
1818
#include"ep/ZigbeeThermostat.h"
19+
#include"ep/ZigbeeFanControl.h"
1920
////Outlets
2021
#include"ep/ZigbeePowerOutlet.h"
2122
//// Sensors

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp