Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32C6 coordinator: Unable to receive attribute reports from devices (TZ-165) #42

Closed
pieterjanbuntinx opened this issue Jun 29, 2023 · 24 comments

Comments

@pieterjanbuntinx
Copy link

Hi

I am developing a custom Zigbee gateway with an ESP32S3 as the main microcontroller and an ESP32C6 as the RCP. Currently, I am trying to receive attribute reports from some temperature/humidity sensors (Sonoff SNZB-02). I am using the esp_zigbee_gateway example (master & esp-idf v5.1rc2) with a few additions:

static void esp_zb_task(void *pvParameters) {
  /* initialize Zigbee stack with Zigbee coordinator config */
  esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG();
  esp_zb_init(&zb_nwk_cfg);
  esp_zb_device_add_report_attr_cb(esp_zb_dev_reporting_cb);
  /* initiate Zigbee Stack start without zb_send_no_autostart_signal auto-start
  
  // .....
}
static void esp_zb_dev_reporting_cb(esp_zb_zcl_addr_t *addr, uint8_t endpoint,
                                    uint16_t cluster_id, uint16_t attr_id,
                                    esp_zb_zcl_attr_type_t attr_type,
                                    void *value) {
  ESP_LOGI(TAG,
           "Switch got report attribute from "
           "address:0x%x,cluster_id:0x%x,attr_id:0x%x,value:%d,attr_type:0x%x,",
           addr->u.short_addr, cluster_id, attr_id, *(uint8_t *)value,
           attr_type);
}

But the callback esp_zb_dev_reporting_cb never seems to be called. When using Zigbee2MQTT I can see the received "attributeReport" message about every 10 minutes or when the temperature/humidity changes.

Am I doing something wrong or is this something that does not work yet in the SDK?

For some door/window sensors, I have a similar issue. How can I have a callback when there is a "statusChangeNotification"?

@github-actions github-actions bot changed the title ESP32C6 coordinator: Unable to receive attribute reports from devices ESP32C6 coordinator: Unable to receive attribute reports from devices (TZ-165) Jun 29, 2023
@abdulrehmanee12
Copy link
Contributor

abdulrehmanee12 commented Jun 30, 2023

hi @pieterjanbuntinx Your implemented callback for receiving attribute reports is missing the dst_endpoint information. We recently modified this callback based on a customer's request to include dst_endpoint in the esp_zb_dev_reporting_cb function. Additionally, we have implemented the report callback in esp_zigbee_customized_devices example esp_HA_customized_switch . You can refer to it for guidance and please make sure to add 'dst_endpoint' and try again.

`static void esp_zb_dev_reporting_cb(esp_zb_zcl_addr_t *addr, uint8_t src_endpoint, uint8_t dst_endpoint, uint16_t cluster_id,
uint16_t attr_id, esp_zb_zcl_attr_type_t attr_type, void *value)

{
ESP_LOGI(TAG, "Switch got report attribute from address:0x%x,src_ep:%d,dst_ep:%d,cluster_id:0x%x,attr_id:0x%x,value:%d,attr_type:0x%x,", addr->u.short_addr, src_endpoint, dst_endpoint, cluster_id,
attr_id, *(uint8_t *)value, attr_type);
}`

@pieterjanbuntinx
Copy link
Author

Hi @abdulrehmanee12,
Thank you for your response!

Sadly changing the callback function did not solve my issue. Otherwise, with the wrong callback, I would have expected the ESP to crash every time that callback was called.

The esp_HA_customized_switch example is where I found the original callback. I must have copied it from an earlier version of the SDK.

In that example, they bind the two devices. Is that necessary for reporting to work? I wanted to try and bind the devices but I was not able to create a find temp/humid sensor or find door sensor function as there exists in the example for the on_off_light (esp_zb_zdo_find_on_off_light). I was thinking of using the ZBOSS function zb_uint8_t zb_zdo_match_desc_req(zb_uint8_t param, zb_callback_t cb); directly. But I am not sure where I can get the zb_uint8_t param argument from (ZBOSS stack pointer I think?). Is there perhaps an example of how to do this?

@abdulrehmanee12
Copy link
Contributor

abdulrehmanee12 commented Jul 3, 2023

@pieterjanbuntinx Yes, binding two devices is necessary for reporting to function correctly. At present, our SDK does not support the "find temp/humid sensor" or "find door sensor" functions. However, in our next release, we will introduce a common function that caters to those requirements. As an example for your work, here is a guide on how to achieve it:

`void esp_zb_zdo_find_door_lock(esp_zb_zdo_match_desc_req_param_t *cmd_req, esp_zb_zdo_match_desc_callback_t user_cb, void *user_ctx)

{
zb_uint8_t bufid = zb_buf_get_out();
zb_uint8_t zdo_tsn = 0;
zb_zdo_match_desc_param_t req;
// 1 is total number of the cluster list
req = zb_buf_initial_alloc(bufid, sizeof(zb_zdo_match_desc_param_t) + (1) * sizeof(zb_uint16_t));
req->nwk_addr = cmd_req->dst_nwk_addr;
req->addr_of_interest = cmd_req->addr_of_interest;
req->profile_id = ZB_AF_HA_PROFILE_ID;
/
searching for temp_sensor */
req->num_in_clusters = 1;
req->num_out_clusters = 0;
req->cluster_list[0] = ZB_ZCL_CLUSTER_ID_DOOR_LOCK;
zdo_tsn = zb_zdo_match_desc_req(bufid, find_device_cb);
ZB_SCHEDULE_APP_ALARM(match_desc_req_device_timeout, zdo_tsn, ESP_ZB_MATCH_DESC_REQ_TIMEOUT);
esp_zb_zdo_callback_register(zdo_tsn, ESP_ZDO_MATCH_DESC_REQ_CLID, (void *)user_cb, user_ctx);

}`

@pieterjanbuntinx
Copy link
Author

Great thanks! I will try this out now.
Do you have any idea how I can receive statusChangeNotifications from an IAS zone like for example a door lock? I don't think this is implemented yet in the SDK. Do you know of a function in the ZBOSS lib?

@abdulrehmanee12
Copy link
Contributor

The IAS zone cluster has already been implemented in our SDK. To receive statusChangeNotifications you can utilize the IAS zone status change notification command esp_zb_zcl_ias_zone_status_change_notif_cmd_req

@pieterjanbuntinx
Copy link
Author

The IAS zone cluster has already been implemented in our SDK. To receive statusChangeNotifications you can utilize the IAS zone status change notification command esp_zb_zcl_ias_zone_status_change_notif_cmd_req

Correct me if I am wrong, but is this function not only for sending the status notifications? I need a function similar to esp_zb_device_add_report_attr_cb that calls the provided callback when such a command is received.

@pieterjanbuntinx Yes, binding two devices is necessary for reporting to function correctly. At present, our SDK does not support the "find temp/humid sensor" or "find door sensor" functions. However, in our next release, we will introduce a common function that caters to those requirements. As an example for your work, here is a guide on how to achieve it:
(...)

I was able to get most of it working. I now have the following code:

void find_temp_humid_sensor(zb_bufid_t bufid) {
    /*Get the beginning of the response.*/
    zb_zdo_match_desc_resp_t* resp = (zb_zdo_match_desc_resp_t*)zb_buf_begin(bufid);
    /* Get the pointer to the parameters buffer, which stores APS layer
     * response.
     */
    zb_apsde_data_indication_t* ind = ZB_BUF_GET_PARAM(bufid, zb_apsde_data_indication_t);
    zb_uint8_t*                 match_ep;

    if (resp->status == ZB_ZDP_STATUS_SUCCESS) {
        /* Match EP list follows right after response header. */
        match_ep = (zb_uint8_t*)(resp + 1);
        printf("Found cluster: addr %d, ep %d\n", ind->src_addr, *match_ep);
    }
}

void esp_zb_zdo_find_temp_humid_sensor(esp_zb_zdo_match_desc_req_param_t* cmd_req, esp_zb_zdo_match_desc_callback_t user_cb, void* user_ctx) {
    zb_uint8_t                 bufid   = zb_buf_get_out();
    zb_uint8_t                 zdo_tsn = 0;
    zb_zdo_match_desc_param_t* req;
    // 1 is total number of the cluster list
    req                   = zb_buf_initial_alloc(bufid, sizeof(zb_zdo_match_desc_param_t) + (1) * sizeof(zb_uint16_t));
    req->nwk_addr         = cmd_req->dst_nwk_addr;
    req->addr_of_interest = cmd_req->addr_of_interest;
    req->profile_id       = ZB_AF_HA_PROFILE_ID;
    /* searching for temp/humid sensor */
    req->num_in_clusters  = 1;
    req->num_out_clusters = 0;
    req->cluster_list[0]  = ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT;
    // req->cluster_list[1]  = ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT;
    zdo_tsn = zb_zdo_match_desc_req(bufid, find_temp_humid_sensor);
    // ZB_SCHEDULE_APP_ALARM(match_desc_req_device_timeout, zdo_tsn, ESP_ZB_MATCH_DESC_REQ_TIMEOUT);
    // esp_zb_zdo_callback_register(zdo_tsn, ESP_ZDO_MATCH_DESC_REQ_CLID, (void*)user_cb, user_ctx);
}

But I have the last two lines commented out. Most importantly, esp_zb_zdo_callback_register seems to be missing in the SDK and/or ZBoss lib. I guess this is something that will be released in the next release of the SDK? Do you perhaps have any estimate of when this will release?

@abdulrehmanee12
Copy link
Contributor

abdulrehmanee12 commented Jul 4, 2023

Correct me if I am wrong, but is this function not only for sending the status notifications? I need a function similar to esp_zb_device_add_report_attr_cb that calls the provided callback when such a command is received.

Yes, you're correct. We haven't tested receiving statusChangeNotifications from an IAS zone yet, so we need to verify if the callback is supported. We will provide you with an update soon.

But I have the last two lines commented out. Most importantly, esp_zb_zdo_callback_register seems to be missing in the SDK and/or ZBoss lib. I guess this is something that will be released in the next release of the SDK? Do you perhaps have any estimate of when this will release?

It has already been implemented in our SDK and I tested it on my side.

@pieterjanbuntinx
Copy link
Author

It has already been implemented in our SDK and I tested it on my side.

If I search on GitHub I cannot find any reference to esp_zb_zdo_callback_register except for in this post. Are you sure it is in the main branch on GitHub?

@abdulrehmanee12
Copy link
Contributor

If I search on GitHub I cannot find any reference to esp_zb_zdo_callback_register except for in this post. Are you sure it is in the main branch on GitHub?

Yes, my mistake. It's our internal implementation and is not currently exposed to users. However, in the next release, we plan to provide a common function that will support door sensors and temp/humid sensors.

@pieterjanbuntinx
Copy link
Author

Okay, thanks!
We will then be patiently waiting on the next release :)

@xieqinan
Copy link
Contributor

The ias zone cluster can not receive the status notification issue has been fixed in esp-zigbee-lib.

Please update the latest esp-zigbee-sdk to fix your problem.

@abdulrehmanee12
Copy link
Contributor

@pieterjanbuntinx We have released a new version of esp_zigbee_sdk that includes the common function to find the matched cluster esp_zb_zdo_match_cluster please use the updated esp_zb_zdo_match_desc_req_param_t to create your required cluster list . Additionally, we have included a callback function esp_zb_add_ias_zone_status_notification_cb for handling statusChangeNotifications. Please use the latest version and go ahead with your project.

@pieterjanbuntinx
Copy link
Author

Thank you for the update @xieqinan & @abdulrehmanee12,

Can my issue be reopened?
I have been testing the new sdk version today for some time. I am now able to receive statusChangeNotifications but not all the time. After commissioning the device, for some time, I can receive the notifications by triggering the door sensor (time 51358-64408). After this, the sensor seems to be leaving the network for sometime and a while rejoin the network. The sensor itself does not seem to be turning off, it still indicates the trigger with its led light. Right after the sensor has joined the network, the ESP also spits outs the error ESP_ZIGBEE_CORE: Failed to handle IAS Zone enroll request (status: 0).
Do you have any idea of what could be wrong here? I am using version 7.1 of the SDK and the v5.1 release version of the IDF.
Below you can find my changes to the default gateway example and the esp console.

void status_change_notif_cb(uint16_t zone_status, uint8_t extended_status, uint8_t zone_id, uint16_t delay) {
    printf("(%lli) received stat_ch_notif: zone_status: %i, ext status: %i, zone_id: %i, delay: %i\n", esp_timer_get_time() / 1000, zone_status, extended_status, zone_id, delay);
}

#define EXTERNAL_DEVICES_ENDPOINT 1

static void esp_zb_task(void* pvParameters) {
    /* initialize Zigbee stack with Zigbee coordinator config */
    esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG();
    esp_zb_init(&zb_nwk_cfg);

    /* create endpoint list */
    esp_zb_ep_list_t* esp_zb_ep_list = esp_zb_ep_list_create();

    /* create cluster list for external device endpoint */
    esp_zb_cluster_list_t* esp_zb_external_devices_cluster_list = esp_zb_zcl_cluster_list_create();

    /* create ias zone cluster with server parameters */
    esp_zb_ias_zone_cluster_cfg_t zone_cfg = {
        .zone_state   = 0,
        .zone_type    = ESP_ZB_ZCL_IAS_ZONE_ZONETYPE_CONTACT_SWITCH,
        .zone_status  = 0,
        .ias_cie_addr = ESP_ZB_ZCL_ZONE_IAS_CIE_ADDR_DEFAULT,
        .zone_id      = 0xFF,
    };
    esp_zb_attribute_list_t* esp_zb_ias_zone_cluster = esp_zb_ias_zone_cluster_create(&zone_cfg);
    esp_zb_cluster_list_add_ias_zone_cluster(esp_zb_external_devices_cluster_list, esp_zb_ias_zone_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE);

    /* create endpoint for external devices */
    esp_zb_ep_list_add_ep(esp_zb_ep_list, esp_zb_external_devices_cluster_list, EXTERNAL_DEVICES_ENDPOINT, ESP_ZB_AF_HA_PROFILE_ID, ESP_ZB_HA_TEST_DEVICE_ID);

    /* register endpoints */
    esp_zb_device_register(esp_zb_ep_list);

    esp_zb_add_ias_zone_status_notification_cb(EXTERNAL_DEVICES_ENDPOINT, status_change_notif_cb);

    /* initiate Zigbee Stack start without zb_send_no_autostart_signal auto-start */
    esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
    ESP_ERROR_CHECK(esp_zb_start(false));
#if (CONFIG_ZB_RADIO_MACSPLIT_UART)
    esp_zb_add_rcp_failure_cb(rcp_error_handler);
#endif
    esp_zb_main_loop_iteration();
    esp_rcp_update_deinit();
    vTaskDelete(NULL);
}
I (1442) main_task: Returned from app_main()
I (1472) ESP_ZB_GATEWAY: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL
I (1502) ESP_ZB_GATEWAY: Zigbee stack initialized
I (2062) ESP_ZB_GATEWAY: Zigbee rcp device booted
I (2062) ESP_ZB_GATEWAY: Running RCP Version: zigbee-54576b7528--0.3.6-2023-06-20 10:48:17 UTC
I (3122) ESP_ZB_GATEWAY: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
I (3622) ESP_ZB_GATEWAY: Start network formation
I (3842) ESP_ZB_GATEWAY: Formed network successfully (ieee_address: ff:fe:18:97:40:ca:4c:40, PAN ID: 0xb29c, Channel:13)
I (4672) ESP_ZB_GATEWAY: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
I (5082) ESP_ZB_GATEWAY: Network steering started
I (49012) ESP_ZB_GATEWAY: ZDO signal: NWK Device Associated (0x12), status: ESP_OK
I (49242) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Update (0x30), status: ESP_OK
I (49802) ESP_ZB_GATEWAY: New device commissioned or rejoined (short: 0x3aa5)
E (50152) ESP_ZIGBEE_CORE: Failed to handle IAS Zone enroll request (status: 0)
(51358) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(54458) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(54558) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(54848) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(55928) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(56378) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(56738) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(57108) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(57438) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(57798) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(58148) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(58398) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(58628) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(58978) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(59208) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(59498) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(59828) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(60088) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(60438) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(60718) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(61018) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(61378) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(61588) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(61888) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(62218) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(62448) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(62728) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(63058) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(63618) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(63868) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(63958) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(64168) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
I (64282) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
(64408) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
I (64522) ESP_ZB_GATEWAY: ZDO signal: ZDO Leave Indication (0x13), status: ESP_OK
I (65292) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (65612) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (66032) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (66452) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (66812) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (67042) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (67672) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (67912) ESP_ZB_GATEWAY: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
I (102722) ESP_ZB_GATEWAY: ZDO signal: ZDO Leave Indication (0x13), status: ESP_OK
I (103692) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Update (0x30), status: ESP_OK
(103728) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
I (103882) ESP_ZB_GATEWAY: New device commissioned or rejoined (short: 0x3aa5)
E (104002) ESP_ZIGBEE_CORE: Failed to handle IAS Zone enroll request (status: 0)
(105148) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(106048) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(106548) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(106928) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(107308) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(107798) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(108088) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(108588) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(108938) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(109288) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(109618) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(110018) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(110278) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
(110668) received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 255, delay: 0
(110988) received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0

@xieqinan
Copy link
Contributor

xieqinan commented Jul 18, 2023

Hi,
I suggest registering an IAS zone request callback using esp_zb_add_ias_zone_enroll_request_cb to respond to the door sensor's request. Additionally, utilize esp_zb_zcl_ias_zone_enroll_cmd_resp to assign the ZoneID attribute for the door sensor.
image

@pieterjanbuntinx
Copy link
Author

Hi @xieqinan,

I am trying to do step 5 from your screenshot but I am not sure how to send the enroll response command inside of the callback shown below. In this callback, I have no access to the ieee/short address of the device that has sent the enroll request.
For testing, I captured the address in a global variable when the device has joined and I used address that in the enroll response command. The device just leaves the network after a few seconds and does not reconnect. If that would have worked, it is not the correct way of doing this because I cannot make sure that the device that had joined is the same as the device that send the enroll request. Do you perhaps have an example of how to do this?

Can you maybe also link to the document where you got this screenshot from? I have found a similar document but from NXP, is there an ESP-specific document available?

void ias_zone_enroll_request_cb(uint16_t zone_type, uint16_t manuf) {
    printf("zone_enroll_req cb: zone_type: %i, manuf: %i\n", zone_type, manuf);

    esp_zb_zcl_ias_zone_enroll_response_cmd_t cmd_resp;
    // cmd_resp.zcl_basic_cmd.dst_addr_u // not available in callback
    cmd_resp.zcl_basic_cmd.dst_endpoint = 1;
    cmd_resp.zcl_basic_cmd.src_endpoint = 1;
    cmd_resp.address_mode               = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; // ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT
    cmd_resp.zone_id                    = 1;
    cmd_resp.enroll_rsp_code            = ESP_ZB_ZCL_IAS_ZONE_ENROLL_RESPONSE_CODE_SUCCESS;
    esp_zb_zcl_ias_zone_enroll_cmd_resp(&cmd_resp);
}

@xieqinan
Copy link
Contributor

Hi @pieterjanbuntinx ,
If the IAS Zone cluster has not been created, will the door sensor leave the Zigbee network? It is difficult to explain the reason behind the IAS Zone command triggering the leave indication signal.

I captured the address in a global variable when the device has joined and I used address that in the enroll response command.

The current method should work, but it is not optimal; a better solution that the network address of request side will as the parameter of callback will be provided in esp-zigbee-sdk v1.0.0.

Can you maybe also link to the document where you got this screenshot from? I have found a similar document but from NXP, is there an ESP-specific document available?

The screenshot is from the Zigbee Zcl library specification 8.2.2.1.3.

@pieterjanbuntinx
Copy link
Author

I am having trouble writing the CIE address to the sensor. I am using the code below to write and read the CIE address to the door sensor. But it always reads out as 00:00:00:00:00:00:00:00 on one sensor and FF:FF:FF:FF:FF:FF:FF:FF on another.
I do get a zone_enroll_cmd_request from the door sensor. If I respond with a zone_enroll_cmd_response, I can read out the ZoneState attribute as 1 (enrolled). After a while, I get a ZDO Leave Indication. The sensor won't rejoin the network after this anymore and it looks like it went back into pairing mode (the led blinks).

If the IAS Zone cluster has not been created, will the door sensor leave the Zigbee network? It is difficult to explain the reason behind the IAS Zone command triggering the leave indication signal.

If I don't create the IAS Zone cluster locally and don't bind it, I get the exact same behavior.

The current method should work, but it is not optimal; a better solution that the network address of request side will as the parameter of callback will be provided in esp-zigbee-sdk v1.0.0.

Will this be the next release?

void esp_zb_app_signal_handler(esp_zb_app_signal_t* signal_struct) {
// (...)

    switch (sig_type) {
    // (...)
        case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE: {
            dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t*)esp_zb_app_signal_get_params(p_sg_p);
            ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr);
            
            // Write CIE address 
            esp_zb_zcl_write_attr_cmd_t req_param = {0};
            req_param.zcl_basic_cmd.src_endpoint  = 1;
            req_param.zcl_basic_cmd.dst_endpoint  = 1;
            memcpy(req_param.zcl_basic_cmd.dst_addr_u.addr_long, dev_annce_params->ieee_addr, sizeof(esp_zb_ieee_addr_t));
            req_param.clusterID     = ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE;
            req_param.attributeID   = ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID;
            req_param.attrType      = ESP_ZB_ZCL_ATTR_TYPE_IEEE_ADDR;
            esp_zb_ieee_addr_t addr = {0};
            esp_zb_get_long_address(addr);
            req_param.attrVal = addr;
            esp_zb_zcl_write_attr_cmd_req(&req_param);

            break;
        }
    // (...)
    }
}

// (...)
// read CIE address
esp_zb_zcl_read_attr_cmd_t read_req;
read_req.address_mode               = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT;
read_req.attributeID                = ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID;
read_req.clusterID                  = ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE;
read_req.zcl_basic_cmd.dst_endpoint = EXTERNAL_DEVICES_ENDPOINT;
read_req.zcl_basic_cmd.src_endpoint = EXTERNAL_DEVICES_ENDPOINT;
memcpy(read_req.zcl_basic_cmd.dst_addr_u.addr_long, test_addr, sizeof(esp_zb_ieee_addr_t));
esp_zb_zcl_read_attr_cmd_req(&read_req);
// (...)
I (11590) COREDUMP_UPLOAD: reset reason is 3
I (12760) ESP_ZB_GATEWAY: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
I (13140) ESP_ZB_GATEWAY: Formed network successfully (ieee extended address: 18:97:40:fe:ff:ca:4c:40, PAN ID: 0xc23b)
I (14000) ESP_ZB_GATEWAY: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
I (14400) ESP_ZB_GATEWAY: Network steering started
I (14640) ESP_ZB_GATEWAY: ZDO signal: NWK Device Associated (0x12), status: ESP_OK
I (15090) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Update (0x30), status: ESP_OK
I (15610) ESP_ZB_GATEWAY: New device commissioned or rejoined (short: 0xd475)
zone_enroll_req cb: zone_type: 21, manuf: 0
Bind successful! (d475)
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 255, delay: 0
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
requested attributes
requested attributes
received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 0, delay: 0
read_attr_resp_cb: status: 0, cluster_id: 1280, attr_id: 16, attr_type: 240, address: 00:00:00:00:00:00:00:00
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
received stat_ch_notif: zone_status: 0, ext status: 0, zone_id: 0, delay: 0
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
I (30160) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
read_attr_resp_cb: status: 0, cluster_id: 1280, attr_id: 16, attr_type: 240, address: 00:00:00:00:00:00:00:00
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
received stat_ch_notif: zone_status: 1, ext status: 0, zone_id: 0, delay: 0
requested attributes

@pieterjanbuntinx
Copy link
Author

With temperature/humidity sensors I get a similar behavior. The device joins the network, I do binding and configure reporting in the bind callback and the device starts sending reports for the configured attributes. But after like 10 seconds the device leaves the network and never rejoins. The device also seems to be in pairing mode with the led blinking.

I (11590) COREDUMP_UPLOAD: reset reason is 3
I (12820) ESP_ZB_GATEWAY: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
I (13200) ESP_ZB_GATEWAY: Formed network successfully (ieee extended address: 18:97:40:fe:ff:ca:4c:40, PAN ID: 0x7166)
I (14030) ESP_ZB_GATEWAY: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
I (14430) ESP_ZB_GATEWAY: Network steering started
I (24800) ESP_ZB_GATEWAY: ZDO signal: NWK Device Associated (0x12), status: ESP_OK
I (25030) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Update (0x30), status: ESP_OK
I (25890) ESP_ZB_GATEWAY: Switch got report attribute from address:0xfb3d,src_ep:1,dst_ep:1,cluster_id:0x405,attr_id:0x0,value:248,attr_type:0x21,
I (25910) ESP_ZB_GATEWAY: New device commissioned or rejoined (short: 0xfb3d)
Bind successful! (fb3d)
I (28870) ESP_ZB_GATEWAY: Switch got report attribute from address:0xfb3d,src_ep:1,dst_ep:1,cluster_id:0x402,attr_id:0x0,value:108,attr_type:0x29,
I (29070) ESP_ZB_GATEWAY: Switch got report attribute from address:0xfb3d,src_ep:1,dst_ep:1,cluster_id:0x405,attr_id:0x0,value:109,attr_type:0x21,
I (35050) ESP_ZB_GATEWAY: Switch got report attribute from address:0xfb3d,src_ep:1,dst_ep:1,cluster_id:0x402,attr_id:0x0,value:117,attr_type:0x29,
I (35090) ESP_ZB_GATEWAY: Switch got report attribute from address:0xfb3d,src_ep:1,dst_ep:1,cluster_id:0x405,attr_id:0x0,value:232,attr_type:0x21,
I (38050) ESP_ZB_GATEWAY: Switch got report attribute from address:0xfb3d,src_ep:1,dst_ep:1,cluster_id:0x402,attr_id:0x0,value:108,attr_type:0x29,
I (40080) ESP_ZB_GATEWAY: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
I (40880) ESP_ZB_GATEWAY: ZDO signal: ZDO Leave Indication (0x13), status: ESP_OK
I (40920) ESP_ZB_GATEWAY: ZDO signal: ZDO Leave Indication (0x13), status: ESP_OK
// (...)

// is called when device has joined in esp_zb_app_signal_handler
esp_zb_zdo_bind_req_param_t bind_req;
memcpy(bind_req.src_address, device->ieee_addr, sizeof(esp_zb_ieee_addr_t));
bind_req.src_endp      = 1;
bind_req.cluster_id    = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT;
bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED;
esp_zb_get_long_address(bind_req.dst_address_u.addr_long);
bind_req.dst_endp     = EXTERNAL_DEVICES_ENDPOINT;
bind_req.req_dst_addr = device->short_addr;
esp_zb_zdo_device_bind_req(&bind_req, bind_cb, (void*)device);

// (...)

// bind callback, attribute reporting is here configured
static void bind_cb(esp_zb_zdp_status_t zdo_status, void* user_ctx) {
    if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
        device_t* device = (device_t*)user_ctx;

        printf("Bind successful! (%x)\n", device->short_addr);

        /* configure report attribute command */
        esp_zb_zcl_config_report_cmd_t report_cmd    = {0};
        int16_t                        report_change = 2;
        memcpy(&report_cmd.zcl_basic_cmd.dst_addr_u.addr_long, device->ieee_addr, sizeof(esp_zb_ieee_addr_t));
        report_cmd.zcl_basic_cmd.dst_endpoint = 1;
        report_cmd.zcl_basic_cmd.src_endpoint = EXTERNAL_DEVICES_ENDPOINT;
        report_cmd.address_mode               = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT;
        report_cmd.clusterID                  = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT;
        report_cmd.attributeID                = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID;
        report_cmd.attrType                   = ESP_ZB_ZCL_ATTR_TYPE_S16;
        report_cmd.min_interval               = 1;
        report_cmd.max_interval               = 10;
        report_cmd.reportable_change          = (void*)&report_change;
        esp_zb_zcl_config_report_cmd_req(&report_cmd);
    }
}

@xieqinan
Copy link
Contributor

Let's address the leave indication problem first. Can you please refer to the related issue? Ensure the same preconfigured key between Zigbee gateway and the sensor.

@pieterjanbuntinx
Copy link
Author

I have set esp_zb_secur_link_key_exchange_required_set to false and that seems to work for both kinds of sensors, thanks! I do find it strange that none of the sensors I have provide the install code.

@xieqinan
Copy link
Contributor

Yes, it is a better way to join Zigbee network by the install code.

@Stelios1908
Copy link

ηι!!!
Is there finally an example to show how I can get from an ED a zone state?

@straga
Copy link

straga commented May 27, 2024

before was esp_zb_add_ias_zone_status_notification_cb, what now need use for cb IAS zone change ?

@xieqinan
Copy link
Contributor

@straga

The esp_zb_add_ias_zone_status_notification_cb() function has been removed in the new SDK. The new SDK provides a new mechanism for cluster callbacks. You can refer to the core_action_cb. The ESP_ZB_CORE_CMD_IAS_ZONE_ZONE_STATUS_CHANGE_NOT_ID action will be triggered when an IAS ZONE status change notification is generated.

By the way, this issue had been closed, please feel free to open new issue if you have questions for the esp-zigbee-sdk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants