• M
    MaP

    I have to log the API data and add it to an existing modbus connection the mango has with a PLC so the PLC and a SCADA system can make decisions/control options based on the data.

    Things are so much easier with less secure connections! Certificate chains and such give me headaches. Its sounding like I will need to perhaps make a python script on the mango OS call it on boot and then also add a API connection to write from the python script into a mango data point. Was hoping for an easy win, alas.

    posted in User help read more
  • M
    MaP

    I noticed you could POST to https requests using httpbuilding - such as the slack integration.

    function notifyToSlack(text, attachments) {
    var url = "https://hooks.slack.com/services/xxxxxxx/yyyyyy/zzzzzzzzzzzzzzzzzzzzzzzzzz";
    var headers = {
    "Content-Type": "application/json"
    };
    var data = {
    "text": text,
    "attachments": attachments
    };
    HttpBuilder.post(url, headers, data).err(function(status, headers, data) {

        throw "Script failed with HTTP status : " + status;
    
    }).resp(function(status, headers, data) {
    
        "Hallo" 
    
    }).execute();
    

    }

    posted in User help read more
  • M
    MaP

    Apprently I need to Generate a Certificate Signing Request (openSSL?) - Then
    the Organisation Validates CSR.

    Organisation Generates the SSL certificate from the CSR.
    Distributes the Certificate details:
    a. Users public certificate
    b. Gateway public certificate
    c. CA certificate

    posted in User help read more
  • M
    MaP

    I have done a bit of quick research into Basic Auth and Client Certs and unfortunately its a valid combination apparently. Im double checking but the documentation says you need your basic auth credentials and a certificate. The api requests are all https requests.

    I was hoping mango would be able to manage it without having to introduce another cloud server or service to manage the data feed. Trying to figure out if it can be done in a meta data source, a scripting source, or perhaps a python script. Keeping it in mango reduces networking requirements and complexity.

    The documentation recommends testing with Postman where you can specify Basic Auth as the Authentication for base64 encoded credentials added to the headers and then add a Client side certificate through the Postman Security settings for client SSL certificates.

    posted in User help read more
  • M
    MaP

    Does mango's httpbuilder support client certificates? I would like mango to connect to an API using Basic Auth and a SSL/TLS client certificate to get some information to transfer to an existing PLC to control a plant. There is an existing modbus connection between Mango and the PLC. Does anyone have a recommendation on the best method to achieve the API integration in Mango?

    posted in User help read more
  • M
    MaP

    updated code snippet with 3 points and a timestamp array concatenated then emailed

    //your code here
    //Query to Retrieve and rollup previous 24 Hours Data
    var endDate = CONTEXT.getTimestamp();
    var startDate = endDate - CONTEXT.millisInPast(MINUTE, 4); //handles DST shenanigans
    var results = [];
    var callback = function(idValueTime) {
      results.push(idValueTime);};
    //var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
    PointValueQuery.rollupQuery( [341,342,282], startDate, endDate, callback, AVERAGE, 1, MINUTE);
    print(results);
    
    //Date and time Variables
    var d = new Date();
    var t = new Date().getTime();
    var y = d.getYear()-70;
    var m = d.getMonth();
    var dayinmonth = d.getDate();
    var hours = d.getHours();
    //ECMA function to convert date to locale string YYYY-MM-DD
    var datestring = d.toLocaleDateString();
    //Substr fX to make date DD-MM-YYYY time format
    var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
    var CSVname = "Performance_"+ddmmyyyy+".csv";
    
    //Creating DateTime For Array
    // 31556926000 mS in Year
    // 2629743000 ms in Month
    // 86400000 ms in Day
    //3600000 ms in an Hour
    //print(results[0].toString()+d.toString()+"\r\n");
    var coeff = 1000 * 60 * 1;
    var date = new Date();
    //var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);
    
    //var csvData =[];
    var csvData ="kW,Timestamp\r\n";
    var TimeWatch = [];
    results.forEach(function(results,index){
        //csvData[index]=results+","+TimeAgo+"\r\n";
        var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);
        TimeWatch[index]=TimeAgo;
        if((index+1)%3<1){
        TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+((index-2)/3)*60000);    
          csvData = csvData+results+","+TimeAgo+"\r\n";  
        }
        else{
            csvData = csvData+results+",";
        }
    });
    //csvDataString = csvData.toString();
    print(csvData);
    //print(TimeWatch);
    /*
    var recipients = ["funtimes84@live.com"];
    var emailContent = new com.serotonin.web.mail.EmailContent(null, 
      "Email body content", com.serotonin.m2m2.Common.UTF8);
    var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
      "PerformanceCSV"+datestring+".csv", csvDataString.getBytes());
    
    emailContent.addAttachment(emailAttachment);
    com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "NorthamCSV_"+ddmmyyyy, emailContent, null);
    */
    

    posted in User help read more
  • M
    MaP

    this seems to have worked i had trouble using arrays with a ,toString function where the "," was appearing in the final csv string - ie)
    Head1,Head2
    Val1,time1
    ,Val2,time2
    ,Val3,time3

    Using Strings seems to ahve gotten the correct output but im worried a string variable might get angry when it contains 1440*7 Values/time

    code so far --

    //Query to Retrieve and rollup previous 24 Hours Data
    var endDate = CONTEXT.getTimestamp();
    var startDate = endDate - CONTEXT.millisInPast(MINUTE, 4); //handles DST shenanigans
    var results = [];
    var callback = function(idValueTime) {
      results.push(idValueTime);};
    var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
    PointValueQuery.rollupQuery( [341], startDate, endDate, callback, AVERAGE, 1, MINUTE);
    print(results);
    
    //Date and time Variables
    var d = new Date();
    var t = new Date().getTime();
    var y = d.getYear()-70;
    var m = d.getMonth();
    var dayinmonth = d.getDate();
    var hours = d.getHours();
    //ECMA function to convert date to locale string YYYY-MM-DD
    var datestring = d.toLocaleDateString();
    //Substr fX to make date DD-MM-YYYY time format
    var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
    var CSVname = "Performance_"+ddmmyyyy+".csv";
    
    //Creating DateTime For Array
    // 31556926000 mS in Year
    // 2629743000 ms in Month
    // 86400000 ms in Day
    //3600000 ms in an Hour
    //print(results[0].toString()+d.toString()+"\r\n");
    var coeff = 1000 * 60 * 1;
    var date = new Date();
    //var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);
    
    //var csvData =[];
    var csvData ="kW,Timestamp\r\n"
    
    results.forEach(function(results,index){
        //csvData[index]=results+","+TimeAgo+"\r\n";
        var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);
        csvData = csvData+results+","+TimeAgo+"\r\n";
        
    });
    //csvDataString = csvData.toString();
    print(csvData)
    

    posted in User help read more
  • M
    MaP

    So far so good. Query works, Email attachment works, and can seperate rows using /r/n. Not sure what variable type is returned by the query but its returned as number,number, so i presume its a string? will Need to transpose over the query to insert /r/n i believe and then construct a corresponding time array for every minute of previous 24 hours for second colomn.

    var endDate = CONTEXT.getTimestamp();
    var startDate = endDate - CONTEXT.millisInPast(MINUTE, 4); //handles DST shenanigans
    var results = [];
    var callback = function(idValueTime) {
      results.push(idValueTime);};
    var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
    PointValueQuery.rollupQuery( [341], startDate, endDate, callback, AVERAGE, 1, MINUTE);
    print(results);
    
    
    var d = new Date();
    //ECMA function to convert date to locale string YYYY-MM-DD
    var datestring = d.toLocaleDateString();
    //Substr fX to make date DD-MM-YYYY time format
    var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
    var CSVname = "Performance_"+ddmmyyyy+".csv";
    print(CSVname);
    /*
    var recipients = ["funtimes@live.com"];
    var emailContent = new com.serotonin.web.mail.EmailContent(null, 
      "Email body content", com.serotonin.m2m2.Common.UTF8);
    var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
      "attached"+datestring+.csv", "Head1,Head2\r\n12,22".getBytes());
    
    emailContent.addAttachment(emailAttachment);
    com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "Attachment test", emailContent, null);
    */
    

    posted in User help read more
  • M
    MaP

    Help is always nice, its nice to struggle with progress but also a point where going in circles becomes painful.

    Ahh so the ByteArrayAttachment doesn't create a file on the filesystem but just creates the file on the fly in the meta source and names it "attached.txt, with "attatched text" being the content of that file?

    posted in User help read more