• Recent
    • Tags
    • Popular
    • Register
    • Login

    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 Mango 5 Documentation Website

    How to set the poll times of a data source into a data point?

    Scripting general Discussion
    1
    1
    805
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • phildunlapP
      phildunlap
      last edited by phildunlap

      I just received this question over the phone. You can do it using a script like the following (this one is an active script on a set point event handler)

      var dsxid = "DS_Poll_Test";
      var dsvo = com.serotonin.m2m2.db.dao.DataSourceDao.instance.getByXid(dsxid);
      var dsrt = com.serotonin.m2m2.Common.runtimeManager.getRunningDataSource(dsvo.getId());
      //It must be a polling data source for this to work
      var pollTimes = dsrt.getLatestPollTimes();
      TIMESTAMP = pollTimes[pollTimes.length-1].key; //Set the time for the value to the time of the poll
      return pollTimes[pollTimes.length-1].value; //get the duration in milliseconds
      

      And here is the JSON from the test configuration:

      {
         "dataSources":[
            {
               "xid":"DS_Poll_Test",
               "name":"vrt",
               "enabled":true,
               "type":"VIRTUAL",
               "alarmLevels":{
                  "POLL_ABORTED":"URGENT"
               },
               "purgeType":"YEARS",
               "updatePeriodType":"SECONDS",
               "polling":true,
               "updatePeriods":5,
               "editPermission":"",
               "purgeOverride":false,
               "purgePeriod":1
            }
         ],
         "dataPoints":[
            {
               "xid":"DP_95f3a171-1183-4eb0-81d5-d18413b1568f",
               "name":"Changer",
               "enabled":true,
               "loggingType":"ON_CHANGE",
               "intervalLoggingPeriodType":"MINUTES",
               "intervalLoggingType":"INSTANT",
               "purgeType":"YEARS",
               "pointLocator":{
                  "dataType":"BINARY",
                  "changeType":{
                     "type":"ALTERNATE_BOOLEAN",
                     "startValue":"true"
                  },
                  "settable":false
               },
               "eventDetectors":[
                  {
                     "type":"POINT_CHANGE",
                     "sourceType":"DATA_POINT",
                     "xid":"ED_d122a920-68ce-416c-b2bf-bd32a868a42d",
                     "alias":"Trigger the poll time script",
                     "alarmLevel":"DO_NOT_LOG"
                  }
               ],
               "plotType":"STEP",
               "rollup":"NONE",
               "unit":"",
               "templateXid":"Binary_Default",
               "chartColour":"",
               "chartRenderer":{
                  "type":"TABLE",
                  "limit":10
               },
               "dataSourceXid":"DS_Poll_Test",
               "defaultCacheSize":1,
               "deviceName":"vrt",
               "discardExtremeValues":false,
               "discardHighLimit":1.7976931348623157E308,
               "discardLowLimit":-1.7976931348623157E308,
               "intervalLoggingPeriod":15,
               "intervalLoggingSampleWindowSize":0,
               "overrideIntervalLoggingSamples":false,
               "preventSetExtremeValues":false,
               "purgeOverride":false,
               "purgePeriod":1,
               "readPermission":"",
               "setExtremeHighLimit":1.7976931348623157E308,
               "setExtremeLowLimit":-1.7976931348623157E308,
               "setPermission":"",
               "textRenderer":{
                  "type":"BINARY",
                  "oneColour":"black",
                  "oneLabel":"one",
                  "zeroColour":"blue",
                  "zeroLabel":"zero"
               },
               "tolerance":0.0
            },
            {
               "xid":"DP_e8d0ea46-b514-4230-aae8-63e38adce6d7",
               "name":"Poll Times",
               "enabled":true,
               "loggingType":"ALL",
               "intervalLoggingPeriodType":"MINUTES",
               "intervalLoggingType":"AVERAGE",
               "purgeType":"YEARS",
               "pointLocator":{
                  "dataType":"NUMERIC",
                  "changeType":{
                     "type":"NO_CHANGE",
                     "startValue":"-1"
                  },
                  "settable":true
               },
               "eventDetectors":[
               ],
               "plotType":"SPLINE",
               "rollup":"NONE",
               "unit":"",
               "chartColour":"",
               "chartRenderer":{
                  "type":"IMAGE",
                  "timePeriodType":"DAYS",
                  "numberOfPeriods":1
               },
               "dataSourceXid":"DS_Poll_Test",
               "defaultCacheSize":1,
               "deviceName":"vrt",
               "discardExtremeValues":false,
               "discardHighLimit":1.7976931348623157E308,
               "discardLowLimit":-1.7976931348623157E308,
               "intervalLoggingPeriod":1,
               "intervalLoggingSampleWindowSize":0,
               "overrideIntervalLoggingSamples":false,
               "preventSetExtremeValues":false,
               "purgeOverride":false,
               "purgePeriod":1,
               "readPermission":"",
               "setExtremeHighLimit":1.7976931348623157E308,
               "setExtremeLowLimit":-1.7976931348623157E308,
               "setPermission":"",
               "textRenderer":{
                  "type":"ANALOG",
                  "useUnitAsSuffix":true,
                  "unit":"",
                  "renderedUnit":"",
                  "format":"0.00"
               },
               "tolerance":0.0
            }
         ],
         "eventHandlers":[
            {
               "eventType":{
                  "sourceType":"DATA_POINT",
                  "dataPointXID":"DP_95f3a171-1183-4eb0-81d5-d18413b1568f",
                  "detectorXID":"ED_d122a920-68ce-416c-b2bf-bd32a868a42d"
               },
               "xid":"EH_96f7b068-4515-4cd3-99f6-cfe94df14acb",
               "handlerType":"SET_POINT",
               "targetPointId":"DP_e8d0ea46-b514-4230-aae8-63e38adce6d7",
               "activeAction":"SCRIPT_VALUE",
               "activeScript":"var dsxid = \"DS_Poll_Test\";\nvar dsvo = com.serotonin.m2m2.db.dao.DataSourceDao.instance.getByXid(dsxid);\nvar dsrt = com.serotonin.m2m2.Common.runtimeManager.getRunningDataSource(dsvo.getId());\n\/\/It must be a polling data source for this to work\nvar pollTimes = dsrt.getLatestPollTimes();\nTIMESTAMP = pollTimes[pollTimes.length-1].key;\nreturn pollTimes[pollTimes.length-1].value;",
               "inactiveAction":"NONE",
               "additionalContext":[
               ],
               "scriptPermissions":{
                  "scriptDataPointReadPermission":"",
                  "scriptDataPointSetPermission":"",
                  "scriptDataSourcePermission":""
               },
               "alias":"",
               "disabled":false
            }
         ]
      }
      

      There is a blemish in that the poll times data point will have two values for each poll (I set it to log all data because the poll time for the virtual source is always zero, and I have the trigger on the data source, so I can't just enable polling) but that is easily fixed if you wish to do this for your own data source(s).

      Edit: Thinking about it again, i may use that script in a meta point, with a polled point on the source as the context update, and an execution delay to assure the event is not processed before the poll is finished. Or one may process the list on a cron to assure they didn't miss any.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post