I am currently utilizing the MQTT extension for Thingworx and have made a connection to my gateway. However, it seems that my gateway is publishing JSON messages to Thingworx in the form of Strings. Is there any way to parse the strings and extract the data from the message to apply it to different properties? There are multiple values being published onto the string, from the topic requested.
Any help or feedback would be much appreciated.
Hey, so I don't know if there is a way to parse it before it gets to the Platform, if that is what you are asking. You should be able to accomplish this, though, if you map a property to receive the full string, and then create a data change event for that property which parses the string and updates the other properties. I hope this helps!
I have mapped the property and it is receiving the full string, however when using the data change event it does not transfer the data over to the new property. I am using sample code I found through this community that is described to resolve the issue I am having. I have also changed the new property's base type to Number
var array = JSON.parse("[" +me.BRIGHTNESS+ "]")
logger.info("Value: " + array.val);
logger.info("TypeID: " + array.hm_addr);
me.BRIGHTNESS_VALUE = parseFloat(array.val);
Again, any feedback would be much appreciated.
I just resolved the string issue and it is now coming in as its original JSON form after re-configuring my gateway. However I am still having the data change issue where I can not extract the value needed for my property. I am using the data changed event subscription and my line reads as:
me.Temperature1 = me.temp.temp1;
I have also changed the Run Time Instance for the Thing Template so that I have access to property write but it is still not transferring the data between the two topics. I have also incorporated a screen shot below of the property window.
Hey what happens if you output a message to the logs with the values me.temp and me.temp.temp1? You can use "logger.info("me.temp = " + me.temp + "; me.temp.temp1 = " + me.temp.temp1");" and make sure your script log is set to allow info statements.
i have developed Mqtt Sample application. now it is successfully completed. but i want to publish Json message on single topic.but its not getting correctly so please help me