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

Using http retriever returns java.net.UnknownHostException:


  • Using http retriever returns java.net.UnknownHostException:


  • How can I get the nth match of a regexp usin http retriever?


  • Hi Radu,

    UnknownHostException - DNS failed to resolve hostname.

    1. Check hostname is typed correctly
    2. Check computer running Mango can access a gateway that does DNS (ping www.google.com, does it work?)
    3. Check that hostname is resolvable in your browser.

    Getting nth match
    You'll have to say more about this and possibly provide an example. Regex has the count braces {} so a expression like (?:.*?conditionText":(\d+).*?){5} would capture the fifth instance of the text conditionText":123 and from my testing captured only the fifth instance, so it is at value capture group 1, which would be only the number since the rest of the group is noncapturing (?:) but the (\d+) captures the value.

    Edit: Also, you may consider this if there are newlines: (?s)(?:.*?conditionText":(\d+).*?){5} as (?s) is the embedded flag to enable . to match newlines.


  • I fixed the unknown host issue, but the regexp is taking too long, I'm parsing the result of:
    https://api.apixu.com/v1/forecast.json?key=07cb1ff64c1e4186afa150737172404&q=Toronto&days=2
    and tring to get 50th value


  • Hmm. Well, I noticed there are only 49 temp_c values in that link, if that's related. Regex is pretty fast, but there probably does exist a more efficient expression if the goal is to get the last value for temp_c.


  • @phildunlap said in Using http retriever returns java.net.UnknownHostException::

    Hmm. Well, I noticed there are only 49 temp_c values in that link, if that's related. Regex is pretty fast, but there probably does exist a more efficient expression if the goal is to get the last value for temp_c.

    Actually the goal is to have a point showing each value. I've tried with this regexp and the cpu goes to 100%


  • Hi Radu,

    I gave it a shot. I did notice what you're saying if I put 50 in as the group number, but that regex doesn't match anyway. I found 48 got me the last value in the set using (?:.*?temp_c":(\d+[.]\d+).*?){48} 48 matched fairly quickly, and all lower numbers should match faster.

    It sounds like you're getting each value into its own data point? You could also try something like grabbing the entire string into a regex (regex .* value index 0), and parsing it using a script like....

    if(httpForecast.time > scriptRun.time) {
        var forecast = JSON.parse(httpForecast.value);
        for( var k = 0; k < forecast.forecast.forecastday.length; k+=1 ) {
            var day = forecast.forecast.forecastday[k];
            for( var i = 0; i < day.hour.length; i += 1 ) {
                 var hour = day.hour*;
                 forecastOutputPoint.set( hour.temp_c, DateTimeUtility.parseDate("yyyy-dd-MM HH:mm", hour.time, "America/Toronto") );
            }
        }
        scriptRun.set(!scriptRun.value);
    }
    

    Where forecastOutputPoint is a Numeric point log all data on the scripting data source, and scriptRun is a binary point on the scripting data source. If I didn't make any mistakes this should have all the values appear in forecastOutputPoint any time the http gets a new forecast and the script runs to parse it.