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

  • Nope that's good. I'll come back to you soon. I've got a busy day ahead!

    Hope it's not too urgent!

    Fox


  • OK! For your query/script:

    //First we need the correct format:
        function pad(number) {
          if (number < 10) {
            return '0' + number;
          }
          return number;
        }
    
       var toISOString = function(d) {
          return d.getUTCFullYear() +
            '-' + pad(d.getUTCMonth() + 1) +
            '-' + pad(d.getUTCDate()) +
            'T' + pad(d.getUTCHours()) +
            ':' + pad(d.getUTCMinutes()) +
            ':' + pad(d) +
            '.' + (d.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
            'Z';
        };
    
    //Make your RQL query up:
    var ts = Number(CONTEXT.timestamp);
    var d = new Date();
    d.setTime(ts);
    var RQL = "eq(tags.Sender,EETest)&sort(deviceName,name)&limit(2)";
    var allPoints = DataPointQuery.query(RQL);
    var body = "Source: 83.147.156.26<br>";
    body += "Device ID: -<br>";
    body += "Time: " + d.toString() + "<br><br>"; //Two newlines
    
    //print(DataPointQuery);
    print(allPoints)
    for(var i=0; i<allPoints.length;i++)
    {
        var value = -99; //if there's an error we'll know
       var dp = allPoints[ i ];
           print(dp)
        d.setTime(dp.runtime.time);
        value = dp.runtime.last(1,true); //or pointValueAt(ts,true)
        if(value[0]){value = value[0].value;}
       body+= dp.xid+":"+value+" - "+toISOString(d)+"<br>";
    }
    return body;//Send as post 
    

    Hope this gives you something to build from. Might be beneficial if you can fire a test post into https://webhook.site so you can check the format of your message. If you can do that, you can share the post link so others can see the format you want to achieve and how it comes from mango.


  • @MattFox Thanks for the help but I'm a bit confused. Do I use this script in the Meta data point? I'm not seeing any points/point values?


  • Yes inside the meta data point. Then when you return the value, it sets that as the point's value to be fired out of the publisher

    Fox


  • Should I see the point values when I validate the script? What I get is -
    "Script result: Source: 83.147.156.26<br>Device ID: -<br>Time: Tue Jun 23 2020 10:06:04 GMT+0100 (BST)<br><br>"


  • put a print( allPoints ) under the query call. There's a chance my tag query doesn't agree with your tags and how you set them.

    EDIT: If you check the other post as I mentioned, you can check my query by pasting it into the RQL query builder in the watchlist builder page.


  • Still no luck with that. The RQL query is working fine in the watchlist builder, giving the correct 2 points back but still no data points or values when I validate the script, even after including print( allPoints ) at the end.


  • I can't remember if 3.7 lets you validate a script like 3.5 and earlier could... Thing is, that loop should be looping twice for those two data points. There has to be an error... Turn on logging and see what you can find.
    I'll do a quick test for you in the morning. It's 10:15pm here and I'm not much help right at this moment!

    Fox


  • No problem. Thanks.


  • I've made some amendments (copy from above) - sure enough the data we needed was inside the runtime property. BUT I found the solution!
    The sodding datapoint query doesn't work in 3.7 without setting the script permissions.
    Normally these were populated by default, but this is no longer the case. In this case, make the script permission run as superuser to get your points through, or at least the user allowed to read those points.

    Once you've done that you'll be away!

    Fox