• 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

    Pulling multiple parameters from a single JSON result

    Scheduled Pinned Locked Moved User help
    6 Posts 2 Posters 1.5k Views 2 Watching
    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.
    • P Offline
      psysak
      last edited by

      Hey hey, I was wondering if doing something like the following would be possible.

      The DarkSky API allows me to get a JSON stream of, for example, the hourly temperatures from yesterday. I've figured out a regex which allows me to find each individual temperature as a group. What I'm wondering is is there a way I can pull each one of those temperature readings in so I can average them all once a day? I was thinking maybe into an alphanumeric point and them via scripting average them?

      I have a solution which I think would work, I can just pull weather data once an hour into a "current temperature" point and then average that at the end of the day, so no rush. I just think being able to do it using one query would be way cooler (although no one will appreciate it :))

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

        Hi Psysak,

        Both those should work. If you alphanumeric matches the whole response you can do something like var response = JSON.parse(alphanum.value); and then you can process it however you like. Then trigger the script on the context update of the alphanumeric point.

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

          Hi Psysak,

          Also, you may consider using the HttpBuilder script utility. Then you can have the whole thing in a scripting data source, clean and tidy.

          There is documentation in the contextual help menu for "Mango Java Script" (which you can access through the scripting help, or the meta point help).

          Here's a thread where I posted something maybe more complex than what you're talking about: https://forum.infiniteautomation.com/topic/2999/intesis-integration

          It sounds like yours may be as simple as...

          var headers = {}
          var parameters = {}
          function handleTemperatureData(data) { /* Do stuff */ }
          HttpBuilder.get("https://someplace.wherever", headers, parameters).err(function(status, headers, content) {
            throw "Script failed with HTTP status: " + status;
          }).resp(function(status, headers, content) { //needs to be 200 status or you can set the accepted statuses
            handleTemperatureData( JSON.parse(content) );
          }).execute();
          1 Reply Last reply Reply Quote 0
          • P Offline
            psysak
            last edited by

            Thanks Phil, just trying to get back at this finally.

            1 Reply Last reply Reply Quote 0
            • P Offline
              psysak
              last edited by

              OMG man, I didn't realize what JSON.parse() did.... now I do... DAMN! :)

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

                Very powerful! I've definitely done many quick things by serializing data into an alphanumeric point with JSON.stringify(object) and getting it back elsewhere with JSON.parse(string)

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