ottopaulsen / MMM-MQTT

MQTT Client module for MagicMirror2
MIT License
57 stars 29 forks source link

Value is mostly 'Undefined' when Json data does not every time contain the parameter and value (with solution) #48

Open thellekamp opened 3 years ago

thellekamp commented 3 years ago

I am using Domoticz. Domoticz does not send the exact same json packet each time. So most of the time (10 seconds) the value of interest is shown as 'Undefined' and the real value is only shown for an instant. As this was not happening in an old version of MMM-MQTT, I could quickly find a solution, which does the job for me.

I made a small change in de MMM-MQTT.js code:

The location: // Extract value if JSON Pointer is configured if (sub.jsonpointer) { value = get(JSON.parse(value), sub.jsonpointer); }

//.. new test if value exists...
if (isNaN(value) == false) { ..the rest of the .code.... }

thellekamp commented 3 years ago

I realize the solution will not work on text values. Better solution:

//.. new test if value exists... if (value != null) { ..the rest of the .code.... }