Skip to main content
1-Visitor
February 28, 2018
Solved

MQTT Datachange NullPointerException

  • February 28, 2018
  • 8 replies
  • 4736 views

Hi,

 

I have a Thing (based on MQTT) with some properties. One of them is called MQTT-Value which is configurate as MQTT-Target. Than I have a subscrption on datachange of the MQTT-Value-property.

 

The subscription looks like this:

me.Environment_Humidity = eventData.newValue.value.humidity;
me.Environment_Particles = eventData.newValue.value.particles;
me.Environment_Temperature = eventData.newValue.value.temp;

...

 

Now I get an error on every time where a new mqtt-value arrives:

[message: Execution error in service script [Event.DataChange:Property.MQTT_Environment] :: Wrapped java.lang.NullPointerException (Event.DataChange:Property.MQTT_Value#1)]

 

The MQTT-Value lookes like this:

{"temp":17.540277128455315,"humidity":48.41761546496747,"particles":409}

 

If I set the MQTT-Value by hand everything works. I think this had todo with permissions. I set visibility&run time-permissions for "system"-user but this doesn't work.

 

I working with ThingWorx 8.2.1-b140

Best answer by PaiChung

Ok so potentially it is your logging that isn't working.

Please check if you have Visibility permissions for the user on the ValueStream and more importantly the Persistence Provider

It might relate to this:

https://community.ptc.com/t5/IoT-AR-Tech-Tips/Visibility-Permissions-when-logging-properties/m-p/534564#M690

 

8 replies

22-Sapphire I
February 28, 2018

It might just be that you aren't parsing the JSON properly.

did you try:

eventData.newValue.humidity;

plus you may have to cast it to a number since it is a string.

 

drichter1-VisitorAuthor
1-Visitor
February 28, 2018

I can watch the data with:

logger.warn("eventData.newValue.value.humidity");

 

and test the type with:

logger.warn("type of eventData.newValue.value.humidity");

 

eventData.newValue gives me an infotable with field time, quality and value.

22-Sapphire I
February 28, 2018

Since the logger.warn is working fine, perhaps you just need to cast it to a variable before assigning it to the property.

So just do a 

var newHumidity = ...

and me.Humidity = newHumidity