From 7d8a4f5077ed51c513c51fbb02240b4fa59c0a18 Mon Sep 17 00:00:00 2001 From: Hadinger Date: Thu, 12 Dec 2019 22:22:34 +0100 Subject: [PATCH 1/2] Fix Zigbee crash #7187 --- tasmota/xdrv_23_zigbee_9_impl.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasmota/xdrv_23_zigbee_9_impl.ino b/tasmota/xdrv_23_zigbee_9_impl.ino index cb08eeaee..9a08c3585 100644 --- a/tasmota/xdrv_23_zigbee_9_impl.ino +++ b/tasmota/xdrv_23_zigbee_9_impl.ino @@ -235,13 +235,14 @@ void ZigbeeInit(void) * Commands \*********************************************************************************************/ -uint32_t strToUInt(const JsonVariant val) { +uint32_t strToUInt(const JsonVariant &val) { // if the string starts with 0x, it is considered Hex, otherwise it is an int if (val.is()) { return val.as(); } else { - if (val.is()) { - return strtoull(val.as(), nullptr, 0); + if (val.is()) { + String sval = val.as(); + return strtoull(sval.c_str(), nullptr, 0); } } return 0; // couldn't parse anything @@ -593,6 +594,7 @@ void CmndZigbeeRead(void) { const JsonVariant &val_attr = getCaseInsensitive(json, PSTR("Read")); if (nullptr != &val_attr) { + uint16_t val = strToUInt(val_attr); if (val_attr.is()) { JsonArray& attr_arr = val_attr; attrs_len = attr_arr.size() * 2; @@ -604,11 +606,9 @@ void CmndZigbeeRead(void) { attrs[i++] = val & 0xFF; attrs[i++] = val >> 8; } - } else { attrs_len = 2; attrs = new uint8_t[attrs_len]; - uint16_t val = strToUInt(val_attr); attrs[0] = val & 0xFF; // little endian attrs[1] = val >> 8; } From 0c717ddbac4d08da681da09f69addcb583e9bdf6 Mon Sep 17 00:00:00 2001 From: Hadinger Date: Thu, 12 Dec 2019 22:32:00 +0100 Subject: [PATCH 2/2] Added ResponseCmndDone() to ZigbeeRead --- tasmota/xdrv_23_zigbee_9_impl.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_23_zigbee_9_impl.ino b/tasmota/xdrv_23_zigbee_9_impl.ino index 9a08c3585..4e2ba5499 100644 --- a/tasmota/xdrv_23_zigbee_9_impl.ino +++ b/tasmota/xdrv_23_zigbee_9_impl.ino @@ -614,9 +614,10 @@ void CmndZigbeeRead(void) { } } - ZigbeeZCLSend(device, cluster, endpoint, ZCL_READ_ATTRIBUTES, false, attrs, attrs_len, false /* we do want a response */); + ZigbeeZCLSend(device, cluster, endpoint, ZCL_READ_ATTRIBUTES, false, attrs, attrs_len, false /* we do want a response */); - if (attrs) { delete[] attrs; } + if (attrs) { delete[] attrs; } + ResponseCmndDone(); } // Allow or Deny pairing of new Zigbee devices