Skip to content

Commit ce9a34d

Browse files
committed
fix(zigbee): Update example + pressure unit
1 parent b64b850 commit ce9a34d

File tree

3 files changed

+27
-33
lines changed

3 files changed

+27
-33
lines changed

Diff for: libraries/Zigbee/examples/Zigbee_Pressure_Flow_Sensor/Zigbee_Pressure_Flow_Sensor.ino

+21-27
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ uint8_t button = BOOT_PIN;
4141
ZigbeeFlowSensor zbFlowSensor = ZigbeeFlowSensor(FLOW_SENSOR_ENDPOINT_NUMBER);
4242
ZigbeePressureSensor zbPressureSensor = ZigbeePressureSensor(PRESSURE_SENSOR_ENDPOINT_NUMBER);
4343

44-
/************************ Temp sensor *****************************/
45-
static void sensors_reading(void *arg) {
46-
for (;;) {
47-
// Read Pressure and Flow sensors value - here is chip temperature used as a dummy value for demonstration
48-
float flow_value = temperatureRead();
49-
uint16_t pressure_value = (uint16_t)temperatureRead()*100; //*100 for demonstration so the value is in 1-3hPa
50-
Serial.printf("Updating flow sensor value to %.2f\r\n", flow_value);
51-
zbFlowSensor.setFlow(flow_value);
52-
Serial.printf("Updating pressure sensor value to %d\r\n", pressure_value);
53-
zbPressureSensor.setPressure(pressure_value);
54-
delay(1000);
55-
}
56-
}
57-
58-
/********************* Arduino functions **************************/
5944
void setup() {
6045
Serial.begin(115200);
6146

@@ -65,19 +50,19 @@ void setup() {
6550
// Optional: set Zigbee device name and model
6651
zbFlowSensor.setManufacturerAndModel("Espressif", "ZigbeeFlowSensor");
6752

68-
// Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
69-
zbFlowSensor.setMinMaxValue(0, 100);
53+
// Set minimum and maximum flow measurement value in 0,1 m3/h
54+
zbFlowSensor.setMinMaxValue(0.0, 100.0);
7055

71-
// Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
72-
zbFlowSensor.setTolerance(1);
56+
// Set tolerance for flow measurement in 0,1 m3/h
57+
zbFlowSensor.setTolerance(1.0);
7358

7459
// Optional: set Zigbee device name and model
7560
zbPressureSensor.setManufacturerAndModel("Espressif", "ZigbeePressureSensor");
7661

77-
// Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
78-
zbPressureSensor.setMinMaxValue(0, 30);
62+
// Set minimum and maximum pressure measurement value in hPa
63+
zbPressureSensor.setMinMaxValue(0, 10000);
7964

80-
// Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
65+
// Set tolerance for temperature measurement in hPa
8166
zbPressureSensor.setTolerance(1);
8267

8368
// Add endpoints to Zigbee Core
@@ -100,19 +85,28 @@ void setup() {
10085
}
10186
Serial.println();
10287

103-
// Start Flow and Pressure sensor reading task
104-
xTaskCreate(sensors_reading, "flow_pressure_sensors_read", 2048, NULL, 10, NULL);
105-
10688
// Set reporting interval for flow and pressure measurement in seconds, must be called after Zigbee.begin()
107-
// min_interval and max_interval in seconds, delta (pressure change in Pa, flow change in 0,1 m3/h)
89+
// min_interval and max_interval in seconds, delta (pressure change in hPa, flow change in 0,1 m3/h)
10890
// if min = 1 and max = 0, reporting is sent only when temperature changes by delta
10991
// if min = 0 and max = 10, reporting is sent every 10 seconds or temperature changes by delta
11092
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of delta change
111-
zbFlowSensor.setReporting(0, 30, 1);
93+
zbFlowSensor.setReporting(0, 30, 1.0);
11294
zbPressureSensor.setReporting(0, 30, 1);
11395
}
11496

11597
void loop() {
98+
static uint32_t timeCounter = 0;
99+
100+
// Read flow nad pressure sensors every 2s
101+
if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s
102+
float flow_value = temperatureRead();
103+
uint16_t pressure_value = (uint16_t)temperatureRead()*100; //*100 for demonstration so the value is in 1000-3000hPa
104+
Serial.printf("Updating flow sensor value to %.2f m3/h\r\n", flow_value);
105+
zbFlowSensor.setFlow(flow_value);
106+
Serial.printf("Updating pressure sensor value to %d hPa\r\n", pressure_value);
107+
zbPressureSensor.setPressure(pressure_value);
108+
}
109+
116110
// Checking button for factory reset
117111
if (digitalRead(button) == LOW) { // Push button pressed
118112
// Key debounce handling

Diff for: libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void ZigbeePressureSensor::setReporting(uint16_t min_interval, uint16_t max_inte
5555
.max_interval = max_interval,
5656
.delta =
5757
{
58-
.u16 = delta, // x Pa
58+
.u16 = delta, // x hPa
5959
},
6060
.def_min_interval = min_interval,
6161
.def_max_interval = max_interval,
@@ -75,7 +75,7 @@ void ZigbeePressureSensor::setReporting(uint16_t min_interval, uint16_t max_inte
7575
void ZigbeePressureSensor::setPressure(int16_t pressure) {
7676
log_v("Updating pressure sensor value...");
7777
/* Update temperature sensor measured value */
78-
log_d("Setting pressure to %d Pa", pressure);
78+
log_d("Setting pressure to %d hPa", pressure);
7979
esp_zb_lock_acquire(portMAX_DELAY);
8080
esp_zb_zcl_set_attribute_val(
8181
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_PRESSURE_MEASUREMENT_VALUE_ID, &pressure, false

Diff for: libraries/Zigbee/src/ep/ZigbeePressureSensor.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ class ZigbeePressureSensor : public ZigbeeEP {
3939
ZigbeePressureSensor(uint8_t endpoint);
4040
~ZigbeePressureSensor();
4141

42-
// Set the pressure value in 1 Pa
42+
// Set the pressure value in 1 hPa
4343
void setPressure(int16_t value);
4444

45-
// Set the min and max value for the pressure sensor in 1 Pa
45+
// Set the min and max value for the pressure sensor in 1 hPa
4646
void setMinMaxValue(int16_t min, int16_t max);
4747

48-
// Set the tolerance value for the pressure sensor in 1 Pa
48+
// Set the tolerance value for the pressure sensor in 1 hPa
4949
void setTolerance(uint16_t tolerance);
5050

51-
// Set the reporting interval for pressure measurement in seconds and delta (pressure change in 1 Pa)
51+
// Set the reporting interval for pressure measurement in seconds and delta (pressure change in 1 hPa)
5252
void setReporting(uint16_t min_interval, uint16_t max_interval, uint16_t delta);
5353

5454
// Report the pressure value

0 commit comments

Comments
 (0)