Merge branch 'master' into release/v3.3.x

This commit is contained in:
Me No Dev 2025-07-08 17:59:48 +03:00 committed by GitHub
commit df3db3c9dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 437 additions and 31 deletions

View file

@ -24,4 +24,5 @@ jobs:
instructions-cla-link: "https://cla-assistant.io/espressif/arduino-esp32" instructions-cla-link: "https://cla-assistant.io/espressif/arduino-esp32"
instructions-contributions-file: "docs/en/contributing.rst" instructions-contributions-file: "docs/en/contributing.rst"
rule-max-commits: "false" rule-max-commits: "false"
rule-target-branch: "false"
commit-messages-min-summary-length: "10" commit-messages-min-summary-length: "10"

View file

@ -306,6 +306,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp
libraries/Zigbee/src/ep/ZigbeeBinary.cpp libraries/Zigbee/src/ep/ZigbeeBinary.cpp
libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp
libraries/Zigbee/src/ep/ZigbeeFanControl.cpp
) )
set(ARDUINO_LIBRARY_BLE_SRCS set(ARDUINO_LIBRARY_BLE_SRCS

View file

@ -51016,10 +51016,12 @@ rakwireless_rak3112.build.dfu_on_boot=0
rakwireless_rak3112.build.f_cpu=240000000L rakwireless_rak3112.build.f_cpu=240000000L
rakwireless_rak3112.build.flash_size=16MB rakwireless_rak3112.build.flash_size=16MB
rakwireless_rak3112.build.flash_freq=80m rakwireless_rak3112.build.flash_freq=80m
rakwireless_rak3112.build.flash_mode=dio rakwireless_rak3112.build.flash_mode=qio
rakwireless_rak3112.build.boot=dio rakwireless_rak3112.build.boot=qio
rakwireless_rak3112.build.partitions=default rakwireless_rak3112.build.partitions=default
rakwireless_rak3112.build.defines= rakwireless_rak3112.build.defines=
rakwireless_rak3112.build.psram_type=opi
rakwireless_rak3112.build.memory_type={build.boot}_{build.psram_type}
rakwireless_rak3112.menu.PSRAM.enabled=Enabled rakwireless_rak3112.menu.PSRAM.enabled=Enabled
rakwireless_rak3112.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM rakwireless_rak3112.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM

View file

@ -56,6 +56,13 @@ static bool i2cDetachBus(void *bus_i2c_num) {
return true; return true;
} }
void *i2cBusHandle(uint8_t i2c_num) {
if (i2c_num >= SOC_I2C_NUM) {
return NULL;
}
return bus[i2c_num].bus_handle;
}
bool i2cIsInit(uint8_t i2c_num) { bool i2cIsInit(uint8_t i2c_num) {
if (i2c_num >= SOC_I2C_NUM) { if (i2c_num >= SOC_I2C_NUM) {
return false; return false;

View file

@ -19,6 +19,7 @@
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#if SOC_I2C_SUPPORTED #if SOC_I2C_SUPPORTED
#include "esp_idf_version.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -39,6 +40,10 @@ esp_err_t i2cWriteReadNonStop(
); );
bool i2cIsInit(uint8_t i2c_num); bool i2cIsInit(uint8_t i2c_num);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
void *i2cBusHandle(uint8_t i2c_num);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -582,8 +582,8 @@ bool AsyncUDP::listen(const ip_addr_t *addr, uint16_t port) {
} }
close(); close();
if (addr) { if (addr) {
IP_SET_TYPE_VAL(_pcb->local_ip, addr->type); IP_SET_TYPE_VAL(_pcb->local_ip, IP_GET_TYPE(addr));
IP_SET_TYPE_VAL(_pcb->remote_ip, addr->type); IP_SET_TYPE_VAL(_pcb->remote_ip, IP_GET_TYPE(addr));
} }
if (_udp_bind(_pcb, addr, port) != ERR_OK) { if (_udp_bind(_pcb, addr, port) != ERR_OK) {
return false; return false;
@ -692,17 +692,8 @@ bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl
return false; return false;
} }
#if CONFIG_LWIP_IPV6 IP_SET_TYPE(&bind_addr, IP_GET_TYPE(addr));
if (IP_IS_V6(addr)) { ip_addr_set_any(IP_IS_V6(addr), &bind_addr);
IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V6);
ip6_addr_set_any(&bind_addr.u_addr.ip6);
} else {
#endif
IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V4);
ip4_addr_set_any(&bind_addr.u_addr.ip4);
#if CONFIG_LWIP_IPV6
}
#endif
if (!listen(&bind_addr, port)) { if (!listen(&bind_addr, port)) {
return false; return false;
} }

