Merge pull request #10666 from s-hadinger/zigbee_autobind

Zigbee don't do auto-bind if device is already known
This commit is contained in:
s-hadinger 2021-01-22 18:36:54 +01:00 committed by GitHub
commit 9f10c431e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 4 deletions

View File

@ -760,8 +760,8 @@
// Auto-binding constants, see `Z_autoAttributeReporting`
// Below are the threshold for attribute reporting
#define USE_ZIGBEE_AUTOBIND_BATTVOLTAGE 0.1 // V
#define USE_ZIGBEE_AUTOBIND_BATTPERCENT 1 // %
#define USE_ZIGBEE_AUTOBIND_BATTVOLTAGE 0.2 // V
#define USE_ZIGBEE_AUTOBIND_BATTPERCENT 5 // %
#define USE_ZIGBEE_AUTOBIND_TEMPERATURE 0.5 // °C
#define USE_ZIGBEE_AUTOBIND_HEATDEMAND 10 // %
#define USE_ZIGBEE_AUTOBIND_PRESSURE 1 // hPA

View File

@ -105,7 +105,11 @@ public:
ZB_RecvMsgFunc recv_func = nullptr; // function to call when message is expected
ZB_RecvMsgFunc recv_unexpected = nullptr; // function called when unexpected message is received
#ifdef USE_ZIGBEE_EZSP
uint32_t permit_end_time = 0; // timestamp when permit join ends
#elif defined(USE_ZIGBEE_ZNP)
bool permit_end_time = false; // in ZNP mode it's only a boolean
#endif
#ifdef USE_ZIGBEE_EZSP
Eeprom24C512 eeprom; // takes only 1 bytes of RAM

View File

@ -965,6 +965,7 @@ public:
Z_Device & devicesAt(size_t i) const;
// Remove device from list
void clearDeviceRouterInfo(void); // reset all router flags, done just before ZbMap
bool removeDevice(uint16_t shortaddr);
// Mark data as 'dirty' and requiring to save in Flash

View File

@ -218,6 +218,15 @@ Z_Device & Z_Devices::updateDevice(uint16_t shortaddr, uint64_t longaddr) {
return device_unk;
}
// Clear the router flag for each device, called at the beginning of ZbMap
void Z_Devices::clearDeviceRouterInfo(void) {
for (Z_Device & device : zigbee_devices._devices) {
if (device.valid()) {
device.setRouter(false);
}
}
}
//
// Clear all endpoints
//

View File

@ -76,7 +76,7 @@ public:
edges()
{}
void reset(void) { edges.reset(); }
void reset(void) { edges.reset(); zigbee_devices.clearDeviceRouterInfo(); }
Z_Mapper_Edge & findEdge(const Z_Mapper_Edge & edge2);
bool addEdge(const Z_Mapper_Edge & edge2);

View File

@ -501,12 +501,15 @@ int32_t ZNP_ReceivePermitJoinStatus(int32_t res, const class SBuffer &buf) {
if (0xFF == duration) {
status_code = ZIGBEE_STATUS_PERMITJOIN_OPEN_XX;
message = PSTR("Enable Pairing mode until next boot");
zigbee.permit_end_time = true; // In ZNP mode, declare permitjoin open
} else if (duration > 0) {
status_code = ZIGBEE_STATUS_PERMITJOIN_OPEN_60;
message = PSTR("Enable Pairing mode for %d seconds");
zigbee.permit_end_time = true; // In ZNP mode, declare permitjoin open
} else {
status_code = ZIGBEE_STATUS_PERMITJOIN_CLOSE;
message = PSTR("Disable Pairing mode");
zigbee.permit_end_time = false; // In ZNP mode, declare permitjoin closed
}
Response_P(PSTR("{\"" D_JSON_ZIGBEE_STATE "\":{"
"\"Status\":%d,\"Message\":\""),
@ -884,6 +887,14 @@ int32_t Z_ReceiveEndDeviceAnnonce(int32_t res, const class SBuffer &buf) {
uint8_t capabilities = buf.get8(10);
#endif
// record if we already knew the ieeeAddr for this device
// this will influence the decision whether we do auto-binding or not
const Z_Device & device_before = zigbee_devices.findShortAddr(nwkAddr);
bool ieee_already_known = false;
if (device_before.valid() && (device_before.longaddr != 0) && (device_before.longaddr == ieeeAddr)) {
ieee_already_known = true;
}
zigbee_devices.updateDevice(nwkAddr, ieeeAddr);
// device is reachable
zigbee_devices.deviceWasReached(nwkAddr);
@ -903,7 +914,10 @@ int32_t Z_ReceiveEndDeviceAnnonce(int32_t res, const class SBuffer &buf) {
Z_Query_Bulb(nwkAddr, wait_ms);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
Z_SendActiveEpReq(nwkAddr);
// Continue the discovery process and auto-binding only if the device was unknown or if PermitJoin is ongoing
if (!ieee_already_known || zigbee.permit_end_time) {
Z_SendActiveEpReq(nwkAddr);
}
return -1;
}