• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Sending JSON objects via MQTT

    User help
    json mqtt
    3
    12
    5.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      silvia
      last edited by

      Hi,

      I'm trying to set up a data point from an MQTT data source. The data received will be a JSON object with timestamp.

      Do you have any documentation regarding the configuration of the 'subscribe topic', as the blue '?' next to 'Point details' gives an eror? (Document id not found: mqttClientPP)

      I'm having issues knowing what to write on the JSON value path, JSON timestamp path and JSON timestamp pattern. If I subscribe as a 'plain' topic type, then I receive the complete object but I don't see how to access the different properties, and if I subscribe as a JSON, then it says that the path must start with a '$'....

      Any ideas please? Thanks :)

      Silvia

      1 Reply Last reply Reply Quote 0
      • S
        silvia
        last edited by

        Some more information on the issue, as I'm still unable to work around it.

        This is what I'm sending (or trying to) via MQTT:

        {"M001":{"timestamp":1499441290602,"reading":2000},
        "M002":{"timestamp":1499441290602,"reading":3000}}
        

        When the data point is configured as a JSON subscribe topic type, as below:

        0_1499679906864_data point config.JPG

        Mango throws an ERROR.

        ERROR 2017-07-10T10:25:09,112 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
        tDataSourceRT.messageArrived:415) - Error during read topic: "test/array2" datap
        oint: "RPi - M001_RPi" payload: "{"meterOne":{"timestamp":1499678815845,"reading
        ":2000},"M002":{"timestamp":1499678815845,"reading":3000}}" exception: "ERROR"
        

        Help doesn't work to see how to configure the JSON subscriber :(
        0_1499678864133_help not working.JPG

        If the JSON value path is set to '$.M001', this is the error received:

        ERROR 2017-07-10T10:43:04,379 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
        tDataSourceRT.messageArrived:415) - Error during read topic: "test/array2" datap
        oint: "RPi - M001_RPi" payload: "{"M001":{"timestamp":1499679891268,"reading":20
        00},"M002":{"timestamp":1499679891268,"reading":3000}}" exception: "com.serotoni
        n.json.type.JsonObject cannot be cast to com.serotonin.json.type.JsonString"
        

        If the data point is configured as 'Plain', then the terminal throws no errors and the message is sent to Mango. I'm trying to access the object named "M001" in different ways, as below:

        <div layout="column" layout-fill flex>
            <md-card flex>
                <ma-get-point-value point-xid="RPi_M001_reading" point="array2"></ma-get-point-value>
               
                <li> array2.value: {{array2.value}}</li>
                <li>array2.value[1]: {{array2.value[1]}}</li>
                <li>array2.value.M001: {{array2.value.M001}}</li>
                <li>array2.value["M001"]: {{array2.value["M001"]}}</li>
                <li>array2.value[M001]: {{array2.value[M001]}}</li>
        
            </md-card>
        </div>
        

        And these are the results:

        0_1499679600490_results.JPG

        I can 'read' the whole string, but I can't individually access the object properties.

        Can anyone offer any support please, as I'm running out of ideas?

        Thanks in advance and have a great day :)

        1 Reply Last reply Reply Quote 0
        • phildunlapP
          phildunlap
          last edited by phildunlap

          Hi Silvia,

          Huh, that's confusing. I notice that in the first error provided the key M001 doesn't exist, for some reason it is "meterOne" then in the second it makes sense it didn't think {"timestamp":1499679891268,"reading":2000} was a string. It seems like the whole value path may be different by the page spacing (looks like your second path is longer), but we can't see the value path in the second image.

          The first error image probably just means key not found in the object, but the error messaging does look like it has room for improvement.

          Perhaps Jared or Will can advise you on how to do that dashboarding. It's going to have to involve parsing the string value into an object... some JSON.parse() type thing.

          1 Reply Last reply Reply Quote 0
          • Jared WiltshireJ
            Jared Wiltshire
            last edited by

            @silvia said in Sending JSON objects via MQTT:

            If the JSON value path is set to '$.M001', this is the error received:
            ERROR 2017-07-10T10:43:04,379 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
            tDataSourceRT.messageArrived:415) - Error during read topic: "test/array2" datap
            oint: "RPi - M001_RPi" payload: "{"M001":{"timestamp":1499679891268,"reading":20
            00},"M002":{"timestamp":1499679891268,"reading":3000}}" exception: "com.serotoni
            n.json.type.JsonObject cannot be cast to com.serotonin.json.type.JsonString"

            This would be because the data type is set to Alphanumeric while the JSON path you specified is for an object. If you set the datatype to plain it doesn't try and parse the JSON so it works.

            As Phillip said, check your usage of meterOne vs M001

            Re. parsing out the individual components of the JSON object on the dashboards, I'd recommend not doing this, you wont be able to use the datapoints effectively on any of the Mango pages.

            Developer at Radix IoT

            S 1 Reply Last reply Reply Quote 0
            • S
              silvia @Jared Wiltshire
              last edited by

              @phildunlap and @Jared-Wiltshire, thank you both for your replies.

              The issue with M001 vs meterOne isn't there anymore, at some point I decided to change the identifier to see if that was the problem, and I screenshoted some old error. Apologies for that. As you can see, when everything is named M001, the same error appears:

              ERROR 2017-07-17T09:18:36,296 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
              tDataSourceRT.messageArrived:415) - Error during read topic: "test/array2" datap
              oint: "RPi - M001_RPi" payload: "{"M001":{"timestamp":1500279612733,"reading":20
              00},"M002":{"timestamp":1500279612733,"reading":3000}}" exception: "ERROR"
              

              @Jared-Wiltshire said in Sending JSON objects via MQTT:

              Re. parsing out the individual components of the JSON object on the dashboards, I'd recommend not doing this, you wont be able to use the datapoints effectively on any of the Mango pages.

              Any alternatives to this? Is there any other format / data type that would allow me to send similar data (a meter identifier, a reading and a timestamp) x 4?

              Thanks and regards.

              1 Reply Last reply Reply Quote 0
              • Jared WiltshireJ
                Jared Wiltshire
                last edited by

                @silvia what exactly are you trying to achieve? If the goal is to simply read the two values into Mango then create two data points, both with Data type set to Numeric. The Topic type should be JSON and the JSON value path should be $.M001.reading for one, and $.M002.reading for the other. If this doesn't work then there may be a bug in the MQTT datasource.

                Developer at Radix IoT

                1 Reply Last reply Reply Quote 0
                • S
                  silvia
                  last edited by

                  Hi @Jared-Wiltshire,

                  Yes, my objective is to read them and then compare the M001.reading with the previous one, see which is the increment (if any), plot it, etc.

                  I've configured new datapoints as instructed (same for M002):
                  0_1500366256813_4292bfa1-4b88-4c95-b82b-3366c78ac43a-image.png

                  ...and these are the errors thrown:

                  ERROR 2017-07-18T09:19:19,813 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
                  tDataSourceRT.getJsonValue:375) - ERROR
                  ERROR 2017-07-18T09:19:19,813 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
                  tDataSourceRT.messageArrived:415) - Error during read topic: "test/array2" datap
                  oint: "RPi - RPi_M001_reading_new" payload: "{"M001":{"timestamp":1500366055687,
                  "reading":2000},"M002":{"timestamp":1500366055687,"reading":3000}}" exception: "
                  ERROR"
                  ERROR 2017-07-18T09:19:19,954 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
                  tDataSourceRT.getJsonValue:375) - ERROR
                  ERROR 2017-07-18T09:19:19,954 (com.infiniteautomation.m2m2.mqtt.client.MqttClien
                  tDataSourceRT.messageArrived:415) - Error during read topic: "test/array2" datap
                  oint: "RPi - RPi_M002_reading_new" payload: "{"M001":{"timestamp":1500366055687,
                  "reading":2000},"M002":{"timestamp":1500366055687,"reading":3000}}" exception: "
                  ERROR"
                  

                  I'm afraid that there's a bug in the MQTT datasource.
                  Would any of you guys be able to have a look into it?

                  Thanks :)

                  1 Reply Last reply Reply Quote 0
                  • S
                    silvia
                    last edited by

                    Hi @Jared-Wiltshire , @phildunlap

                    Have any of you had a chance of looking into this bug?

                    Cheers :)

                    Jared WiltshireJ 1 Reply Last reply Reply Quote 0
                    • Jared WiltshireJ
                      Jared Wiltshire @silvia
                      last edited by

                      @silvia Sorry there hasn't been any follow up. We have been sending a few emails backwards and forwards about this. I'll see where we got to and reply back today.

                      Developer at Radix IoT

                      1 Reply Last reply Reply Quote 0
                      • phildunlapP
                        phildunlap
                        last edited by

                        I have sent you an email Silvia!

                        1 Reply Last reply Reply Quote 0
                        • S
                          silvia
                          last edited by

                          Thanks @phildunlap , I'll try what you've sent me asap and post the results back here :)

                          1 Reply Last reply Reply Quote 0
                          • Jared WiltshireJ
                            Jared Wiltshire
                            last edited by

                            @silvia We have made a v3.1.2 release of the MQTT data source which should rectify the issues you were experiencing.

                            There we some bugs around referencing values inside JSON objects so we decided to switch the notation over to the JSON pointer spec. Your existing points with $. type notation will be automatically converted and hopefully should just work.

                            I've added a help document to the data point edit page for MQTT too (click the blue help icon).

                            Developer at Radix IoT

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post