View file

@ -39,7 +39,7 @@ extern "C" {
#include "Arduino.h" #include "Arduino.h"
TwoWire::TwoWire(uint8_t bus_num) TwoWire::TwoWire(uint8_t bus_num)
: num(bus_num & 1), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size : num(bus_num), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size
, ,
rxBuffer(NULL), rxIndex(0), rxLength(0), txBuffer(NULL), txLength(0), txAddress(0), _timeOutMillis(50), nonStop(false) rxBuffer(NULL), rxIndex(0), rxLength(0), txBuffer(NULL), txLength(0), txAddress(0), _timeOutMillis(50), nonStop(false)
#if !CONFIG_DISABLE_HAL_LOCKS #if !CONFIG_DISABLE_HAL_LOCKS
@ -62,6 +62,10 @@ TwoWire::~TwoWire() {
#endif #endif
} }
uint8_t TwoWire::getBusNum() {
return num;
}
bool TwoWire::initPins(int sdaPin, int sclPin) { bool TwoWire::initPins(int sdaPin, int sclPin) {
if (sdaPin < 0) { // default param passed if (sdaPin < 0) { // default param passed
if (num == 0) { if (num == 0) {

View file

@ -105,6 +105,8 @@ public:
bool end() override; bool end() override;
uint8_t getBusNum();
bool setClock(uint32_t freq) override; bool setClock(uint32_t freq) override;
void beginTransmission(uint8_t address) override; void beginTransmission(uint8_t address) override;

View file

@ -0,0 +1,83 @@
# Arduino-ESP32 Zigbee Fan Control Example
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.
# Supported Targets
Currently, this example supports the following targets.
| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |
## Fan Control Functions
1. Initialize a Zigbee fan control device.
2. Control fan modes (OFF, LOW, MEDIUM, HIGH, ON).
3. Respond to fan control commands from the Zigbee network.
## Hardware Required
* ESP32-H2 or ESP32-C6 development board
* A USB cable for power supply and programming
* RGB LED for visual feedback (built-in on most development boards)
### Configure the Project
In this example the RGB LED is used to indicate the current fan control mode.
The LED colors represent different fan modes:
- OFF: No light
- LOW: Blue
- MEDIUM: Yellow
- HIGH: Red
- ON: White
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).
#### 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 ZCZR (coordinator/router)`
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee ZCZR 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)

View file

@ -0,0 +1,129 @@
// Copyright 2025 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 simple Zigbee fan control.
*
* The example demonstrates how to use Zigbee library to create a router device fan control.
* The fan control is a Zigbee router 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_ZCZR
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
#endif
#include "Zigbee.h"
/* Zigbee light bulb configuration */
#define ZIGBEE_FAN_CONTROL_ENDPOINT 1
#ifdef RGB_BUILTIN
uint8_t led = RGB_BUILTIN; // To demonstrate the current fan control mode
#else
uint8_t led = 2;
#endif
uint8_t button = BOOT_PIN;
ZigbeeFanControl zbFanControl = ZigbeeFanControl(ZIGBEE_FAN_CONTROL_ENDPOINT);
/********************* fan control callback function **************************/
void setFan(ZigbeeFanMode mode) {
switch (mode) {
case FAN_MODE_OFF:
rgbLedWrite(led, 0, 0, 0); // Off
Serial.println("Fan mode: OFF");
break;
case FAN_MODE_LOW:
rgbLedWrite(led, 0, 0, 255); // Blue
Serial.println("Fan mode: LOW");
break;
case FAN_MODE_MEDIUM:
rgbLedWrite(led, 255, 255, 0); // Yellow
Serial.println("Fan mode: MEDIUM");
break;
case FAN_MODE_HIGH:
rgbLedWrite(led, 255, 0, 0); // Red
Serial.println("Fan mode: HIGH");
break;
case FAN_MODE_ON:
rgbLedWrite(led, 255, 255, 255); // White
Serial.println("Fan mode: ON");
break;
default: log_e("Unhandled fan mode: %d", mode); break;
}
}
/********************* Arduino functions **************************/
void setup() {
Serial.begin(115200);
// Init LED that will be used to indicate the current fan control mode
rgbLedWrite(led, 0, 0, 0);
// Init button for factory reset
pinMode(button, INPUT_PULLUP);
//Optional: set Zigbee device name and model
zbFanControl.setManufacturerAndModel("Espressif", "ZBFanControl");
// Set the fan mode sequence to LOW_MED_HIGH
zbFanControl.setFanModeSequence(FAN_MODE_SEQUENCE_LOW_MED_HIGH);
// Set callback function for fan mode change
zbFanControl.onFanModeChange(setFan);
//Add endpoint to Zigbee Core
Serial.println("Adding ZigbeeFanControl endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbFanControl);
// When all EPs are registered, start Zigbee in ROUTER mode
if (!Zigbee.begin(ZIGBEE_ROUTER)) {
Serial.println("Zigbee failed to start!");
Serial.println("Rebooting...");
ESP.restart();
}
Serial.println("Connecting to network");
while (!Zigbee.connected()) {
Serial.print(".");
delay(100);
}
Serial.println();
}
void loop() {
// Checking button for factory reset
if (digitalRead(button) == LOW) { // Push button pressed
// Key debounce handling
delay(100);
int startTime = millis();
while (digitalRead(button) == LOW) {
delay(50);
if ((millis() - startTime) > 3000) {
// If key pressed for more than 3secs, factory reset Zigbee and reboot
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
delay(1000);
Zigbee.factoryReset();
}
}
}
delay(100);
}

View file

@ -0,0 +1,6 @@
{
"fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr",
"requires": [
"CONFIG_ZB_ENABLED=y"
]
}

View file

@ -12,25 +12,31 @@ Zigbee KEYWORD1
ZigbeeEP KEYWORD1 ZigbeeEP KEYWORD1
# Endpoint Classes # Endpoint Classes
ZigbeeLight KEYWORD1 ZigbeeAnalog KEYWORD1
ZigbeeSwitch KEYWORD1 ZigbeeBinary KEYWORD1
ZigbeeCarbonDioxideSensor KEYWORD1
ZigbeeColorDimmableLight KEYWORD1 ZigbeeColorDimmableLight KEYWORD1
ZigbeeColorDimmerSwitch KEYWORD1 ZigbeeColorDimmerSwitch KEYWORD1
ZigbeeContactSwitch KEYWORD1
ZigbeeDimableLight KEYWORD1
ZigbeeDoorWindowHandle KEYWORD1
ZigbeeElectricalMeasurement KEYWORD1
ZigbeeFanControl KEYWORD1
ZigbeeFlowSensor KEYWORD1
ZigbeeGateway KEYWORD1
ZigbeeIlluminanceSensor KEYWORD1
ZigbeeLight KEYWORD1
ZigbeeOccupancySensor KEYWORD1
ZigbeePM25Sensor KEYWORD1
ZigbeePowerOutlet KEYWORD1
ZigbeePressureSensor KEYWORD1
ZigbeeRangeExtender KEYWORD1
ZigbeeSwitch KEYWORD1
ZigbeeTempSensor KEYWORD1 ZigbeeTempSensor KEYWORD1
ZigbeeThermostat KEYWORD1 ZigbeeThermostat KEYWORD1
ZigbeeFlowSensor KEYWORD1
ZigbeePressureSensor KEYWORD1
ZigbeeOccupancySensor KEYWORD1
ZigbeeAnalog KEYWORD1
ZigbeeCarbonDioxideSensor KEYWORD1
ZigbeeContactSwitch KEYWORD1
ZigbeeDoorWindowHandle KEYWORD1
ZigbeeGateway KEYWORD1
ZigbeeRangeExtender KEYWORD1
ZigbeeVibrationSensor KEYWORD1 ZigbeeVibrationSensor KEYWORD1
ZigbeeWindowCovering KEYWORD1 ZigbeeWindowCovering KEYWORD1
ZigbeeIlluminanceSensor KEYWORD1 ZigbeeWindSpeedSensor KEYWORD1
ZigbeePowerOutlet KEYWORD1
# Other # Other
zigbee_role_t KEYWORD1 zigbee_role_t KEYWORD1
@ -39,6 +45,8 @@ zb_device_params_t KEYWORD1
zigbee_scan_result_t KEYWORD1 zigbee_scan_result_t KEYWORD1
zb_power_source_t KEYWORD1 zb_power_source_t KEYWORD1
ZigbeeWindowCoveringType KEYWORD1 ZigbeeWindowCoveringType KEYWORD1
ZigbeeFanMode KEYWORD1
ZigbeeFanModeSequence KEYWORD1
####################################### #######################################
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
@ -73,6 +81,7 @@ printBoundDevices KEYWORD2
getBoundDevices KEYWORD2 getBoundDevices KEYWORD2
bound KEYWORD2 bound KEYWORD2
allowMultipleBinding KEYWORD2 allowMultipleBinding KEYWORD2
setManualBinding KEYWORD2
setManufacturerAndModel KEYWORD2 setManufacturerAndModel KEYWORD2
setPowerSource KEYWORD2 setPowerSource KEYWORD2
setBatteryPercentage KEYWORD2 setBatteryPercentage KEYWORD2
@ -80,6 +89,13 @@ reportBatteryPercentage KEYWORD2
readManufacturer KEYWORD2 readManufacturer KEYWORD2
readModel KEYWORD2 readModel KEYWORD2
onIdentify KEYWORD2 onIdentify KEYWORD2
addTimeCluster KEYWORD2
setTime KEYWORD2
setTimezone KEYWORD2
getTime KEYWORD2
getTimezone KEYWORD2
addOTAClient KEYWORD2
clearBoundDevices KEYWORD2
# ZigbeeLight + ZigbeeColorDimmableLight # ZigbeeLight + ZigbeeColorDimmableLight
onLightChange KEYWORD2 onLightChange KEYWORD2
@ -171,7 +187,7 @@ setTilted KEYWORD2
# ZigbeeVibrationSensor # ZigbeeVibrationSensor
setVibration KEYWORD2 setVibration KEYWORD2
ZigbeeWindowCovering # ZigbeeWindowCovering
onOpen KEYWORD2 onOpen KEYWORD2
onClose KEYWORD2 onClose KEYWORD2
onGoToLiftPercentage KEYWORD2 onGoToLiftPercentage KEYWORD2
@ -186,6 +202,26 @@ setConfigStatus KEYWORD2
setMode KEYWORD2 setMode KEYWORD2
setLimits KEYWORD2 setLimits KEYWORD2
# ZigbeeBinary
addBinaryInput KEYWORD2
addBinaryOutput KEYWORD2
onBinaryOutputChange KEYWORD2
setBinaryInput KEYWORD2
setBinaryOutput KEYWORD2
getBinaryOutput KEYWORD2
reportBinaryInput KEYWORD2
reportBinaryOutput KEYWORD2
setBinaryInputApplication KEYWORD2
setBinaryInputDescription KEYWORD2
setBinaryOutputApplication KEYWORD2
setBinaryOutputDescription KEYWORD2
# ZigbeeFanControl
setFanModeSequence KEYWORD2
getFanMode KEYWORD2
getFanModeSequence KEYWORD2
onFanModeChange KEYWORD2
####################################### #######################################
# Constants (LITERAL1) # Constants (LITERAL1)
####################################### #######################################

View file

@ -16,6 +16,7 @@
#include "ep/ZigbeeLight.h" #include "ep/ZigbeeLight.h"
//// Controllers //// Controllers
#include "ep/ZigbeeThermostat.h" #include "ep/ZigbeeThermostat.h"
#include "ep/ZigbeeFanControl.h"
////Outlets ////Outlets
#include "ep/ZigbeePowerOutlet.h" #include "ep/ZigbeePowerOutlet.h"
//// Sensors //// Sensors

View file

@ -0,0 +1,60 @@
#include "ZigbeeFanControl.h"
#if CONFIG_ZB_ENABLED
ZigbeeFanControl::ZigbeeFanControl(uint8_t endpoint) : ZigbeeEP(endpoint) {
_device_id = ESP_ZB_HA_THERMOSTAT_DEVICE_ID; //There is no FAN_CONTROL_DEVICE_ID in the Zigbee spec
//Create basic analog sensor clusters without configuration
_cluster_list = esp_zb_zcl_cluster_list_create();
esp_zb_cluster_list_add_basic_cluster(_cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_identify_cluster(_cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_fan_control_cluster(_cluster_list, esp_zb_fan_control_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
_ep_config = {
.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_HEATING_COOLING_UNIT_DEVICE_ID, .app_device_version = 0
};
}
bool ZigbeeFanControl::setFanModeSequence(ZigbeeFanModeSequence sequence) {
esp_zb_attribute_list_t *fan_control_cluster =
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_FAN_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_err_t ret = esp_zb_cluster_update_attr(fan_control_cluster, ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_SEQUENCE_ID, (void *)&sequence);
if (ret != ESP_OK) {
log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret));
return false;
}
_current_fan_mode_sequence = sequence;
_current_fan_mode = FAN_MODE_OFF;
// Set initial fan mode to OFF
ret = esp_zb_cluster_update_attr(fan_control_cluster, ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID, (void *)&_current_fan_mode);
if (ret != ESP_OK) {
log_e("Failed to set fan mode: 0x%x: %s", ret, esp_err_to_name(ret));
return false;
}
return true;
}
//set attribute method -> method overridden in child class
void ZigbeeFanControl::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) {
//check the data and call right method
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_FAN_CONTROL) {
if (message->attribute.id == ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_8BIT_ENUM) {
_current_fan_mode = *(ZigbeeFanMode *)message->attribute.data.value;
fanModeChanged();
} else {
log_w("Received message ignored. Attribute ID: %d not supported for Fan Control", message->attribute.id);
}
} else {
log_w("Received message ignored. Cluster ID: %d not supported for Fan Control", message->info.cluster);
}
}
void ZigbeeFanControl::fanModeChanged() {
if (_on_fan_mode_change) {
_on_fan_mode_change(_current_fan_mode);
} else {
log_w("No callback function set for fan mode change");
}
}
#endif // CONFIG_ZB_ENABLED

View file

@ -0,0 +1,65 @@
/* Class of Zigbee Pressure sensor endpoint inherited from common EP class */
#pragma once
#include "soc/soc_caps.h"
#include "sdkconfig.h"
#if CONFIG_ZB_ENABLED
#include "ZigbeeEP.h"
#include "ha/esp_zigbee_ha_standard.h"
// Custom Arduino-friendly enums for fan mode values
enum ZigbeeFanMode {
FAN_MODE_OFF = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_OFF,
FAN_MODE_LOW = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_LOW,
FAN_MODE_MEDIUM = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_MEDIUM,
FAN_MODE_HIGH = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_HIGH,
FAN_MODE_ON = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_ON,
FAN_MODE_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_AUTO,
FAN_MODE_SMART = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SMART,
};
// Custom Arduino-friendly enums for fan mode sequence
enum ZigbeeFanModeSequence {
FAN_MODE_SEQUENCE_LOW_MED_HIGH = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_MED_HIGH,
FAN_MODE_SEQUENCE_LOW_HIGH = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_HIGH,
FAN_MODE_SEQUENCE_LOW_MED_HIGH_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_MED_HIGH_AUTO,
FAN_MODE_SEQUENCE_LOW_HIGH_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_HIGH_AUTO,
FAN_MODE_SEQUENCE_ON_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_ON_AUTO,
};
class ZigbeeFanControl : public ZigbeeEP {
public:
ZigbeeFanControl(uint8_t endpoint);
~ZigbeeFanControl() {}
// Set the fan mode sequence value
bool setFanModeSequence(ZigbeeFanModeSequence sequence);
// Use to get fan mode
ZigbeeFanMode getFanMode() {
return _current_fan_mode;
}
// Use to get fan mode sequence
ZigbeeFanModeSequence getFanModeSequence() {
return _current_fan_mode_sequence;
}
// On fan mode change callback
void onFanModeChange(void (*callback)(ZigbeeFanMode mode)) {
_on_fan_mode_change = callback;
}
private:
void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override;
//callback function to be called on fan mode change
void (*_on_fan_mode_change)(ZigbeeFanMode mode);
void fanModeChanged();
ZigbeeFanMode _current_fan_mode;
ZigbeeFanModeSequence _current_fan_mode_sequence;
};
#endif // CONFIG_ZB_ENABLED

View file

@ -95,7 +95,7 @@ def generate_bootloader_image(bootloader_elf):
env.VerboseAction( env.VerboseAction(
" ".join( " ".join(
[ [
'"$PYTHONEXE" "$OBJCOPY"', "$OBJCOPY",
"--chip", "--chip",
build_mcu, build_mcu,
"elf2image", "elf2image",

View file

@ -47,4 +47,17 @@ static const uint8_t SCK = 13;
#define LORA_BUSY 48 #define LORA_BUSY 48
#define LORA_IRQ LORA_DIO1 #define LORA_IRQ LORA_DIO1
// For WisBlock modules, see: https://docs.rakwireless.com/Product-Categories/WisBlock/
#define WB_IO1 21
#define WB_IO2 14
#define WB_IO3 41
#define WB_IO4 42
#define WB_IO5 38
#define WB_IO6 39
#define WB_A0 1
#define WB_A1 2
#define WB_CS 12
#define WB_LED1 46
#define WB_LED2 45
#endif /* Pins_Arduino_h */ #endif /* Pins_Arduino_h */