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

  • Hi,

    I have a http-retriever-data-source that gives me a 1 hour weather forecast:

    0_1563794544125_0ec90f90-dfcd-40b4-a894-cefa22eb2266-image.png

    The Value-RegEx -> hour value="01:00"><temp value="(.*?)" works and give me the temp value 18 - all fine.
    If I set the logging time to "When point value changes", Mango stored the value with the actual timestamp, but I need a timestamp with the forecast date and hour, in my example above -> day value="20190722" and -> hour value="01:00" --> 2019-07-22T01:00:00.000+2:00

    If I try in the TimeRegEx:

    0_1563795344854_baa46563-b60f-4172-9385-2f793bb1166f-image.png

    only the date is correct but the time isn't 1:00.
    Is there a way to put date and time together?


  • Hi Ralf,

    This would not be easy to achieve in an HTTP Retriever. Have you considered using the HttpBuilder script utility? You would be able to put the whole data series into the same point, in that case, as you would have the text of the response available to run as much parsing on as you need.


  • Hi phildunlap,

    that's a good idea but I find no example in the forum/docu, Do you have one?


  • Certainly!

    There are a few examples, this one is probably the most in-depth:
    https://forum.infiniteautomation.com/topic/2999/intesis-integration
    This is probably the most relevant:
    https://forum.infiniteautomation.com/topic/3251/httpbuilder-not-defined
    But there are others, and soon to be one more!
    https://www.google.com/search?q=site%3A%2F%2Fforum.infiniteautomation.com+httpbuilder

    For this, it might look like this...

    //Untested, source URL not provided
    function handleResponse(content) {
        //Why does [0-1] have a ?; does it present Jan 1 as 201911 ?
        var dayInformation = /day value="([0-9]{4})([0-1]?[0-9])([0-3]?[0-9])"/.exec(content);
        if(dayInformation === null)
            throw "Could not find date information in content";
            
        for(var k = 0; k < 24; k+=1) {
            var valueRegex = new RegExp('hour value="' + (k < 10 ? "0"+k : k) + ':00"><temp value="(.*?)"');
            var data = valueRegex.exec(content)
            if(data !== null) {
                //this timestamp should be in the server's timezone
                var timestamp = new Date(parseInt(dayInformation[1]), //year
                                         parseInt(dayInformation[2])-1, //month index
                                         parseInt(dayInformation[3]), k); //day and hours
                
                //This would be a scripting data point on the scripting data source:
                tempForecastPoint.set(parseFloat(data[1]), timestamp.getTime());
            }
        }
    }
    
    //Okay, let's pull in the data...
    var headers = {} //Maybe you need an Accept header?
    var parameters = {} //Perhaps an API token or date?
    HttpBuilder.get("sptth://thisforecastwebsite.extension", headers, parameters).err(
        function(status, headers, content) {
            throw "Script failed with HTTP status: " + status;
    }).resp(function(status, headers, content) {
        handleResponse(content);
    }).execute();
    

    Edit: And the documentation would be in the main Mango JavaScript help: https://help.infiniteautomation.com/about-mango-java-script


  • Hi phildunlap,

    thank you for the quick help and code!

    If I run at 19:00 the script it validate with the list:

    0_1563987882851_1666f48a-a22c-4355-91b9-b451dbb5fdac-image.png

    All fine, but the records end at 19:00 from 00:00 - 19:00. Data source saves historic is ON, the point logging is OFF. Are there specific settings for the logging till 24:00?

    0_1563988093218_edc4ecf6-d1f6-4a91-b9c3-9ee3f9f8453b-image.png


  • I would initially suspect the discard future dated values to be the culprit:
    0_1563990872858_discard-future-dated-values.png


  • I set 48h, no change. It only saves up to the current time: 9:00 here.

    0_1564038865667_3721379c-cabf-415f-b94c-634b0e176ce2-image.png


  • This is probably only a display issue. I would guess above that on the page it is showing the value for hour 23 as the current value, and that if you chart it for the day you will see the values in the chart. Thanks for bringing this to our attention!