@@ -41,21 +41,6 @@ uint8_t button = BOOT_PIN;
4141ZigbeeFlowSensor zbFlowSensor = ZigbeeFlowSensor(FLOW_SENSOR_ENDPOINT_NUMBER);
4242ZigbeePressureSensor 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 **************************/
5944void 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
11597void 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
0 commit comments