2 Replies Latest reply on Aug 4, 2017 9:37 AM by drichter RSS
    drichter Explorer

    Get null pointer exception if property change via mqtt

    Since I change to ThingWorx 8 I have a big trouble with setting property values via mqtt.

     

    I send messages like this via mqtt to an thing (base type mqtt)

     

    { "temp":3.1,

    "brightness":11.2,

    "name":"climateSensor_3",

    "humidity":5.3,

    "pressure":6.4,

    "CO2concentration":8.5 }

     

    This message will set in a property of the thing named MQTTValue (type json). If MQTTValue change I call a subscriber which will set all properties of the think to the properties of the message:

     

    var newVal = eventData.newValue.value;

     

    me.temp = newVal.temp;

    me.humidity = newVal.humidity;

    ...

     

    I surrounded it by a try catch.

     

    Everytime I get a mqtt message where a value is changed I get an null pointer exception at the set-line.

     

    Example:

    All properties of the climateSensor_3 thing are set to 10. Now a new mqtt message arrived where every property is also 10:

    { "temp":10.0,

    "brightness":10.0,

    "name":"climateSensor_3",

    "humidity":10.0,

    "pressure":10.0,

    "CO2concentration":10.0 }


    ==> no exception


    Now a other mqtt message arrived where one property is not the same like the old value:


    { "temp":20.0,

    "brightness":10.0,

    "name":"climateSensor_3",

    "humidity":10.0,

    "pressure":10.0,

    "CO2concentration":10.0 }


    ==> null pointer exception in line "me.temp = newVal.temp;"

     

    If the message would be like this:

     

    { "temp":10.0,

    "brightness":20.0,

    "name":"climateSensor_3",

    "humidity":10.0,

    "pressure":10.0,

    "CO2concentration":10.0 }


    I get the error on line "me.brightness = newVal.brightness;"


    Another strange thing is I get the null pointer exception but the value is still changed.