• 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-up a point that starts a Mango script

    Mango Automation general Discussion
    2
    6
    1.2k
    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.
    • E
      etantonio
      last edited by

      Good morning,
      my idea is to upgrade some STM32 board monitored with Mango,
      about this I've a flag named "upgrade" , when upgrade=1 then I want to disable datasources, update the firmware with a Python script then enable the datasources and send a reboot signal.

      My idea was about using a scripting datasource, but it is not possible to specify less than 1 minute with cron.

      Looking instead at an alarm associated to "upgrade" it seems that it is only possible to run OS processes and so it is not possible to enable and disable the datasources as I need.

      Any idea about how to fire a Mango script using a point event handler
      or
      how to set a scripting datasource execution every five seconds.
      thanks,
      Antonio

      iif (upgrade.value === 1) {
          print( "Update required!" );
          print( "Start datasource shutdown " );
          RuntimeManager.disableDataSource('FML01-main');
          RuntimeManager.disableDataSource('FML01-conf'); 
          print( "End   datasource shutdown" );
          
          
          print( "START target Update Script" );
          var response = com.serotonin.m2m2.rt.maint.work.ProcessWorkItem.executeProcessCommand("/home/solergy/./tracker_upgrade_IP.sh S07E-MCU-3AX.bin upload 172.16.9.12", 300);
          print( response.key );
          print( "END   target Update Script" );
          
          
          print( "Start datasource power-on " );
          RuntimeManager.enableDataSource('FML01-main');
          RuntimeManager.enableDataSource('FML01-conf'); 
          print( "End datasource power-on" );
          
          java.lang.Thread.sleep(90000);
          
          print("Start board reset");
          manualAct.set(8);
      }else{
          print( "Update not required." );
      }
      
      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Hi etantonio,

        You are using Mango 2.8.8, correct?

        You can simply put this logic into a meta point and have some point you set to trigger the script.

        Any idea about how to fire a Mango script using a point event handler

        In later Mango versions the set point event handler has a 'set to scripted value' option that would be an appropriate to use. The email handler can run a script too. But, in 2.8.8 you may need to have a set point handler set a value to a meta point's context point, which triggers the meta point.

        how to set a scripting datasource execution every five seconds

        0/5 * * * * ? https://en.wikipedia.org/wiki/Cron

        Also in later versions scripting data sources can be triggered by context point events. Upgrading from 2+ years ago's version comes with a lot of features!

        1 Reply Last reply Reply Quote 0
        • E
          etantonio
          last edited by etantonio

          Thanks Phil,
          yes, I'm using Mango 2.8.8, I'm following your suggestion so I created a metapoint named "updateInProgress",

          0_1557826003514_c8bc3473-93eb-4530-a614-c5ffbd6286aa-immagine.png

          it is activated by the modbus datapoint named "update" infact the event choise is "contextupdate"

          0_1557826154172_a121e25e-b855-4cd4-819e-e5444e08820b-immagine.png

          the script associated to the metapoint is the following:

          LOG.info("upgrade.value: " + upgrade.value );
          if (upgrade.value === 1) {
              LOG.info("Update required!" );
              upgrade.set(0);
              java.lang.Thread.sleep(15000);
              LOG.info("upgrade.value: " + upgrade.value + "Disabled" );        
                  
              LOG.info( "Start shutdown datasource" );
              RuntimeManager.disableDataSource('FML01-main');
              RuntimeManager.disableDataSource('FML01-conf'); 
              LOG.info( "End shutdown datasource" );
          
              LOG.info( "Start Script Update target" );
              var response = com.serotonin.m2m2.rt.maint.work.ProcessWorkItem.executeProcessCommand("/home/solergy/./tracker_upgrade_IP.sh S07E-MCU-3AX.bin upload 172.16.9.12", 300);
              LOG.info( response.key );
              LOG.info( "Fine Script Update target" );
          
              java.lang.Thread.sleep(30000);
              
              LOG.info( "Start power-on datasource" );
              RuntimeManager.enableDataSource('FML01-main');
              RuntimeManager.enableDataSource('FML01-conf'); 
              LOG.info( "Fine power-on datasource" );
              
              java.lang.Thread.sleep(30000);
              
              LOG.info("Start reset board");
              manualAct.set(8);
              return 0;
          }
          

          but I'ven't clear the following:

          1. upgrade.set(0); seems not to work inside the script, there is some reason for this? Maybe this is the difference with the scripting datasource, I can change only the value of "FML01 Meta - upgradeInProgress" at the end of the associated script, is it true?

          2. why is the script called always instead of just when "upgrade" changes:
            0_1557835800902_8ef5d27f-d2ad-41eb-93ac-97d86e7e2b55-immagine.png

          3. it is not possible to add this metapoint "FML01 Meta - upgradeInProgress" to the context, why?

          4. the var "isUpgradeInProgress" is the same than "FML01 Meta - upgradeInProgress" or what else?

          5. My requirement is that during the script execution the "updateInProgress" datapoint value is 1 or true , instead otherwise its value have to be 0 or false, is it possible to achieve this behaviour?

          6. it is possible to catch generic exception to be sure that I can re-enable the datasources

          Thanks,
          Antonio

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            1. upgrade.set(0); seems not to work inside the script, there is some reason for this? Maybe this is the difference with the scripting datasource, I can change only the value of "FML01 Meta - upgradeInProgress" at the end of the associated script, is it true?

            In newer versions of Mango, you would be able to set via the .set() functions, but in 2.8 those functions only exist for scripting data source context points. It was added to context points for meta scripts somewhere around version 3.2. Setting values to context points that update context can produce loose infinite loops, but it is permitted.

            1. why is the script called always instead of just when "upgrade" changes:

            Is it a virtual point set to not change? If so it is still getting polled by the virtual data source which would produce updates. In later versions of Mango the virtual data source can not poll at all, which is a feature on all polling data sources in 3.6. Also in later versions the update event can be specified to logged value events and change events, in addition to update events. The benefits of using a newer version are many!

            1. it is not possible to add this metapoint "FML01 Meta - upgradeInProgress" to the context, why?

            It is already in the context, so the answer to (4) is Yes.

            1. My requirement is that during the script execution the "updateInProgress" datapoint value is 1 or true , instead otherwise its value have to be 0 or false, is it possible to achieve this behaviour?

            You could upgrade, and then you can use meta points for this purpose, otherwise you'd have to use a scripting data source. Of course, you could also do the leg work of looking around the 2.8 version on our Github, and find the right Java functions to invoke to set the values you need to set from the meta point. If the script needs to be event driven in 2.8, you'd probably need to get the data source from the runtime manager and force it to poll. The RuntimeManager.refreshDataSource("DS_XID"); function wasn't around in 2.8 and scripting data source context points don't listen for data point events.

            1. it is possible to catch generic exception to be sure that I can re-enable the datasources

            In JavaScript? Have you attempted using

            try {
            
            } catch(excep) {
            
            }
            

            It is somewhat of a burden to try to recall what was possible in 2.8 and then hamstring the solutions we suggest to a feature set that we've expanded so much upon.

            1 Reply Last reply Reply Quote 0
            • E
              etantonio
              last edited by

              Thanks Phil for your help,
              for me is important to learn deeper all complex functions offered by Mango.
              In this case I think the best solution will be to use a scripting datasource with about 10 seconds poll on variable "update".
              The scripting datasource is a singleton? I mean if I have a long script inside (1 minute) while the script is called every 5 seconds, what happens?

              1 Reply Last reply Reply Quote 0
              • phildunlapP
                phildunlap
                last edited by

                It would be the same as any other polling data source with long running polls: polls that occur while previous polls are running will increment the aborted polls count and not poll.

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