• MattFox

    I've written a few scripts/dashboards that involve irrigation in mango. Due to IP I cannot share it. I can definitely agree with the idea of using the advanced scheduler as that allows you to use time when to fire and set a duration.
    However if they are always sequential and you know that you will always have a fixed amount of sprinkler zones to work with I suggest doing a dashboard that involves the use of slider inputs to set your duration either in minutes or percentage (if your time will never exceed n minutes) and perhaps the same for a delay tied to a virtual data point. And also a binary datapoint with a <ma-switch) to toggle a zone on or off.
    As Phil suggests if you've got a PLC in the mix definitely use that as I'm sure you must have some sort of real time clock you can work from to generate the interrupts you need. Then map those to the settings generated via mango. ie timer ticks etc

    I'm not hugely aware of how your system is constructed. At least by every time you make an amendment to these settings, you can either make it trigger an update via the scripting source to push these settings down the line. Otherwise set it to have an hourly (or whatever is needed) push for the settings.

    Happy to give more input if you can describe how the system works. Sorry I don't use modbus so I cannot help a great deal in that area.

    posted in Mango Automation general Discussion read more
  • MattFox

    I've been working more on it and I get the feeling that I'm not properly getting the pointValue times right.
    I've been using CONTEXT.getRuntime() but I strongly get the feeling that this value is constant for when the script is fired - including when I do a force recalculate history.
    I've the metadata point itself. the variable name IE. events is a virtual datapoint I was hoping to try and catch the data into but I'm thinking I might just leave it in the meta point so I don't double up.
    The other is supposed to be when I've got a pump running. Sorry Phil I'm running circles round myself here!

    var ROLLUPMINS  = 15; 
    var numberOfVals = 2; //I want two values, now, and the previous.
    var MS_PER_MINUTE = 60000;
    var from = new Date(CONTEXT.getRuntime() - (ROLLUPMINS* numberOfVals * MS_PER_MINUTE) );
    var values = [];
    //print(from);
    
    var valueCallback = function( value, index ) { //function definition in com.infiniteautomation.mango.db.query.PVTQueryCallback
      // print(value);print(index);
     // LOG.info(value);
       values.push( value );
    };
    //values.push(volume.last(2) );
    //values.push(volume.last(0));
    //print(volume.lastValue(1));
    //print(volume.pointValuesSince(from));
    
    
    PointValueQuery.query( 
        [ volume.getDataPointWrapper().getId()],
        from.valueOf(), 
        CONTEXT.getRuntime(),
        false, 
        valueCallback);  
    
    print( values );
        
    /*    PointValueQuery.query( 
        [ volume.getDataPointWrapper().getId()],
        _24th, 
        _25th,
        false, 
        valueCallback);  */
    
    
    // Start Date:
    function getEventData(status, headers, content) { //setResponseCallback
    	var data = content;//	print(status);
    //	print(data);
    	 data = JSON.parse(data);
        //print(data.jsonData.startTime);
        data.jsonData.endTime=values[0].time;
        return JSON.stringify(data.jsonData),data.jsonData.startTime;
    }
    
    /*
    if( values[1].value!=values[0].value && values[0].value==0 )
    {
        print("va1 > val2");
        LOG.info("va1 > val2");
        return "va1 > val2";
    }
    
    if( values[1].value!=values[0].value && values[1].value==0 )
    {
        print("va1 < val2");
        LOG.info("va1 < val2");
        return "va1 < val2";
    }*/
    
    print(IE.lastValue().value);
    if( 0<values[1].value && values[0].value==0 )
    {
       
        LOG.info(IE.value);
        if(IE.lastValue().value=='')
        {
            LOG.info(values[0].time);
            var tmp = {
              title:"Commencing "+ new Date(parseInt(values[0].time)).toLocaleString("NZST"),
              startTime:values[0].time,
              endTime:''
            };
    
           events.set( JSON.stringify(tmp) ,values[0].time);
           IE.set(JSON.stringify(tmp),values[0].time);
    
        }
        else
        {
             var last = JSON.parse(IE.lastValue().value);
             if(last.endTime.length)
             {
            LOG.info(values[0].time);
            var tmp = {
              title:"Commencing "+ new Date(parseInt(values[0].time)).toLocaleString("NZST"),
              startTime:values[0].time,
              endTime:''
            };
    
           events.set( JSON.stringify(tmp) ,values[0].time);
           IE.set(JSON.stringify(tmp),values[0].time);
    
             }
        }
    }
    
    //end date
    
    if( values[1].value==0)
        var tmp = JSON.parse(IE.lastValue().value);
        tmp.endTime = values[1].time;
        IE.set( JSON.stringify(tmp), tmp.startTime  );
        events.set( JSON.stringify(tmp), tmp.startTime  );
    }
    

    posted in How-To read more
  • MattFox

    What phil said, but there is no reason why you cannot run a script on client mango systems and store all information into alphanumeric point which fires on an alert. At least then you could view it on a dashboard in realtime that way.

    posted in User help read more
  • MattFox

    My way of doing this involves publishing the uptime datapoint and if it doesn't update after 30mins I fire an email event.

    posted in User help read more
  • MattFox

    Just so I understand correctly. You want all values to appear in the same row in order for a given day/hour?
    Timestamps will differ as no two values will ever come in at the same time.
    But for those that do, you want them appended on the same line. Correct?

    To make things easier, it might be better to average all of your points so all timestamps match then you can list columns as a

    timestamp,datapoint1,datapoint2
    

    format.
    Let me know your thoughts

    Fox

    posted in How-To read more
  • MattFox

    What's wrong with the time format?
    Are you opening the csv with excel or something like notepad?

    posted in How-To read more
  • MattFox

    Thanks Phil I'll try your advice. By the end of it all I got to the point of throwing caution to the wind and aimlessly trying anything to ensure I could get things formatted correctly and in the right order. I'll look at giving more detail tomorrow.

    Fox

    posted in How-To read more
  • MattFox

    As the title says (hopefully) I'm trying to capture whilst a value transitions from being zero to anything above zero and then from a value back to zero; and store those timestamps into a metapoint/virtual datapoint.
    By doing this it means I can have a user select from a drop down a chosen event (in chronological order) which will provide the starting and end timestamps for the data I need.
    I've been trying to capture this in a metadata point and I'm just having no luck. I even went as far as using the JSON rest api to store data as a placeholder so once I have both the start and end of an 'above 0' period the values are stored into the datapoint.
    And no prevail.
    Has anyone got any ideas or what I could do to implement and ensure I obtain the desired script behaviour?

    I check between two values to see the status and if there is a change and the value is zero I take a snapshot.

    //Start Date
    // 0 --> .>0
    if( values[1].value>values[0].value && values[0].value===0 )
    {
        var tmp = {
          title:"Commencing "+  new Date(parseInt(values[0].time)).toLocaleString("NZST"),
          startTime:values[0].time,
          endTime:''
        };
       // setJSONStore("Effluent-Pump-1","user",tmp);
       events.set( JSON.stringify(tmp) );
       return JSON.stringify(tmp);
      
    }
    
    //end date
    // >0  --> 0
    if( values[1].value<values[0].value && values[1].value===0 )
    { 
        //getJSONStore("Effluent-Pump-1","user",getEventData,{}); //custom global script I threw together.
        var tmp = JSON.parse(IE.value);
        tmp.endTime = values[1].time;
        IE.set( JSON.stringify(tmp), volume.lastValue.time  );
    events.set( JSON.stringify(tmp), volume.lastValue.time  );
    }
    

    posted in How-To read more
  • MattFox

    @iperry said in Exporting Excel reports to csv:

    The part I was missing was using the subclass FileAttachment. doh

    Yep, having the EmailAttachment class as an abstract class means it cannot be instantiated. Gotta use the public child classes.

    posted in User help read more