Merge pull request #9841 from s-hadinger/zigbee_zbleave

Zigbee command ``ZbLeave`` to unpair a device
This commit is contained in:
Theo Arends 2020-11-13 19:34:29 +01:00 committed by GitHub
commit e356b31322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- Zigbee command ``ZbInfo`` and prepare support for EEPROM
- Support for AS608 optical and R503 capacitive fingerprint sensor
- Command ``SetOption115 1`` to enable ESP32 MiBle
- Zigbee command ``ZbLeave`` to unpair a device
### Changed
- Core library from v2.7.4.5 to v2.7.4.7

View File

@ -572,6 +572,7 @@
#define D_JSON_ZIGBEE_UNBIND "ZbUnbind"
#define D_CMND_ZIGBEE_BIND_STATE "BindState"
#define D_JSON_ZIGBEE_BIND_STATE "ZbBindState"
#define D_CMND_ZIGBEE_LEAVE "Leave"
#define D_CMND_ZIGBEE_MAP "Map"
#define D_JSON_ZIGBEE_MAP "ZbMap"
#define D_JSON_ZIGBEE_PARENT "ZbParent"

View File

@ -33,7 +33,7 @@ const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix
D_CMND_ZIGBEE_INFO "|" D_CMND_ZIGBEE_FORGET "|" D_CMND_ZIGBEE_SAVE "|" D_CMND_ZIGBEE_NAME "|"
D_CMND_ZIGBEE_BIND "|" D_CMND_ZIGBEE_UNBIND "|" D_CMND_ZIGBEE_PING "|" D_CMND_ZIGBEE_MODELID "|"
D_CMND_ZIGBEE_LIGHT "|" D_CMND_ZIGBEE_OCCUPANCY "|"
D_CMND_ZIGBEE_RESTORE "|" D_CMND_ZIGBEE_BIND_STATE "|" D_CMND_ZIGBEE_MAP "|"
D_CMND_ZIGBEE_RESTORE "|" D_CMND_ZIGBEE_BIND_STATE "|" D_CMND_ZIGBEE_MAP "|" D_CMND_ZIGBEE_LEAVE "|"
D_CMND_ZIGBEE_CONFIG "|" D_CMND_ZIGBEE_DATA
;
@ -49,7 +49,7 @@ void (* const ZigbeeCommand[])(void) PROGMEM = {
&CmndZbInfo, &CmndZbForget, &CmndZbSave, &CmndZbName,
&CmndZbBind, &CmndZbUnbind, &CmndZbPing, &CmndZbModelId,
&CmndZbLight, &CmndZbOccupancy,
&CmndZbRestore, &CmndZbBindState, &CmndZbMap,
&CmndZbRestore, &CmndZbBindState, &CmndZbMap, CmndZbLeave,
&CmndZbConfig, CmndZbData,
};
@ -943,6 +943,40 @@ void CmndZbUnbind(void) {
ZbBindUnbind(true);
}
//
// ZbLeave - ask for a device to leave the network
//
void CmndZbLeave(void) {
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
uint16_t shortaddr = zigbee_devices.parseDeviceFromName(XdrvMailbox.data, true).shortaddr;
if (BAD_SHORTADDR == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
#ifdef USE_ZIGBEE_ZNP
SBuffer buf(14);
buf.add8(Z_SREQ | Z_ZDO); // 25
buf.add8(ZDO_MGMT_LEAVE_REQ); // 34
buf.add16(shortaddr); // shortaddr
buf.add64(0); // remove self
buf.add8(0x00); // don't rejoin and don't remove children
ZigbeeZNPSend(buf.getBuffer(), buf.len());
#endif // USE_ZIGBEE_ZNP
#ifdef USE_ZIGBEE_EZSP
// ZDO message payload (see Zigbee spec 2.4.3.3.4)
SBuffer buf(10);
buf.add64(0); // remove self
buf.add8(0x00); // don't rejoin and don't remove children
EZ_SendZDO(shortaddr, ZDO_MGMT_LEAVE_REQ, buf.getBuffer(), buf.len());
#endif // USE_ZIGBEE_EZSP
ResponseCmndDone();
}
void CmndZbBindState_or_Map(uint16_t zdo_cmd) {
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
uint16_t shortaddr = zigbee_devices.parseDeviceFromName(XdrvMailbox.data, true).shortaddr;