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

MQTT Broker Data

Highlighted
Visitor

MQTT Broker Data

Hello,

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.

Thank you!

Tags (1)
6 REPLIES 6

Re: MQTT Broker Data

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!

Re: MQTT Broker Data

Hi Tori,

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[0].val);

logger.info("TypeID: " + array[0].hm_addr);

me.BRIGHTNESS_VALUE = parseFloat(array[0].val);

Again, any feedback would be much appreciated.

Christian Acosta

Re: MQTT Broker Data

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.

Re: MQTT Broker Data

JSON message come into temp property:

{"q":192,"s":9,"c":7,"t":"2017-12-07T16:32:58Z","temp2":19.8,"temp1":20.1}

Re: MQTT Broker Data

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.

Re: MQTT Broker Data

Hello,

          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 

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________