How to set-up a point that starts a Mango script
-
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,
Antonioiif (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." ); }
-
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/CronAlso 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!
-
Thanks Phil,
yes, I'm using Mango 2.8.8, I'm following your suggestion so I created a metapoint named "updateInProgress",it is activated by the modbus datapoint named "update" infact the event choise is "contextupdate"
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:
-
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?
-
why is the script called always instead of just when "upgrade" changes:
-
it is not possible to add this metapoint "FML01 Meta - upgradeInProgress" to the context, why?
-
the var "isUpgradeInProgress" is the same than "FML01 Meta - upgradeInProgress" or what else?
-
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?
-
it is possible to catch generic exception to be sure that I can re-enable the datasources
Thanks,
Antonio -
-
- 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.- 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!
- 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.
- 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.- 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.
-
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? -
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.