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

Process Event handler to fire external script


  • It's going to be related to event detector and point settings. Export the JSON for the point, we cannot see how you've got the event detector configured and point settings configured


  • You can add another virtual point into the context for the set point handler, and set a value to it in the script before returning. Then in the script you do something like this,

    if( lastSet.time >= CONTEXT.getRuntime() - 15000 ) //15 seconds
      return UNCHANGED;
    lastSet.set(!lastSet.value); //we care about times, not values, so alternate a binary
    return true;
    

  • @MattFox This is the SSH data point:

    {
            "xid":"DP_41011e72-6228-4ae6-a4e3-6fdce7c45ec7",
            "name":"Trigger",
            "enabled":true,
            "loggingType":"ON_CHANGE",
            "intervalLoggingPeriodType":"MINUTES",
            "intervalLoggingType":"INSTANT",
            "purgeType":"YEARS",
            "pointLocator":{
               "dataType":"ALPHANUMERIC",
               "setCommand":"\/home\/mango\/detect-start.sh",
               "queryable":false,
               "settable":true
            },
            "eventDetectors":[
            ],
            "plotType":"STEP",
            "rollup":"NONE",
            "unit":"",
            "templateXid":"Alphanumeric_Default",
            "simplifyType":"NONE",
            "chartColour":"red",
            "chartRenderer":{
               "type":"TABLE",
               "limit":10
            },
            "dataSourceXid":"DS_40cb68b0-350f-4b16-b54b-5bc359cf8241",
            "defaultCacheSize":1,
            "deviceName":"MangoES",
            "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":"",
            "tags":{
            },
            "textRenderer":{
               "type":"PLAIN",
               "useUnitAsSuffix":true,
               "unit":"",
               "renderedUnit":"",
               "suffix":""
            },
            "tolerance":0.0
         },
    

    And here's the virtual data point that I use to trigger:

     {
             "xid":"DP_d8a89826-e771-4760-ac46-9064a5e3b3d0",
             "name":"doorIsOpen",
             "enabled":true,
             "loggingType":"ON_CHANGE",
             "intervalLoggingPeriodType":"MINUTES",
             "intervalLoggingType":"INSTANT",
             "purgeType":"YEARS",
             "pointLocator":{
                "dataType":"BINARY",
                "changeType":{
                   "type":"NO_CHANGE",
                   "startValue":"True"
                },
                "settable":true
             },
             "eventDetectors":[
                {
                   "type":"BINARY_STATE",
                   "sourceType":"DATA_POINT",
                   "xid":"ED_80c9adf7-f1ad-4058-a60a-05a58f53ecf6",
                   "name":"",
                   "alarmLevel":"NONE",
                   "durationType":"SECONDS",
                   "duration":0,
                   "state":true
                },
                {
                   "type":"BINARY_STATE",
                   "sourceType":"DATA_POINT",
                   "xid":"ED_915a14f9-17da-4885-9c22-a53648617c04",
                   "name":"",
                   "alarmLevel":"NONE",
                   "durationType":"SECONDS",
                   "duration":0,
                   "state":false
                }
             ],
             "plotType":"STEP",
             "rollup":"NONE",
             "unit":"",
             "templateXid":"Binary_Default",
             "simplifyType":"NONE",
             "chartColour":"blue",
             "chartRenderer":{
                "type":"TABLE",
                "limit":10
             },
             "dataSourceXid":"DS_5d06b8ba-c91b-4c93-b594-92c5009ec67e",
             "defaultCacheSize":1,
             "deviceName":"Virtual Data Source",
             "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":"",
             "tags":{
             },
             "textRenderer":{
                "type":"BINARY",
                "oneColour":"#ff0000",
                "oneLabel":"one",
                "zeroColour":"blue",
                "zeroLabel":"zero"
             },
             "tolerance":0.0
          },
    

    @phildunlap What is lastSet in this case? It says lastSet is undeclared.


  • That's the variable name I gave to a binary virtual point that would be in the Set point handler's "Additional Context."

    I guess you could in theory have issues then where you wanted the script to be invoked more than once in a fifteen second interval, but at that point you're really on the hook for specifying the logic you need very clearly. It may be easier for your script to use a lock file or some such.


  • @phildunlap Ok, I see what you mean. So if my source point has not changed for 15 seconds, I can treat it as unchanged and do something off of that.
    For now, I just created another data point event detector for the source point to detect a state of 0. And when the state is 0, I run a process command that kills the python script. It seems to get the job done, and now when I run "top" I can see the python process going away and back as I toggle the source point.

    Thanks for the help guys!


  • @khuang said in Process Event handler to fire external script:

    And when the state is 0, I run a process command that kills the python script.

    If you're having to kill the script I suggest you establish some more parameters and make it return/exit after it fires. You don't want errant scripts causing havoc in your system. Scripts should be one shots only.


  • Glad you got it figured out! Thanks Fox!

    I can treat it as unchanged and do something off of that.

    UNCHANGED is a special return value for email handlers, set point handlers, meta points, and point links to cancel whatever would normally occur. So no email, no value set to the target point, no value to the meta point, and no value to the target of the point link.


  • @phildunlap Thanks to you too my man. We got to the bottom in the end. Not easy trying to work out scenarios without being there.


  • @mattfox Yes, that is a good idea. I will work on thinking of a safe way to exit. My exact use case is that the script will detect people in real time and the only reason why I would want to stop this detection is if a bit flips to zero in the PLC. I was thinking that a safe way to exit could be to continuously poll the data point I want to trigger on to see if it is zero, and if it is zero I exit. However, I would have to make an API call every second. If you have any ideas, please let me know.


  • Why poll? use a datapoint that is amended via the PLC. Make it reflect the state of the PLC and use that to control your script status. It should be able to trigger the other way, not with you polling it.
    If needs be contact me via chat and we can discuss in detail.