• 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

    HttpBuilder not defined

    User help
    3
    14
    2.2k
    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.
    • Jared WiltshireJ
      Jared Wiltshire
      last edited by

      @psysak You will have to post the script you are talking about. A meta data point script?

      Developer at Radix IoT

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

        Almost assuredly that ES is not up to date. if you update Mango, you should have the HttpBuilder in your script's context in all script areas.

        1 Reply Last reply Reply Quote 0
        • P
          psysak @Jared Wiltshire
          last edited by

          @jared-wiltshire Hey, of course! sorry about that. Let me see if updating it helps.

          @phildunlap hmmm... what version did that functionality appear in? The Mango in question that I will be loading it into is still a v2.8.

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

            The release notes suggest 3.2.2: https://github.com/infiniteautomation/ma-core-public/blob/main/Core/RELEASE-NOTES

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

              Here's the script, this is part of a scripting data source.

              var headers = {}
              var parameters = {}
              var regex = '{\"time\":(\\d*),.*?\"temperature\":(-?\\d*\\.?\\d*).*?\"daily\".*?{.*?\[.*?\"time\":(\\d*),.*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?\"temperatureHigh\":(-?\\d*\\.?\\d*).*?]';
              var match;
              
              // This is the function which parses the returned data from DarkSky
              // The passed variable "data" is the actual JSON contents returned
              function handleTemperatureData(data) {
              
                 // The var match is an array which results from parsing the data through the regex
                 // Each element of the array is an individual value where
                 // match[1] returns current time
                 // match[2] returns the current temperature
                 // match[3] is a time value for the first forecast value
                 // match[4-11] are the daily forecast high temperatures
                 match = RegExp(regex).exec(data);
              
                  var k;
                  
                  // This is required because the way that DarkSky returns data sometimes 
                  // the first "forecast" data point is actually still a forecast temperature
                  // for today. If this is the case then we have to skip this value otherwise
                  // the forecast for tomorrow will actually be the forecast for today etc
                  if(match[3] < match[1]) { 
                      // This means that the first reading is for today, skip it and use the 
                      // next value as a starting point
                      k = 5;
                  } else {
                      k = 4;
                  }
              
                  if(match.length >= 11) {
                      CurrentTemp.set(match[2]);
                      OneDayForecastTemp.set(match[k]);
                      TwoDayForecastTemp.set(match[k+1]);
                      ThreeDayForecastTemp.set(match[k+2]);
                      FourDayForecastTemp.set(match[k+3]);
                      FiveDayForecastTemp.set(match[k+4]);
                      SixDayForecastTemp.set(match[k+5]);
                      SevenDayForecastTemp.set(match[k+6]);
                      
                  }
              } // End of function
               
              // This portion is the part which actually retreives the data from DarkSky
              HttpBuilder.get("https://api.darksky.net/forecast/token/45.321488,%20-75.671071?units=si&exclude=minutely,hourly", 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
                 // If all is well then call the parsing function and pass the JSON to it
                 handleTemperatureData(content);
              }).execute();
              

              Is there any way to duplicate this functionality on a V2 Mango ES?

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

                No trivial way.

                If you know the headers you need in that GET (no dynamic request construction), you could put the whole GET HTTP request into the Query command of an alphanumeric TCP/IP point (don't forget the trailing \n\n in HTTP, and a \n between header rows)

                So probably a query command like (you may need to experiment with removing the Host header, adding Content-Type, whatever. The easiest would be making the request in the browser with the developer tools open, then you can see a working request's [probably excessive] headers),

                GET /forecast/token/45.321488,%20-75.671071?units=si&exclude=minutely,hourly HTTP/1.1\nHost: api.darksky.net\n\n
                

                Then from your script you can do

                RuntimeManager.refreshDataPoint("DP_TCPIP_HTTP_Magic");
                var response = tcpIpHttpMagicContextPoint.value;
                
                1 Reply Last reply Reply Quote 0
                • P
                  psysak
                  last edited by

                  It's all good, I'll see if about upgrading that unit and it not simplifying something down for this particular instance.

                  As always thank you!

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

                    Most welcome!

                    Could always publish this to it from the updated Mango. The Persistent TCP publisher or HTTP publisher would probably work.

                    MangoES's do have 2-->3 upgrade pricing available but not through the store.

                    The TCP/IP data point solution may not be so bad.

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

                      @phildunlap to publish I would need to be able to connect into the V2 mango right? That ES is on a customer site and I don't know how willing they would be to let me open up ports sadly :(

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

                        Correct. There may still be options like a reverse SSH tunnel to leave connection initiation in the hands of the client-housed device. Was just a thought!

                        It looks like if there was a regex solution to the first forecast changing the group number you're starting at, then the HTTP retriever data source would be an option.

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

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • P
                            psysak
                            last edited by

                            OK I think I came up with something else. I use the HTTP Retriever, pull the entire string into an alpha point and then simply pass that alpha point into my original script and let regex do it's thing. I think that works!

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

                              Good solution!

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