cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Get null pointer exception if property change via mqtt

drichter
14-Alexandrite

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.

1 ACCEPTED SOLUTION

Accepted Solutions
drichter
14-Alexandrite
(To:drichter)

Now I get it =)

In this post from Pai Chung: Visibility Permissions when logging properties helps me out. I have to add Visbility to the Persistence Provider of the ValueStream. Which is not so easy.

You have to go to your ValueStream and click on ThingworxPersistenceProvider and click on View. Than you must start the AddVisibilityPermission-Service of the PersistenceProvider:


principal: Everyone

principalType: Organization


After that the ValueStream will work

View solution in original post

2 REPLIES 2
drichter
14-Alexandrite
(To:drichter)

Maybe I have the issues but not the solution.

If I remove the ValueStream I don't get the null pointer exception. I tested it with other things and the same result. The ValueStream causes the trouble.

Now I try to

  • add Everyone (includes System) to Visibility of ValueStream
  • add System to Run Time Permission (read, write, event, subscribe, execute)
  • add System to Design Time Permissions (read, update, delete)

But this helps me not =(

drichter
14-Alexandrite
(To:drichter)

Now I get it =)

In this post from Pai Chung: Visibility Permissions when logging properties helps me out. I have to add Visbility to the Persistence Provider of the ValueStream. Which is not so easy.

You have to go to your ValueStream and click on ThingworxPersistenceProvider and click on View. Than you must start the AddVisibilityPermission-Service of the PersistenceProvider:


principal: Everyone

principalType: Organization


After that the ValueStream will work

Top Tags