@@ -243,6 +243,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
243243 } else {
244244 Zigbee._connected = true ;
245245 }
246+ Zigbee.searchBindings ();
246247 }
247248 } else {
248249 /* commissioning failed */
@@ -309,8 +310,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
309310 Bit 6 – Security capability
310311 Bit 7 – Reserved
311312 */
312-
313- // for each endpoint in the list call the findEndpoint function if not bounded or allowed to bind multiple devices
313+ // for each endpoint in the list call the findEndpoint function if not bounded or allowed to bind multiple devices
314314 for (std::list<ZigbeeEP *>::iterator it = Zigbee.ep_objects .begin (); it != Zigbee.ep_objects .end (); ++it) {
315315 if (!(*it)->bound () || (*it)->epAllowMultipleBinding ()) {
316316 (*it)->findEndpoint (&cmd_req);
@@ -391,6 +391,72 @@ void ZigbeeCore::scanDelete() {
391391 _scan_status = ZB_SCAN_FAILED;
392392}
393393
394+ // Recall bounded devices from the binding table after reboot
395+ void ZigbeeCore::bindingTableCb (const esp_zb_zdo_binding_table_info_t *table_info, void *user_ctx)
396+ {
397+ bool done = true ;
398+ esp_zb_zdo_mgmt_bind_param_t *req = (esp_zb_zdo_mgmt_bind_param_t *)user_ctx;
399+ esp_zb_zdp_status_t zdo_status = (esp_zb_zdp_status_t )table_info->status ;
400+ log_d (" Binding table callback for address 0x%04x with status %d" , req->dst_addr , zdo_status);
401+ if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
402+ // Print binding table log simple
403+ log_d (" Binding table info: total %d, index %d, count %d" , table_info->total , table_info->index , table_info->count );
404+
405+ if (table_info->total == 0 ) {
406+ log_d (" No binding table entries found" );
407+ free (req);
408+ return ;
409+ }
410+
411+ // Create a new device object and fill it with the binding table info
412+ zb_device_params_t *device = (zb_device_params_t *)malloc (sizeof (zb_device_params_t ));
413+ device->endpoint = table_info->record ->dst_endp ;
414+
415+ // log all tableinfo record
416+ log_d (" Binding table record: src_endp %d, dst_endp %d, cluster_id 0x%04x, dst_addr_mode %d" , table_info->record ->src_endp , table_info->record ->dst_endp , table_info->record ->cluster_id , table_info->record ->dst_addr_mode );
417+ log_d (" Short address: 0x%04x" , table_info->record ->dst_address .addr_short );
418+ log_d (" ieee_address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" , table_info->record ->dst_address .addr_long [7 ], table_info->record ->dst_address .addr_long [6 ], table_info->record ->dst_address .addr_long [5 ], table_info->record ->dst_address .addr_long [4 ], table_info->record ->dst_address .addr_long [3 ], table_info->record ->dst_address .addr_long [2 ], table_info->record ->dst_address .addr_long [1 ], table_info->record ->dst_address .addr_long [0 ]);
419+
420+ if (table_info->record ->dst_addr_mode == ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT ) {
421+ device->short_addr = table_info->record ->dst_address .addr_short ;
422+ } else { // ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT
423+ memcpy (device->ieee_addr , table_info->record ->dst_address .addr_long , sizeof (esp_zb_ieee_addr_t ));
424+ }
425+
426+ log_d (" Bound device: endpoint %d, short address 0x%04x to endpoint %d" , table_info->record ->dst_endp , table_info->record ->dst_address .addr_short , table_info->record ->src_endp );
427+
428+ // Add to list of bound devices of proper endpoint
429+ for (std::list<ZigbeeEP *>::iterator it = Zigbee.ep_objects .begin (); it != Zigbee.ep_objects .end (); ++it) {
430+ if ((*it)->getEndpoint () == table_info->record ->src_endp ) {
431+ (*it)->addBoundDevice (device);
432+ }
433+ }
434+
435+ // Continue reading the binding table
436+ if (table_info->index + table_info->count < table_info->total ) {
437+ /* There are unreported binding table entries, request for them. */
438+ req->start_index = table_info->index + table_info->count ;
439+ esp_zb_zdo_binding_table_req (req, bindingTableCb, req);
440+ done = false ;
441+ }
442+ }
443+
444+ if (done) {
445+ // Print bound devices
446+ log_d (" Filling bounded devices finished" );
447+ free (req);
448+ }
449+ }
450+
451+
452+ void ZigbeeCore::searchBindings (){
453+ esp_zb_zdo_mgmt_bind_param_t *mb_req = (esp_zb_zdo_mgmt_bind_param_t *)malloc (sizeof (esp_zb_zdo_mgmt_bind_param_t ));
454+ mb_req->dst_addr = esp_zb_get_short_address ();
455+ mb_req->start_index = 0 ;
456+ log_d (" Requesting binding table for address 0x%04x" , mb_req->dst_addr );
457+ esp_zb_zdo_binding_table_req (mb_req, bindingTableCb, (void *)mb_req);
458+ }
459+
394460// Function to convert enum value to string
395461const char *ZigbeeCore::getDeviceTypeString (esp_zb_ha_standard_devices_t deviceId) {
396462 switch (deviceId) {
0 commit comments