Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
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
Solved! Go to Solution.
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:
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.
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.
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
Nope, this does not work either :/
Now I on a older thingworx maschine (8.1.1-b108) and I have the same problem.
I think the problem have something todo with the property writes of me.xxx. I change my subscription code to this:
try { var newValue = eventData.newValue.value; var newHumidity = newValue.humidity; var newParticles = newValue.particles; var newTemperature = newValue.temp; me.Environment_Humidity = 1; me.Environment_Particles = 2; me.Environment_Temperature = 3; } catch(err) { logger.error("Error on line " + err.lineNumber + ": " + err.message); }
So you can see I add some numbers and ignore the mqtt stuff. The mqtt value will changed every 5s (means every 5 seconds the subscription will be called). Now I get this errors (every entry is 5s apart):
The values in the thing are changed (each with 5 seconds distance).
If I set DataChange of my properties (Environment_Humidity, Environment_Particles, Environment_Temperature) to "Never" I get no errors and the values will be set. But than I can't log the value history.
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:
Thx this works :)