Fix Domoticz exception

Fix exception when wrong Domoticz JSON message is received (#3963)
This commit is contained in:
Theo Arends 2018-10-04 11:01:50 +02:00
parent 0d7a1a62fc
commit 52d88439ff
2 changed files with 20 additions and 4 deletions

View File

@ -3,7 +3,8 @@
* Add support for MQTT Client based on lwmqtt to be selected by #define MQTT_LIBRARY_TYPE MQTT_ARDUINOMQTT * 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 * Change MQTT_ARDUINOMQTT command timeout from 1 to 10 seconds
* Add Hebrew language file (#3960) * Add Hebrew language file (#3960)
* * Fix exception when wrong Domoticz JSON message is received (#3963)
*
* 6.2.1.10 20180930 * 6.2.1.10 20180930
* Add command RGBWWTable to support color calibration (#3933) * Add command RGBWWTable to support color calibration (#3933)
* Add support for Michael Haustein ESP Switch * Add support for Michael Haustein ESP Switch

View File

@ -150,6 +150,15 @@ void DomoticzMqttSubscribe()
"svalue1" : "0", "svalue1" : "0",
"switchType" : "Dimmer", "switchType" : "Dimmer",
"unit" : 1 "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]; char stemp1[10];
unsigned long idx = 0; unsigned long idx = 0;
int16_t nvalue; int16_t nvalue = -1;
int16_t found = 0; int16_t found = 0;
domoticz_update_flag = 1; domoticz_update_flag = 1;
@ -174,7 +183,9 @@ boolean DomoticzMqttData()
// return 1; // return 1;
// } // }
idx = domoticz["idx"]; 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); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue);
AddLog(LOG_LEVEL_DEBUG_MORE); AddLog(LOG_LEVEL_DEBUG_MORE);
@ -198,7 +209,11 @@ boolean DomoticzMqttData()
found = 1; found = 1;
} else if ((!iscolordimmer && 2 == nvalue) || // gswitch_sSetLevel } else if ((!iscolordimmer && 2 == nvalue) || // gswitch_sSetLevel
(iscolordimmer && 15 == nvalue)) { // Color_SetBrightnessLevel (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)) { if (light_type && (Settings.light_dimmer == nvalue) && ((power >> i) &1)) {
return 1; return 1;
} }