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

Appearance settings

Commit d3509ef

Browse filesBrowse files
P-R-O-C-H-YCopilotpre-commit-ci-lite[bot]
authored
feat(zigbee): Add battery voltage attribute support (espressif#11210)
* feat(zigbee): Add battery voltage attribute support * Update libraries/Zigbee/src/ZigbeeEP.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 7f60945 commit d3509ef
Copy full SHA for d3509ef

File tree

3 files changed

+28
-7
lines changed
Filter options

3 files changed

+28
-7
lines changed

‎libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino

Copy file name to clipboardExpand all lines: libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ void setup() {
8585
// Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
8686
zbTempSensor.setTolerance(1);
8787

88-
// Set power source to battery and set battery percentage to measured value (now 100% for demonstration)
89-
// The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) anytime
90-
zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100);
88+
// Set power source to battery, battery percentage and battery voltage (now 100% and 3.5V for demonstration)
89+
// The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) or zbTempSensor.setBatteryVoltage(voltage) anytime after Zigbee.begin()
90+
zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100, 35);
9191

9292
// Add humidity cluster to the temperature sensor device with min, max and tolerance values
9393
zbTempSensor.addHumiditySensor(0, 100, 1);

‎libraries/Zigbee/src/ZigbeeEP.cpp

Copy file name to clipboardExpand all lines: libraries/Zigbee/src/ZigbeeEP.cpp
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
7373
return ret_name == ESP_OK && ret_model == ESP_OK;
7474
}
7575

76-
bool ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_percentage) {
76+
bool ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_percentage, uint8_t battery_voltage) {
7777
esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
7878
esp_err_t ret = esp_zb_cluster_update_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, (void *)&power_source);
7979
if (ret != ESP_OK) {
@@ -93,6 +93,11 @@ bool ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_pe
9393
log_e("Failed to add battery percentage attribute: 0x%x: %s", ret, esp_err_to_name(ret));
9494
return false;
9595
}
96+
ret = esp_zb_power_config_cluster_add_attr(power_config_cluster, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID, (void *)&battery_voltage);
97+
if (ret != ESP_OK) {
98+
log_e("Failed to add battery voltage attribute: 0x%x: %s", ret, esp_err_to_name(ret));
99+
return false;
100+
}
96101
ret = esp_zb_cluster_list_add_power_config_cluster(_cluster_list, power_config_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
97102
if (ret != ESP_OK) {
98103
log_e("Failed to add power config cluster: 0x%x: %s", ret, esp_err_to_name(ret));
@@ -125,6 +130,21 @@ bool ZigbeeEP::setBatteryPercentage(uint8_t percentage) {
125130
return true;
126131
}
127132

133+
bool ZigbeeEP::setBatteryVoltage(uint8_t voltage) {
134+
esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
135+
esp_zb_lock_acquire(portMAX_DELAY);
136+
ret = esp_zb_zcl_set_attribute_val(
137+
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_POWER_CONFIG, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID, &voltage, false
138+
);
139+
esp_zb_lock_release();
140+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
141+
log_e("Failed to set battery voltage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
142+
return false;
143+
}
144+
log_v("Battery voltage updated");
145+
return true;
146+
}
147+
128148
bool ZigbeeEP::reportBatteryPercentage() {
129149
/* Send report attributes command */
130150
esp_zb_zcl_report_attr_cmd_t report_attr_cmd;

‎libraries/Zigbee/src/ZigbeeEP.h

Copy file name to clipboardExpand all lines: libraries/Zigbee/src/ZigbeeEP.h
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ class ZigbeeEP {
8181
char *readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr);
8282

8383
// Set Power source and battery percentage for battery powered devices
84-
bool setPowerSource(zb_power_source_t power_source, uint8_t percentage = 255);
85-
bool setBatteryPercentage(uint8_t percentage);
86-
bool reportBatteryPercentage();
84+
bool setPowerSource(zb_power_source_t power_source, uint8_t percentage = 0xff, uint8_t voltage = 0xff); // voltage in 100mV
85+
bool setBatteryPercentage(uint8_t percentage); // 0-100 %
86+
bool setBatteryVoltage(uint8_t voltage); // voltage in 100mV (example value 35 for 3.5V)
87+
bool reportBatteryPercentage(); // battery voltage is not reportable attribute
8788

8889
// Set time
8990
bool addTimeCluster(tm time = {}, int32_t gmt_offset = 0); // gmt offset in seconds

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.