Additional Scripts to alter the data source and network configuration
-
Reason behind is I would like to have control to enable/activate the datasource (putting it online or offline) or change the parameters of the network ( i.e. ip address, bring online or offline) in order to install two identical MangoEs for the purpose of redundancy. One is label as Master and the other is Slave. My Idea is the Master will publish a continuous pulse which the slave will continuously monitor at certain interval and once the time period elapse and there is no pulse coming from the Master the Slave MangoEs will enable the datasource and possibly redefine the IP address to effectively replace the Master when it fail. I know this is a poor mans solution but may work. Calling the script will be define in the event handler or through Script datasource.
A better alternative would be integrating in the MAngoEs code itself. Any idea please...
-
Hi Joey Uson, welcome to the forum!
All of that does sound quite possible! Let alone the myriad of ways to achieve some kind of heartbeat between two MangoES units. You could use any of the publishers, really, and since there is Mango on both ends I would recommend the Mango Persistent TCP Publisher / Data Source pair. Simply create a virtual data source and point on the 'Master' and publish this point to the 'Slave.' That then has a No Update detector on the received point, and the detector has an event handler script that invokes the IP change.
However, if you want to use Modbus IP, which seems like what you are describing with the Master/Slave terms and that we'd be changing IP addresses, you can do that by creating a Modbus Publisher on the 'Slave' and 'publishing' a settable virtual point. Then the 'Master' will have a Modbus IP data source pointed at the slave, and a scripting data source (or be more efficient, use a virtual data source and a point link with no script) will set a point value to the Master's modbus point, which will set it to the 'Slave.' Then, once again event detector, event handler.
If you have the MangoESConfiguration module installed (which by default you should), you could change the IP address with the following script:
var interfaceSettings = com.infiniteautomation.system.SystemManager.INSTANCE.interfaces(); var eth0; for( var k = 0; k < interfaceSettings.length; k+=1 ) { var iface = interfaceSettings[k]; if( (iface.name !== "eth0") ) continue; eth0 = iface; break; } if( typeof eth0 === 'undefined' ) throw "No eth0 interface found."; var addresses = eth0.getAddresses(); for( var k = 0; k < addresses.length; k+=1 ) { var address = addresses[k]; if( ! address.isIpv6() ) { //okay, found the eth0's IPv4 settings, set address address.setAddress( "192.168.1.123" ); //address.networkPrefixLength = 24; //probably not changing break; } } //ensure eth0 is configured for a static IPv4: eth0.setIpv4AddressingType("static"); //You're probably not changing it, but, //eth0.setIpv4Gateway( "192.168.1.1" ); //Okay, we set up our eth0 interface now, so let's apply these changes com.infiniteautomation.system.SystemManager.INSTANCE.setInterface( eth0 );
And that should work to modify your IPv4 address to 192.168.1.123
-
Thanks for the explanation and scripts, I'll test on Sunday