3
3
#include " Zigbee_handlers.cpp"
4
4
#include " Arduino.h"
5
5
6
+
6
7
Zigbee_Core::Zigbee_Core () {
7
8
_radio_config = ZIGBEE_DEFAULT_RADIO_CONFIG ();
8
9
_host_config = ZIGBEE_DEFAULT_HOST_CONFIG ();
@@ -254,9 +255,9 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
254
255
255
256
// TODO: Save the device short address and endpoint to the list ????????
256
257
257
- // for each endpoint in the list call the find_endpoint function if not bounded
258
+ // for each endpoint in the list call the find_endpoint function if not bounded or allowed to bind multiple devices
258
259
for (std::list<Zigbee_EP*>::iterator it = Zigbee.ep_objects .begin (); it != Zigbee.ep_objects .end (); ++it) {
259
- if (!(*it)->_is_bound ) {
260
+ if (!(*it)->_is_bound || (*it)-> _allow_multiple_binding ) {
260
261
(*it)->find_endpoint (&cmd_req);
261
262
}
262
263
}
@@ -277,87 +278,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
277
278
}
278
279
}
279
280
280
- // // Zigbee action handlers
281
- // static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) {
282
- // esp_err_t ret = ESP_OK;
283
- // /* TODO:
284
- // Implement handlers for different Zigbee actions (callback_id's)
285
- // */
286
- // // NOTE: Implement all Zigbee actions that can be handled by the Zigbee_Core class, or just call user defined callback function and let the user handle the action and read the message properly
287
- // // NOTE: This may me harder for users, to know what callback_id's are available and what message type is received
288
- // switch (callback_id) {
289
- // case ESP_ZB_CORE_SET_ATTR_VALUE_CB_ID: ret = zb_attribute_set_handler((esp_zb_zcl_set_attr_value_message_t *)message); break;
290
- // case ESP_ZB_CORE_REPORT_ATTR_CB_ID: ret = zb_attribute_reporting_handler((esp_zb_zcl_report_attr_message_t *)message); break;
291
- // case ESP_ZB_CORE_CMD_READ_ATTR_RESP_CB_ID: ret = zb_read_attr_resp_handler((esp_zb_zcl_cmd_read_attr_resp_message_t *)message); break;
292
- // case ESP_ZB_CORE_CMD_REPORT_CONFIG_RESP_CB_ID: ret = zb_configure_report_resp_handler((esp_zb_zcl_cmd_config_report_resp_message_t *)message); break;
293
- // case ESP_ZB_CORE_CMD_DEFAULT_RESP_CB_ID: log_i("Received default response"); break;
294
- // default: log_w("Receive unhandled Zigbee action(0x%x) callback", callback_id); break;
295
- // }
296
-
297
- // //TODO: get destination endpoint from the message:
298
- // uint8_t dst_endpoint = ((esp_zb_zcl_set_attr_value_message_t *)message)->info.dst_endpoint;
299
-
300
-
301
-
302
- // return ret;
303
- // }
304
-
305
- // static esp_err_t zb_attribute_set_handler(const esp_zb_zcl_set_attr_value_message_t *message) {
306
- // if (!message) {
307
- // log_e("Empty message");
308
- // }
309
- // if (message->info.status != ESP_ZB_ZCL_STATUS_SUCCESS) {
310
- // log_e("Received message: error status(%d)", message->info.status);
311
- // }
312
-
313
- // log_i(
314
- // "Received message: endpoint(%d), cluster(0x%x), attribute(0x%x), data size(%d)", message->info.dst_endpoint, message->info.cluster, message->attribute.id,
315
- // message->attribute.data.size
316
- // );
317
-
318
- // // List through all Zigbee EPs and call the callback function, with the message
319
- // for (std::list<Zigbee_EP*>::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) {
320
- // if (message->info.dst_endpoint == (*it)->_endpoint) {
321
- // //TODO: implement argument passing to the callback function
322
- // //if Zigbee_EP argument is set, pass it to the callback function
323
- // // if ((*it)->_arg) {
324
- // // (*it)->_cb(message, (*it)->_arg);
325
- // // }
326
- // // else {
327
- // (*it)->_cb(message); //method zb_attribute_set_handler in the LIGHT EP
328
- // // }
329
- // }
330
- // }
331
- // return ESP_OK;
332
- // }
333
-
334
- // static esp_err_t zb_attribute_reporting_handler(const esp_zb_zcl_report_attr_message_t *message) {
335
- // if (!message) {
336
- // log_e("Empty message");
337
- // }
338
- // if (message->status != ESP_ZB_ZCL_STATUS_SUCCESS) {
339
- // log_e("Received message: error status(%d)", message->status);
340
- // }
341
- // log_i(
342
- // "Received report from address(0x%x) src endpoint(%d) to dst endpoint(%d) cluster(0x%x)", message->src_address.u.short_addr, message->src_endpoint,
343
- // message->dst_endpoint, message->cluster
344
- // );
345
- // // List through all Zigbee EPs and call the callback function, with the message
346
- // for (std::list<Zigbee_EP*>::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) {
347
- // if (message->info.dst_endpoint == (*it)->_endpoint) {
348
- // //TODO: implement argument passing to the callback function
349
- // //if Zigbee_EP argument is set, pass it to the callback function
350
- // // if ((*it)->_arg) {
351
- // // (*it)->_cb(message, (*it)->_arg);
352
- // // }
353
- // // else {
354
- // (*it)->_cb(message);
355
- // // }
356
- // }
357
- // }
358
- // return ESP_OK;
359
- // }
360
-
281
+ void Zigbee_Core::factoryReset () {
282
+ log_v (" Factory reseting Zigbee stack, device will reboot" );
283
+ esp_zb_factory_reset ();
284
+ }
361
285
362
286
363
287
// TODO: Implement scanning network
@@ -394,4 +318,48 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
394
318
// esp_host_zb_output(ESP_ZNSP_ZDO_BIND_SET, &zdo_data, sizeof(esp_zb_zdo_bind_req_t), &output, &outlen);
395
319
// }
396
320
321
+ // Function to convert enum value to string
322
+ const char * Zigbee_Core::getDeviceTypeString (esp_zb_ha_standard_devices_t deviceId) {
323
+ switch (deviceId) {
324
+ case ESP_ZB_HA_ON_OFF_SWITCH_DEVICE_ID: return " General On/Off switch" ;
325
+ case ESP_ZB_HA_LEVEL_CONTROL_SWITCH_DEVICE_ID: return " Level Control Switch" ;
326
+ case ESP_ZB_HA_ON_OFF_OUTPUT_DEVICE_ID: return " General On/Off output" ;
327
+ case ESP_ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_DEVICE_ID: return " Level Controllable Output" ;
328
+ case ESP_ZB_HA_SCENE_SELECTOR_DEVICE_ID: return " Scene Selector" ;
329
+ case ESP_ZB_HA_CONFIGURATION_TOOL_DEVICE_ID: return " Configuration Tool" ;
330
+ case ESP_ZB_HA_REMOTE_CONTROL_DEVICE_ID: return " Remote Control" ;
331
+ case ESP_ZB_HA_COMBINED_INTERFACE_DEVICE_ID: return " Combined Interface" ;
332
+ case ESP_ZB_HA_RANGE_EXTENDER_DEVICE_ID: return " Range Extender" ;
333
+ case ESP_ZB_HA_MAINS_POWER_OUTLET_DEVICE_ID: return " Mains Power Outlet" ;
334
+ case ESP_ZB_HA_DOOR_LOCK_DEVICE_ID: return " Door lock client" ;
335
+ case ESP_ZB_HA_DOOR_LOCK_CONTROLLER_DEVICE_ID: return " Door lock controller" ;
336
+ case ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID: return " Simple Sensor device" ;
337
+ case ESP_ZB_HA_CONSUMPTION_AWARENESS_DEVICE_ID: return " Consumption Awareness Device" ;
338
+ case ESP_ZB_HA_HOME_GATEWAY_DEVICE_ID: return " Home Gateway" ;
339
+ case ESP_ZB_HA_SMART_PLUG_DEVICE_ID: return " Smart plug" ;
340
+ case ESP_ZB_HA_WHITE_GOODS_DEVICE_ID: return " White Goods" ;
341
+ case ESP_ZB_HA_METER_INTERFACE_DEVICE_ID: return " Meter Interface" ;
342
+ case ESP_ZB_HA_ON_OFF_LIGHT_DEVICE_ID: return " On/Off Light Device" ;
343
+ case ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID: return " Dimmable Light Device" ;
344
+ case ESP_ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID: return " Color Dimmable Light Device" ;
345
+ case ESP_ZB_HA_DIMMER_SWITCH_DEVICE_ID: return " Dimmer Switch Device" ;
346
+ case ESP_ZB_HA_COLOR_DIMMER_SWITCH_DEVICE_ID: return " Color Dimmer Switch Device" ;
347
+ case ESP_ZB_HA_SHADE_DEVICE_ID: return " Shade" ;
348
+ case ESP_ZB_HA_SHADE_CONTROLLER_DEVICE_ID: return " Shade controller" ;
349
+ case ESP_ZB_HA_WINDOW_COVERING_DEVICE_ID: return " Window Covering client" ;
350
+ case ESP_ZB_HA_WINDOW_COVERING_CONTROLLER_DEVICE_ID: return " Window Covering controller" ;
351
+ case ESP_ZB_HA_HEATING_COOLING_UNIT_DEVICE_ID: return " Heating/Cooling Unit device" ;
352
+ case ESP_ZB_HA_THERMOSTAT_DEVICE_ID: return " Thermostat Device" ;
353
+ case ESP_ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID: return " Temperature Sensor" ;
354
+ case ESP_ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_ID: return " IAS Control and Indicating Equipment" ;
355
+ case ESP_ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_ID: return " IAS Ancillary Control Equipment" ;
356
+ case ESP_ZB_HA_IAS_ZONE_ID: return " IAS Zone" ;
357
+ case ESP_ZB_HA_IAS_WARNING_DEVICE_ID: return " IAS Warning Device" ;
358
+ case ESP_ZB_HA_TEST_DEVICE_ID: return " Custom HA device for test" ;
359
+ case ESP_ZB_HA_CUSTOM_TUNNEL_DEVICE_ID: return " Custom Tunnel device" ;
360
+ case ESP_ZB_HA_CUSTOM_ATTR_DEVICE_ID: return " Custom Attributes Device" ;
361
+ default : return " Unknown device type" ;
362
+ }
363
+ }
364
+
397
365
Zigbee_Core Zigbee = Zigbee_Core();
0 commit comments