espressif / esp-zigbee-sdk

Espressif Zigbee SDK
Apache License 2.0
178 stars 31 forks source link

Bind switch to coordinator bind error - how to debug? (TZ-1134) #428

Closed mw75 closed 2 months ago

mw75 commented 2 months ago

Question

I'm implementing a Zigbee to Can-Bus bridge. Can-bus to Power-Plug is working by a modified Zigbee_Light_Switch example.

Now i try to get actions/attribute updates from a switch/remote. I can read the cluster list from the simple description, but when i try to bind the on-Off-cluster to the coordinator i just get an error in the bind callback.

How to debug what's wrong?

I have registered an action handler and expect calls when the switch button is pressed. Is this a valid assumption?

Additional context.

static void simple_desc_cb(esp_zb_zdp_status_t zdo_status, esp_zb_af_simple_desc_1_1_t *simple_desc, void *user_ctx)
{
    log_i("simple_desc_cb called: %s",esp_err_to_name(zdo_status ) );
    uint16_t *dev = (uint16_t*)(user_ctx);
    if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
        log_i("Simple desc response: status(%s), device_id(%d), app_version(%d), profile_id(0x%x), endpoint_ID(%d)",
            esp_err_to_name(zdo_status),
            simple_desc->app_device_id,
            simple_desc->app_device_version,
            simple_desc->app_profile_id,
            simple_desc->endpoint
        );
        log_i("Cluster ID list:");
        for (int i = simple_desc->app_input_cluster_count; i < (simple_desc->app_input_cluster_count + simple_desc->app_output_cluster_count); i++) {
            log_i("0x%x",*(simple_desc->app_cluster_list + i));
            if(*(simple_desc->app_cluster_list + i)==ESP_ZB_ZCL_CLUSTER_ID_ON_OFF){
              esp_zb_zdo_bind_req_param_t bind_req;
              bind_req.src_endp = simple_desc->endpoint;
              bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF;
              bind_req.dst_addr_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT;
              esp_zb_get_long_address(bind_req.dst_address_u.addr_long);
              bind_req.dst_endp = HA_ONOFF_SWITCH_ENDPOINT;
              bind_req.req_dst_addr = esp_zb_get_short_address();
              log_i("Try to bind On/Off");
              esp_zb_zdo_device_bind_req(&bind_req, bind_cb, user_ctx);
            }
        }
    }
}
static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx) {
  log_i("bind_cb called: %s",esp_err_to_name(zdo_status ) );
  if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
    log_i("Bound successfully!");
    if (user_ctx) {
      zb_device_params_t *dev = (zb_device_params_t *)user_ctx;
      log_i("The device originating from address(0x%x) on endpoint(%d)", dev->short_addr, dev->endpoint);
      free(dev);
    }
  }
}

[ 7854][I][Zigbee_Light_Switch.ino:157] simple_desc_cb(): simple_desc_cb called: ESP_OK [ 7854][I][Zigbee_Light_Switch.ino:160] simple_desc_cb(): Simple desc response: status(ESP_OK), device_id(2080), app_version(1), profile_id(0x104), endpoint_ID(1) [ 7855][I][Zigbee_Light_Switch.ino:167] simple_desc_cb(): Cluster ID list: [ 7856][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x3 [ 7856][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x4 [ 7856][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x5 [ 7857][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x6 [ 7857][I][Zigbee_Light_Switch.ino:178] simple_desc_cb(): Try to bind On/Off [ 7857][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x8 [ 7858][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x19 [ 7858][I][Zigbee_Light_Switch.ino:169] simple_desc_cb(): 0x1000 [ 7859][I][Zigbee_Light_Switch.ino:113] bind_cb(): bind_cb called: ERROR

lpy4105 commented 2 months ago

You can print out the value of zdo_status and check the defination of esp_zb_zdp_status_t to identify the reason for the zdo request failure.

Going over the code you provided, I'm suspecting that you populated a wrong request destionation address.

bind_req.req_dst_addr = esp_zb_get_short_address();

I believe it should be the peer address you want the request to be sent to.