34
34
#include " Zigbee.h"
35
35
36
36
/* Zigbee thermostat configuration */
37
- #define THERMOSTAT_ENDPOINT_NUMBER 5
37
+ #define THERMOSTAT_ENDPOINT_NUMBER 1
38
+ #define USE_RECEIVE_TEMP_WITH_SOURCE 1
38
39
uint8_t button = BOOT_PIN;
39
40
40
41
ZigbeeThermostat zbThermostat = ZigbeeThermostat(THERMOSTAT_ENDPOINT_NUMBER);
@@ -48,13 +49,28 @@ float sensor_tolerance;
48
49
struct tm timeinfo = {}; // Time structure for Time cluster
49
50
50
51
/* ***************** Temperature sensor handling *******************/
51
- void recieveSensorTemp (float temperature) {
52
+ #if USE_RECEIVE_TEMP_WITH_SOURCE == 0
53
+ void receiveSensorTemp (float temperature) {
52
54
Serial.printf (" Temperature sensor value: %.2f°C\n " , temperature);
53
55
sensor_temp = temperature;
54
56
}
57
+ #else
58
+ void receiveSensorTempWithSource (float temperature, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address) {
59
+ if (src_address.addr_type == ESP_ZB_ZCL_ADDR_TYPE_SHORT) {
60
+ Serial.printf (" Temperature sensor value: %.2f°C from endpoint %d, address 0x%04x\n " , temperature, src_endpoint, src_address.u .short_addr );
61
+ } else {
62
+ Serial.printf (
63
+ " Temperature sensor value: %.2f°C from endpoint %d, address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n " , temperature, src_endpoint,
64
+ src_address.u .ieee_addr [7 ], src_address.u .ieee_addr [6 ], src_address.u .ieee_addr [5 ], src_address.u .ieee_addr [4 ], src_address.u .ieee_addr [3 ],
65
+ src_address.u .ieee_addr [2 ], src_address.u .ieee_addr [1 ], src_address.u .ieee_addr [0 ]
66
+ );
67
+ }
68
+ sensor_temp = temperature;
69
+ }
70
+ #endif
55
71
56
- void recieveSensorConfig (float min_temp, float max_temp, float tolerance) {
57
- Serial.printf (" Temperature sensor settings : min %.2f°C, max %.2f°C, tolerance %.2f°C\n " , min_temp, max_temp, tolerance);
72
+ void receiveSensorConfig (float min_temp, float max_temp, float tolerance) {
73
+ Serial.printf (" Temperature sensor config : min %.2f°C, max %.2f°C, tolerance %.2f°C\n " , min_temp, max_temp, tolerance);
58
74
sensor_min_temp = min_temp;
59
75
sensor_max_temp = max_temp;
60
76
sensor_tolerance = tolerance;
@@ -66,9 +82,15 @@ void setup() {
66
82
// Init button switch
67
83
pinMode (button, INPUT_PULLUP);
68
84
69
- // Set callback functions for temperature and configuration receive
70
- zbThermostat.onTempRecieve (recieveSensorTemp);
71
- zbThermostat.onConfigRecieve (recieveSensorConfig);
85
+ // Set callback function for receiving temperature from sensor - Use only one option
86
+ #if USE_RECEIVE_TEMP_WITH_SOURCE == 0
87
+ zbThermostat.onTempReceive (receiveSensorTemp); // If you bound only one sensor or you don't need to know the source of the temperature
88
+ #else
89
+ zbThermostat.onTempReceiveWithSource (receiveSensorTempWithSource);
90
+ #endif
91
+
92
+ // Set callback function for receiving sensor configuration
93
+ zbThermostat.onConfigReceive (receiveSensorConfig);
72
94
73
95
// Optional: set Zigbee device name and model
74
96
zbThermostat.setManufacturerAndModel (" Espressif" , " ZigbeeThermostat" );
@@ -107,19 +129,30 @@ void setup() {
107
129
108
130
Serial.println ();
109
131
110
- // Get temperature sensor configuration
111
- zbThermostat.getSensorSettings ();
132
+ // Get temperature sensor configuration for all bound sensors by endpoint number and address
133
+ std::list<zb_device_params_t *> boundSensors = zbThermostat.getBoundDevices ();
134
+ for (const auto &device : boundSensors) {
135
+ Serial.println (" --------------------------------" );
136
+ if (device->short_addr == 0x0000 || device->short_addr == 0xFFFF ) { // End devices never have 0x0000 short address or 0xFFFF group address
137
+ Serial.printf (
138
+ " Device on endpoint %d, IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n " , device->endpoint , device->ieee_addr [7 ], device->ieee_addr [6 ],
139
+ device->ieee_addr [5 ], device->ieee_addr [4 ], device->ieee_addr [3 ], device->ieee_addr [2 ], device->ieee_addr [1 ], device->ieee_addr [0 ]
140
+ );
141
+ zbThermostat.getSensorSettings (device->endpoint , device->ieee_addr );
142
+ } else {
143
+ Serial.printf (" Device on endpoint %d, short address: 0x%x\r\n " , device->endpoint , device->short_addr );
144
+ zbThermostat.getSensorSettings (device->endpoint , device->short_addr );
145
+ }
146
+ }
112
147
}
113
148
114
149
void loop () {
115
150
// Handle button switch in loop()
116
151
if (digitalRead (button) == LOW) { // Push button pressed
117
-
118
152
// Key debounce handling
119
153
while (digitalRead (button) == LOW) {
120
154
delay (50 );
121
155
}
122
-
123
156
// Set reporting interval for temperature sensor
124
157
zbThermostat.setTemperatureReporting (0 , 10 , 2 );
125
158
}
@@ -130,5 +163,6 @@ void loop() {
130
163
last_print = millis ();
131
164
int temp_percent = (int )((sensor_temp - sensor_min_temp) / (sensor_max_temp - sensor_min_temp) * 100 );
132
165
Serial.printf (" Loop temperature info: %.2f°C (%d %%)\n " , sensor_temp, temp_percent);
166
+ zbThermostat.printBoundDevices (Serial);
133
167
}
134
168
}
0 commit comments