5 Replies Latest reply on Dec 11, 2017 9:02 AM by ttielebein RSS
    cacosta Newbie

    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!

      • Re: MQTT Broker Data
        ttielebein Collaborator

        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
            cacosta Newbie

            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
                cacosta Newbie

                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.