-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feat(Zigbee): Recall bounded devices after reboot + IEEE address option for commands #10676
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
Changes from 4 commits
d45a267
a6c9d5c
fa53967
40c56b5
c47324a
21409b4
8e6cbfe
c8f7c1b
3ee00ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,8 @@ | |||||
#include "esp_zigbee_cluster.h" | ||||||
#include "zcl/esp_zigbee_zcl_power_config.h" | ||||||
|
||||||
#define ZB_CMD_TIMEOUT 10000 // 10 seconds | ||||||
|
||||||
bool ZigbeeEP::_is_bound = false; | ||||||
bool ZigbeeEP::_allow_multiple_binding = false; | ||||||
|
||||||
|
@@ -112,13 +114,20 @@ void ZigbeeEP::reportBatteryPercentage() { | |||||
log_v("Battery percentage reported"); | ||||||
} | ||||||
|
||||||
char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr) { | ||||||
char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr) { | ||||||
/* Read peer Manufacture Name & Model Identifier */ | ||||||
esp_zb_zcl_read_attr_cmd_t read_req; | ||||||
read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; | ||||||
|
||||||
if(short_addr != 0){ | ||||||
read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; | ||||||
read_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; | ||||||
} else { | ||||||
read_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; | ||||||
memcpy(read_req.zcl_basic_cmd.dst_addr_u.addr_long, ieee_addr, sizeof(esp_zb_ieee_addr_t)); | ||||||
} | ||||||
|
||||||
read_req.zcl_basic_cmd.src_endpoint = _endpoint; | ||||||
read_req.zcl_basic_cmd.dst_endpoint = endpoint; | ||||||
read_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; | ||||||
read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_BASIC; | ||||||
|
||||||
uint16_t attributes[] = { | ||||||
|
@@ -130,22 +139,31 @@ char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr) { | |||||
// clear read manufacturer | ||||||
_read_manufacturer = nullptr; | ||||||
|
||||||
esp_zb_lock_acquire(portMAX_DELAY); | ||||||
esp_zb_zcl_read_attr_cmd_req(&read_req); | ||||||
esp_zb_lock_release(); | ||||||
|
||||||
//Wait for response or timeout | ||||||
if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { | ||||||
if (xSemaphoreTake(lock, ZB_CMD_TIMEOUT) != pdTRUE) { | ||||||
log_e("Error while reading manufacturer"); | ||||||
} | ||||||
return _read_manufacturer; | ||||||
} | ||||||
|
||||||
char *ZigbeeEP::readModel(uint8_t endpoint, uint16_t short_addr) { | ||||||
char *ZigbeeEP::readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr) { | ||||||
/* Read peer Manufacture Name & Model Identifier */ | ||||||
esp_zb_zcl_read_attr_cmd_t read_req; | ||||||
read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; | ||||||
|
||||||
if(short_addr != 0){ | ||||||
read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; | ||||||
read_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; | ||||||
} else { | ||||||
read_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; | ||||||
memcpy(read_req.zcl_basic_cmd.dst_addr_u.addr_long, ieee_addr, sizeof(esp_zb_ieee_addr_t)); | ||||||
} | ||||||
|
||||||
read_req.zcl_basic_cmd.src_endpoint = _endpoint; | ||||||
read_req.zcl_basic_cmd.dst_endpoint = endpoint; | ||||||
read_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; | ||||||
read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_BASIC; | ||||||
|
||||||
uint16_t attributes[] = { | ||||||
|
@@ -157,22 +175,32 @@ char *ZigbeeEP::readModel(uint8_t endpoint, uint16_t short_addr) { | |||||
// clear read model | ||||||
_read_model = nullptr; | ||||||
|
||||||
esp_zb_lock_acquire(portMAX_DELAY); | ||||||
esp_zb_zcl_read_attr_cmd_req(&read_req); | ||||||
esp_zb_lock_release(); | ||||||
|
||||||
//Wait for response or timeout | ||||||
//Semaphore take | ||||||
if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { | ||||||
if (xSemaphoreTake(lock, ZB_CMD_TIMEOUT) != pdTRUE) { | ||||||
log_e("Error while reading model"); | ||||||
} | ||||||
return _read_model; | ||||||
} | ||||||
|
||||||
void ZigbeeEP::printBoundDevices() { | ||||||
log_i("Bound devices:"); | ||||||
for ([[maybe_unused]] | ||||||
const auto &device : _bound_devices) { | ||||||
log_i("Device on endpoint %d, short address: 0x%x", device->endpoint, device->short_addr); | ||||||
print_ieee_addr(device->ieee_addr); | ||||||
void ZigbeeEP::printBoundDevices(Print *print) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such functions in Arduino should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @me-no-dev But can I then use a default parameter? So if there is nothing passed, it will print in log_i? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
if (print == nullptr) { | ||||||
log_i("Bound devices:"); | ||||||
for ([[maybe_unused]] | ||||||
const auto &device : _bound_devices) { | ||||||
log_i("Device on endpoint %d, short address: 0x%x, ieee address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", device->endpoint, device->short_addr, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep log_i for this scenario. If user calls printBoundDevices, and do not provide the Serial where to print, it will be printed with Log Info. |
||||||
device->ieee_addr[7], device->ieee_addr[6], device->ieee_addr[5], device->ieee_addr[4], device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0]); | ||||||
} | ||||||
} else { | ||||||
print->println("Bound devices:"); | ||||||
for ([[maybe_unused]] | ||||||
const auto &device : _bound_devices) { | ||||||
print->printf("Device on endpoint %d, short address: 0x%x, ieee address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n", device->endpoint, device->short_addr, | ||||||
device->ieee_addr[7], device->ieee_addr[6], device->ieee_addr[5], device->ieee_addr[4], device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0]); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
zbSwitch.printBoundDevices(Serial);
with the new API