From 0b18c60ba244fb7d3bd57b39bbe5eb0e49532750 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 16 Nov 2022 13:43:36 +0100 Subject: [PATCH 1/3] Zigbee ZbProbe for unknown devices and doc helper --- tasmota/include/i18n.h | 1 + .../xdrv_23_zigbee_A_impl.ino | 61 ++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/tasmota/include/i18n.h b/tasmota/include/i18n.h index 85445545b..7896e761b 100644 --- a/tasmota/include/i18n.h +++ b/tasmota/include/i18n.h @@ -689,6 +689,7 @@ #define D_CMND_ZIGBEE_LOAD "Load" #define D_CMND_ZIGBEE_LOADDUMP "LoadDump" #define D_CMND_ZIGBEE_UNLOAD "Unload" +#define D_CMND_ZIGBEE_ATTRDUMP "AttrDump" // Commands xdrv_25_A4988_Stepper.ino #define D_CMND_MOTOR "MOTOR" diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino index 4f44a8115..8fb559d34 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino @@ -21,6 +21,8 @@ #define XDRV_23 23 +#define ZIGBEE_DOC // enable special functions used for Zigbee documentation generation - generally not useful + #include "UnishoxStrings.h" const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix @@ -40,7 +42,10 @@ const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix D_CMND_ZIGBEE_LIGHT "|" D_CMND_ZIGBEE_OCCUPANCY "|" 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 "|" D_CMND_ZIGBEE_SCAN "|" D_CMND_ZIGBEE_ENROLL "|" D_CMND_ZIGBEE_CIE "|" - D_CMND_ZIGBEE_LOAD "|" D_CMND_ZIGBEE_UNLOAD "|" D_CMND_ZIGBEE_LOADDUMP + D_CMND_ZIGBEE_LOAD "|" D_CMND_ZIGBEE_UNLOAD "|" D_CMND_ZIGBEE_LOADDUMP "|" +#ifdef ZIGBEE_DOC + D_CMND_ZIGBEE_ATTRDUMP +#endif // ZIGBEE_DOC ; SO_SYNONYMS(kZbSynonyms, @@ -64,6 +69,9 @@ void (* const ZigbeeCommand[])(void) PROGMEM = { &CmndZbConfig, &CmndZbData, &CmndZbScan, &CmndZbenroll, &CmndZbcie, &CmndZbLoad, &CmndZbUnload, &CmndZbLoadDump, +#ifdef ZIGBEE_DOC + &CmndZbAttrDump, +#endif // ZIGBEE_DOC }; /********************************************************************************************/ @@ -1119,8 +1127,16 @@ void CmndZbProbe(void) { // void CmndZbProbeOrPing(boolean probe) { if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; } - uint16_t shortaddr = zigbee_devices.parseDeviceFromName(XdrvMailbox.data, nullptr, nullptr, XdrvMailbox.payload).shortaddr; - if (BAD_SHORTADDR == shortaddr) { ResponseCmndChar_P(PSTR(D_ZIGBEE_UNKNOWN_DEVICE)); return; } + uint16_t parsed_shortaddr = BAD_SHORTADDR; + uint16_t shortaddr = zigbee_devices.parseDeviceFromName(XdrvMailbox.data, &parsed_shortaddr, nullptr, XdrvMailbox.payload).shortaddr; + if (BAD_SHORTADDR == shortaddr) { + if (BAD_SHORTADDR == parsed_shortaddr) { // second chance if we provided 0x.... address for a device not in the list + ResponseCmndChar_P(PSTR(D_ZIGBEE_UNKNOWN_DEVICE)); + return; + } else { + shortaddr = parsed_shortaddr; + } + } // set a timer for Reachable - 2s default value zigbee_devices.setTimer(shortaddr, 0, Z_CAT_REACHABILITY_TIMEOUT, 0, 0, Z_CAT_REACHABILITY, 0 /* value */, &Z_Unreachable); @@ -1417,6 +1433,45 @@ void CmndZbLoadDump(void) { ResponseCmndDone(); } +#ifdef ZIGBEE_DOC +// Command `ZbAttrDump` +// Dump all the attribute aliases for documentation purpose +// +void CmndZbAttrDump(void) { + // does not require Zigbee to actually run + AddLog(LOG_LEVEL_INFO, PSTR("Alias|Cluster|Attribute|Type")); + AddLog(LOG_LEVEL_INFO, PSTR(":---|:---|:---|:---")); + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { + const Z_AttributeConverter *converter = &Z_PostProcess[i]; + if (0 == pgm_read_word(&converter->name_offset)) { continue; } + const char * alias = Z_strings + pgm_read_word(&converter->name_offset); + uint16_t cluster = CxToCluster(pgm_read_byte(&converter->cluster_short)); + uint16_t attrid = pgm_read_word(&converter->attribute); + uint8_t attrtype = pgm_read_byte(&converter->type); + char type_name[16]; + Z_getTypeByNumber(type_name, sizeof(type_name), attrtype); + AddLog(LOG_LEVEL_INFO, PSTR("`%s`|0x%04X|0x%04X|%%%02X - %s"), alias, cluster, attrid, attrtype, type_name); + } + AddLog(LOG_LEVEL_INFO, PSTR("")); + + AddLog(LOG_LEVEL_INFO, PSTR("Alias|Cluster|Command")); + AddLog(LOG_LEVEL_INFO, PSTR(":---|:---|:---")); + for (uint32_t i = 0; i < sizeof(Z_Commands) / sizeof(Z_Commands[0]); i++) { + const Z_CommandConverter *conv = &Z_Commands[i]; + const char * alias = Z_strings + pgm_read_word(&conv->tasmota_cmd_offset); + uint16_t cluster = pgm_read_word(&conv->cluster); + uint8_t direction = pgm_read_byte(&conv->direction); + uint8_t cmd = pgm_read_byte(&conv->cmd); + if (direction & 0x01) { // only coordinator to device + AddLog(LOG_LEVEL_INFO, PSTR("`%s`|0x%04X|0x%02X"), alias, cluster, cmd); + } + } + AddLog(LOG_LEVEL_INFO, PSTR("")); + + ResponseCmndDone(); +} +#endif // ZIGBEE_DOC + // // Command `ZbScan` // Run an energy scan From a26e634408208544a43b3c92dd5e1fb4c8ce9c2e Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 16 Nov 2022 13:44:06 +0100 Subject: [PATCH 2/3] Doc is off by default --- tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino index 8fb559d34..c0b198523 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino @@ -21,7 +21,7 @@ #define XDRV_23 23 -#define ZIGBEE_DOC // enable special functions used for Zigbee documentation generation - generally not useful +// #define ZIGBEE_DOC // enable special functions used for Zigbee documentation generation - generally not useful #include "UnishoxStrings.h" @@ -1467,7 +1467,7 @@ void CmndZbAttrDump(void) { } } AddLog(LOG_LEVEL_INFO, PSTR("")); - + ResponseCmndDone(); } #endif // ZIGBEE_DOC From 56e06b7fc545f96757d2bd96c8114dc239c4bbf0 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 16 Nov 2022 13:45:59 +0100 Subject: [PATCH 3/3] Fix command name bug --- tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino index c0b198523..46f3b7023 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino @@ -42,9 +42,9 @@ const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix D_CMND_ZIGBEE_LIGHT "|" D_CMND_ZIGBEE_OCCUPANCY "|" 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 "|" D_CMND_ZIGBEE_SCAN "|" D_CMND_ZIGBEE_ENROLL "|" D_CMND_ZIGBEE_CIE "|" - D_CMND_ZIGBEE_LOAD "|" D_CMND_ZIGBEE_UNLOAD "|" D_CMND_ZIGBEE_LOADDUMP "|" + D_CMND_ZIGBEE_LOAD "|" D_CMND_ZIGBEE_UNLOAD "|" D_CMND_ZIGBEE_LOADDUMP #ifdef ZIGBEE_DOC - D_CMND_ZIGBEE_ATTRDUMP + "|" D_CMND_ZIGBEE_ATTRDUMP #endif // ZIGBEE_DOC ;