@@ -41,21 +41,6 @@ uint8_t button = BOOT_PIN;
41
41
ZigbeeFlowSensor zbFlowSensor = ZigbeeFlowSensor(FLOW_SENSOR_ENDPOINT_NUMBER);
42
42
ZigbeePressureSensor zbPressureSensor = ZigbeePressureSensor(PRESSURE_SENSOR_ENDPOINT_NUMBER);
43
43
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 **************************/
59
44
void setup () {
60
45
Serial.begin (115200 );
61
46
@@ -65,19 +50,19 @@ void setup() {
65
50
// Optional: set Zigbee device name and model
66
51
zbFlowSensor.setManufacturerAndModel (" Espressif" , " ZigbeeFlowSensor" );
67
52
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 );
70
55
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 );
73
58
74
59
// Optional: set Zigbee device name and model
75
60
zbPressureSensor.setManufacturerAndModel (" Espressif" , " ZigbeePressureSensor" );
76
61
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 );
79
64
80
- // Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
65
+ // Set tolerance for temperature measurement in hPa
81
66
zbPressureSensor.setTolerance (1 );
82
67
83
68
// Add endpoints to Zigbee Core
@@ -100,19 +85,28 @@ void setup() {
100
85
}
101
86
Serial.println ();
102
87
103
- // Start Flow and Pressure sensor reading task
104
- xTaskCreate (sensors_reading, " flow_pressure_sensors_read" , 2048 , NULL , 10 , NULL );
105
-
106
88
// 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)
108
90
// if min = 1 and max = 0, reporting is sent only when temperature changes by delta
109
91
// if min = 0 and max = 10, reporting is sent every 10 seconds or temperature changes by delta
110
92
// 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 );
112
94
zbPressureSensor.setReporting (0 , 30 , 1 );
113
95
}
114
96
115
97
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
+
116
110
// Checking button for factory reset
117
111
if (digitalRead (button) == LOW) { // Push button pressed
118
112
// Key debounce handling
0 commit comments