espressif / esp-zigbee-sdk

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

esp_zb_zcl_write_attr_cmd_req not working (TZ-1054) #402

Closed mundevx closed 2 months ago

mundevx commented 3 months ago

Question

I have a zigbee coordinator and zigbee router, and both are bind successfully. The Zigbee router using customized_server example code with minor changes and zigbee_gateway example i used for Coordinator. The coordinator side dont have any clusters and only search for device, bind that device and stores the information like short address and pan address, etc. Issue is that esp_zb_zcl_on_off_cmd_req is working fine, but esp_zb_zcl_write_attr_cmd_req is not working and i spend 2 days in it.

void send_write_command(uint16_t short_addr){ esp_zb_zcl_on_off_cmd_t cmd_req; cmd_req.zcl_basic_cmd.src_endpoint = 1; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = rx_short_addr; cmd_req.zcl_basic_cmd.dst_endpoint = 1; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID;
esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_on_off_cmd_req(&cmd_req); esp_zb_lock_release(); }

void send_write_attr_val(uint16_t short_addr, bool state) { esp_zb_zcl_attribute_t attr_field; attr_field.id = ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID; attr_field.data.type = ESP_ZB_ZCL_ATTR_TYPE_BOOL; attr_field.data.size = 1; attr_field.data.value = (uint8_t*)&state;

esp_zb_zcl_write_attr_cmd_t write_req;
memset(&write_req, 0, sizeof(write_req));

write_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr;
write_req.zcl_basic_cmd.dst_endpoint = 1; // Target endpoint on the device
write_req.zcl_basic_cmd.src_endpoint = 1; // Source endpoint (set to 1 or 0 depending on your setup)
write_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT;
write_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF;
write_req.attr_field = &attr_field;
write_req.attr_number = 1;
esp_zb_lock_acquire(portMAX_DELAY);
esp_err_t result = esp_zb_zcl_write_attr_cmd_req(&write_req);
esp_zb_lock_release();

}

After successfully binding from Coordinator with Zigbee Light Device, and i call function from coordinator the "send_write_command" is working fine and toggling light and finding callbacks. But if i call "send_write_attr_val", nothin happens and Zigbee Light Device doen't show any callback log. Means to say, esp_zb_zcl_write_attr_cmd_req is not working. I used all 4 address_mode in this function. Nothing happens. Please help me for this issue.

Additional context.

No response

xieqinan commented 3 months ago

Hello @mundevx ,

The ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID attribute does not have WRITE access, so you cannot modify it using the esp_zb_zcl_write_attr_cmd_req() command.

image

By the way, we've discussed similar issues multiple times. The lack of sufficient debug logs in the SDK is the primary reason for your challenges. We plan to add more user-friendly debug logs in future releases. In the meantime, I recommend referring to the debug documentation. Reviewing the Zigbee Cluster Library would also help you identify the root causes of Zigbee issues.