@@ -50,17 +50,18 @@ void ZigbeeSwitch::findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t
50
50
51
51
// find on_off light endpoint
52
52
void ZigbeeSwitch::findEndpoint (esp_zb_zdo_match_desc_req_param_t *cmd_req) {
53
- uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF};
54
- esp_zb_zdo_match_desc_req_param_t on_off_req = {
55
- .dst_nwk_addr = cmd_req->dst_nwk_addr ,
56
- .addr_of_interest = cmd_req->addr_of_interest ,
57
- .profile_id = ESP_ZB_AF_HA_PROFILE_ID,
58
- .num_in_clusters = 1 ,
59
- .num_out_clusters = 1 ,
60
- .cluster_list = cluster_list,
61
- };
62
-
63
- esp_zb_zdo_match_cluster (&on_off_req, findCb, &_endpoint);
53
+ if (!_is_bound || _allow_multiple_binding){
54
+ uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF};
55
+ esp_zb_zdo_match_desc_req_param_t on_off_req = {
56
+ .dst_nwk_addr = cmd_req->dst_nwk_addr ,
57
+ .addr_of_interest = cmd_req->addr_of_interest ,
58
+ .profile_id = ESP_ZB_AF_HA_PROFILE_ID,
59
+ .num_in_clusters = 1 ,
60
+ .num_out_clusters = 1 ,
61
+ .cluster_list = cluster_list,
62
+ };
63
+ esp_zb_zdo_match_cluster (&on_off_req, findCb, &_endpoint);
64
+ }
64
65
}
65
66
66
67
// Methods to control the light
@@ -70,7 +71,7 @@ void ZigbeeSwitch::lightToggle() {
70
71
cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
71
72
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
72
73
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID;
73
- log_i (" Sending 'light toggle' command" );
74
+ log_v (" Sending 'light toggle' command" );
74
75
esp_zb_zcl_on_off_cmd_req (&cmd_req);
75
76
} else {
76
77
log_e (" Light not bound" );
@@ -84,7 +85,7 @@ void ZigbeeSwitch::lightToggle(uint16_t group_addr) {
84
85
cmd_req.zcl_basic_cmd .dst_addr_u .addr_short = group_addr;
85
86
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT;
86
87
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID;
87
- log_i (" Sending 'light toggle' command to group address 0x%x" , group_addr);
88
+ log_v (" Sending 'light toggle' command to group address 0x%x" , group_addr);
88
89
esp_zb_zcl_on_off_cmd_req (&cmd_req);
89
90
} else {
90
91
log_e (" Light not bound" );
@@ -99,7 +100,23 @@ void ZigbeeSwitch::lightToggle(uint8_t endpoint, uint16_t short_addr) {
99
100
cmd_req.zcl_basic_cmd .dst_addr_u .addr_short = short_addr;
100
101
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT;
101
102
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID;
102
- log_i (" Sending 'light toggle' command to endpoint %d, address 0x%x" , endpoint, short_addr);
103
+ log_v (" Sending 'light toggle' command to endpoint %d, address 0x%x" , endpoint, short_addr);
104
+ esp_zb_zcl_on_off_cmd_req (&cmd_req);
105
+ } else {
106
+ log_e (" Light not bound" );
107
+ }
108
+ }
109
+
110
+ void ZigbeeSwitch::lightToggle (uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) {
111
+ if (_is_bound) {
112
+ esp_zb_zcl_on_off_cmd_t cmd_req;
113
+ cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
114
+ cmd_req.zcl_basic_cmd .dst_endpoint = endpoint;
115
+ cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT;
116
+ cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID;
117
+ memcpy (cmd_req.zcl_basic_cmd .dst_addr_u .addr_long , ieee_addr, sizeof (esp_zb_ieee_addr_t ));
118
+ log_v (" Sending 'light toggle' command to endpoint %d, ieee address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" ,
119
+ endpoint, ieee_addr[7 ], ieee_addr[6 ], ieee_addr[5 ], ieee_addr[4 ], ieee_addr[3 ], ieee_addr[2 ], ieee_addr[1 ], ieee_addr[0 ]);
103
120
esp_zb_zcl_on_off_cmd_req (&cmd_req);
104
121
} else {
105
122
log_e (" Light not bound" );
@@ -112,7 +129,7 @@ void ZigbeeSwitch::lightOn() {
112
129
cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
113
130
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
114
131
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_ON_ID;
115
- log_i (" Sending 'light on' command" );
132
+ log_v (" Sending 'light on' command" );
116
133
esp_zb_zcl_on_off_cmd_req (&cmd_req);
117
134
} else {
118
135
log_e (" Light not bound" );
@@ -126,7 +143,7 @@ void ZigbeeSwitch::lightOn(uint16_t group_addr) {
126
143
cmd_req.zcl_basic_cmd .dst_addr_u .addr_short = group_addr;
127
144
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT;
128
145
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_ON_ID;
129
- log_i (" Sending 'light on' command to group address 0x%x" , group_addr);
146
+ log_v (" Sending 'light on' command to group address 0x%x" , group_addr);
130
147
esp_zb_zcl_on_off_cmd_req (&cmd_req);
131
148
} else {
132
149
log_e (" Light not bound" );
@@ -141,7 +158,23 @@ void ZigbeeSwitch::lightOn(uint8_t endpoint, uint16_t short_addr) {
141
158
cmd_req.zcl_basic_cmd .dst_addr_u .addr_short = short_addr;
142
159
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT;
143
160
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_ON_ID;
144
- log_i (" Sending 'light on' command to endpoint %d, address 0x%x" , endpoint, short_addr);
161
+ log_v (" Sending 'light on' command to endpoint %d, address 0x%x" , endpoint, short_addr);
162
+ esp_zb_zcl_on_off_cmd_req (&cmd_req);
163
+ } else {
164
+ log_e (" Light not bound" );
165
+ }
166
+ }
167
+
168
+ void ZigbeeSwitch::lightOn (uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) {
169
+ if (_is_bound) {
170
+ esp_zb_zcl_on_off_cmd_t cmd_req;
171
+ cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
172
+ cmd_req.zcl_basic_cmd .dst_endpoint = endpoint;
173
+ cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT;
174
+ cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_ON_ID;
175
+ memcpy (cmd_req.zcl_basic_cmd .dst_addr_u .addr_long , ieee_addr, sizeof (esp_zb_ieee_addr_t ));
176
+ log_v (" Sending 'light on' command to endpoint %d, ieee address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" ,
177
+ endpoint, ieee_addr[7 ], ieee_addr[6 ], ieee_addr[5 ], ieee_addr[4 ], ieee_addr[3 ], ieee_addr[2 ], ieee_addr[1 ], ieee_addr[0 ]);
145
178
esp_zb_zcl_on_off_cmd_req (&cmd_req);
146
179
} else {
147
180
log_e (" Light not bound" );
@@ -154,7 +187,7 @@ void ZigbeeSwitch::lightOff() {
154
187
cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
155
188
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
156
189
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID;
157
- log_i (" Sending 'light off' command" );
190
+ log_v (" Sending 'light off' command" );
158
191
esp_zb_zcl_on_off_cmd_req (&cmd_req);
159
192
} else {
160
193
log_e (" Light not bound" );
@@ -168,7 +201,7 @@ void ZigbeeSwitch::lightOff(uint16_t group_addr) {
168
201
cmd_req.zcl_basic_cmd .dst_addr_u .addr_short = group_addr;
169
202
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT;
170
203
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID;
171
- log_i (" Sending 'light off' command to group address 0x%x" , group_addr);
204
+ log_v (" Sending 'light off' command to group address 0x%x" , group_addr);
172
205
esp_zb_zcl_on_off_cmd_req (&cmd_req);
173
206
} else {
174
207
log_e (" Light not bound" );
@@ -183,7 +216,23 @@ void ZigbeeSwitch::lightOff(uint8_t endpoint, uint16_t short_addr) {
183
216
cmd_req.zcl_basic_cmd .dst_addr_u .addr_short = short_addr;
184
217
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT;
185
218
cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID;
186
- log_i (" Sending 'light off' command to endpoint %d, address 0x%x" , endpoint, short_addr);
219
+ log_v (" Sending 'light off' command to endpoint %d, address 0x%x" , endpoint, short_addr);
220
+ esp_zb_zcl_on_off_cmd_req (&cmd_req);
221
+ } else {
222
+ log_e (" Light not bound" );
223
+ }
224
+ }
225
+
226
+ void ZigbeeSwitch::lightOff (uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) {
227
+ if (_is_bound) {
228
+ esp_zb_zcl_on_off_cmd_t cmd_req;
229
+ cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
230
+ cmd_req.zcl_basic_cmd .dst_endpoint = endpoint;
231
+ cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT;
232
+ cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID;
233
+ memcpy (cmd_req.zcl_basic_cmd .dst_addr_u .addr_long , ieee_addr, sizeof (esp_zb_ieee_addr_t ));
234
+ log_v (" Sending 'light off' command to endpoint %d, ieee address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" ,
235
+ endpoint, ieee_addr[7 ], ieee_addr[6 ], ieee_addr[5 ], ieee_addr[4 ], ieee_addr[3 ], ieee_addr[2 ], ieee_addr[1 ], ieee_addr[0 ]);
187
236
esp_zb_zcl_on_off_cmd_req (&cmd_req);
188
237
} else {
189
238
log_e (" Light not bound" );
@@ -197,7 +246,7 @@ void ZigbeeSwitch::lightOffWithEffect(uint8_t effect_id, uint8_t effect_variant)
197
246
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
198
247
cmd_req.effect_id = effect_id;
199
248
cmd_req.effect_variant = effect_variant;
200
- log_i (" Sending 'light off with effect' command" );
249
+ log_v (" Sending 'light off with effect' command" );
201
250
esp_zb_zcl_on_off_off_with_effect_cmd_req (&cmd_req);
202
251
} else {
203
252
log_e (" Light not bound" );
@@ -209,7 +258,7 @@ void ZigbeeSwitch::lightOnWithSceneRecall() {
209
258
esp_zb_zcl_on_off_on_with_recall_global_scene_cmd_t cmd_req;
210
259
cmd_req.zcl_basic_cmd .src_endpoint = _endpoint;
211
260
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
212
- log_i (" Sending 'light on with scene recall' command" );
261
+ log_v (" Sending 'light on with scene recall' command" );
213
262
esp_zb_zcl_on_off_on_with_recall_global_scene_cmd_req (&cmd_req);
214
263
} else {
215
264
log_e (" Light not bound" );
@@ -223,7 +272,7 @@ void ZigbeeSwitch::lightOnWithTimedOff(uint8_t on_off_control, uint16_t time_on,
223
272
cmd_req.on_off_control = on_off_control; // TODO: Test how it works, then maybe change API
224
273
cmd_req.on_time = time_on;
225
274
cmd_req.off_wait_time = time_off;
226
- log_i (" Sending 'light on with time off' command" );
275
+ log_v (" Sending 'light on with time off' command" );
227
276
esp_zb_zcl_on_off_on_with_timed_off_cmd_req (&cmd_req);
228
277
} else {
229
278
log_e (" Light not bound" );
0 commit comments