Skip to content

Commit 5b149f6

Browse files
authored
Create ZigbeeWindSpeedSensor.ino
1 parent f063d8d commit 5b149f6

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @brief This example demonstrates Zigbee temperature sensor.
17+
*
18+
* The example demonstrates how to use Zigbee library to create a end device wind speed sensor.
19+
* The wind speed sensor is a Zigbee end device, which is controlled by a Zigbee coordinator.
20+
*
21+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
22+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
23+
*
24+
* Please check the README.md for instructions and more detailed description.
25+
*
26+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
27+
*/
28+
29+
#ifndef ZIGBEE_MODE_ED
30+
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
31+
#endif
32+
33+
#include "ZigbeeCore.h"
34+
#include "ep/ZigbeeWindSpeedSensor.h"
35+
36+
#define BUTTON_PIN 9 //Boot button for C6/H2
37+
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
38+
39+
ZigbeeWindSpeedSensor zbWindSpeedSensor = ZigbeeWindSpeedSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
40+
41+
/************************ Temp sensor *****************************/
42+
static void windspeed_sensor_value_update(void *arg) {
43+
for (;;) {
44+
// Read temperature sensor value
45+
float tsens_value = temperatureRead();
46+
log_v("Temperature sensor value: %.2f°C", tsens_value);
47+
// Update temperature value in Temperature sensor EP
48+
zbWindSpeedSensor.setWindspeed(tsens_value);
49+
delay(1000);
50+
}
51+
}
52+
53+
/********************* Arduino functions **************************/
54+
void setup() {
55+
56+
Serial.begin(115200);
57+
while (!Serial) {
58+
delay(10);
59+
}
60+
61+
// Init button switch
62+
pinMode(BUTTON_PIN, INPUT);
63+
64+
// Optional: set Zigbee device name and model
65+
zbWindSpeedSensor.setManufacturerAndModel("Espressif", "ZigbeeWindSpeedSensor");
66+
67+
// Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
68+
zbWindSpeedSensor.setMinMaxValue(10, 50);
69+
70+
// Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
71+
zbWindSpeedSensor.setTolerance(1);
72+
73+
// Add endpoint to Zigbee Core
74+
Zigbee.addEndpoint(&zbWindSpeedSensor);
75+
76+
// When all EPs are registered, start Zigbee in End Device mode
77+
Zigbee.begin();
78+
79+
// Start Wind speed sensor reading task
80+
xTaskCreate(windspeed_sensor_value_update, "wind_speed_sensor_update", 2048, NULL, 10, NULL);
81+
82+
// Set reporting interval for temperature measurement in seconds, must be called after Zigbee.begin()
83+
// min_interval and max_interval in seconds, delta (temp change in °C)
84+
// if min = 1 and max = 0, reporting is sent only when temperature changes by delta
85+
// if min = 0 and max = 10, reporting is sent every 10 seconds or temperature changes by delta
86+
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of temperature change
87+
zbWindSpeedSensor.setReporting(1, 0, 1);
88+
}
89+
90+
void loop() {
91+
// Checking button for factory reset
92+
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
93+
// Key debounce handling
94+
delay(100);
95+
int startTime = millis();
96+
while (digitalRead(BUTTON_PIN) == LOW) {
97+
delay(50);
98+
if ((millis() - startTime) > 3000) {
99+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
100+
Serial.printf("Resetting Zigbee to factory settings, reboot.\n");
101+
Zigbee.factoryReset();
102+
}
103+
}
104+
zbWindSpeedSensor.reportWindspeed();
105+
}
106+
delay(100);
107+
}

0 commit comments

Comments
 (0)