From 52d88439ffe0f4fbc6ccbda235f512cb7045ad62 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 4 Oct 2018 11:01:50 +0200 Subject: [PATCH] Fix Domoticz exception Fix exception when wrong Domoticz JSON message is received (#3963) --- sonoff/_changelog.ino | 3 ++- sonoff/xdrv_07_domoticz.ino | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 00c59c3a5..2af5885db 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -3,7 +3,8 @@ * Add support for MQTT Client based on lwmqtt to be selected by #define MQTT_LIBRARY_TYPE MQTT_ARDUINOMQTT * Change MQTT_ARDUINOMQTT command timeout from 1 to 10 seconds * Add Hebrew language file (#3960) - * + * Fix exception when wrong Domoticz JSON message is received (#3963) + * * 6.2.1.10 20180930 * Add command RGBWWTable to support color calibration (#3933) * Add support for Michael Haustein ESP Switch diff --git a/sonoff/xdrv_07_domoticz.ino b/sonoff/xdrv_07_domoticz.ino index a30f79439..7710cad13 100644 --- a/sonoff/xdrv_07_domoticz.ino +++ b/sonoff/xdrv_07_domoticz.ino @@ -150,6 +150,15 @@ void DomoticzMqttSubscribe() "svalue1" : "0", "switchType" : "Dimmer", "unit" : 1 +} + * Fail on this one +{ + "LastUpdate" : "2018-10-02 20:39:45", + "Name" : "Sfeerverlichting", + "Status" : "Off", + "Timers" : "true", + "Type" : "Group", + "idx" : "2" } */ @@ -157,7 +166,7 @@ boolean DomoticzMqttData() { char stemp1[10]; unsigned long idx = 0; - int16_t nvalue; + int16_t nvalue = -1; int16_t found = 0; domoticz_update_flag = 1; @@ -174,7 +183,9 @@ boolean DomoticzMqttData() // return 1; // } idx = domoticz["idx"]; - nvalue = domoticz["nvalue"]; + if (domoticz.containsKey("nvalue")) { + nvalue = domoticz["nvalue"]; + } snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue); AddLog(LOG_LEVEL_DEBUG_MORE); @@ -198,7 +209,11 @@ boolean DomoticzMqttData() found = 1; } else if ((!iscolordimmer && 2 == nvalue) || // gswitch_sSetLevel (iscolordimmer && 15 == nvalue)) { // Color_SetBrightnessLevel - nvalue = domoticz["svalue1"]; + if (domoticz.containsKey("svalue1")) { + nvalue = domoticz["svalue1"]; + } else { + return 1; + } if (light_type && (Settings.light_dimmer == nvalue) && ((power >> i) &1)) { return 1; }