From 698dd755de3dcfcfa01fe1a973db1b1ae39736cf Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Fri, 13 Nov 2020 19:23:35 +0100 Subject: [PATCH] Zigbee command ``ZbLeave`` to unpair a device --- CHANGELOG.md | 1 + tasmota/i18n.h | 1 + tasmota/xdrv_23_zigbee_A_impl.ino | 38 +++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c7ba3cb1..7562fc9a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 3d8254960..9a0528c9e 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -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" diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index c1066b296..7acd3e4a1 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -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;