Logic Machine Forum
Master Slave with LM5 - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Master Slave with LM5 (/showthread.php?tid=5723)



Master Slave with LM5 - Kuru - 06.11.2024

Hello,

In my project, I have an LM5 as the Master and another as the Slave.
The Slave is intended to switch on if the connection to the Master fails. Both should perform the same function.
I have KNX, DALI, BACnet, and Modbus communication.

Is there a way for the Slave to only activate when the connection to the Master has failed?
The Slave should, however, always listen in on all communications so that it is up-to-date in case of a Master failure.

Thank you very much for your help.


RE: Master Slave with LM5 - Daniel - 06.11.2024

Can you provide more info how the DALI, BACnet and modbus is done?


RE: Master Slave with LM5 - Kuru - 06.11.2024

(06.11.2024, 11:21)Daniel Wrote: Can you provide more info how the DALI, BACnet and modbus is done?

KNX sensors control the lighting via DALI. In the event of a failure, the second LM should take over the control and visualization.

The LM communicates with the Schneider Gateway via BACnet. Modbus is used for communication with field devices.

In case of a Master LM failure, everything should continue to operate via the Slave LM. Sensor values are visualized.


RE: Master Slave with LM5 - Daniel - 06.11.2024

the DALI - is it KNX DALI gateway?
LM communicates with the Schneider Gateway via BACnet - what do you mean here? Is LM bacnet server or client?
Modbus - is it RTU or IP?
Two LMs can't have same IP so in any case this will need to be manually switched to new url.


RE: Master Slave with LM5 - Kuru - 07.11.2024

(06.11.2024, 12:42)Daniel Wrote: the DALI - is it KNX DALI gateway?
LM communicates with the Schneider Gateway via BACnet - what do you mean here? Is LM bacnet server or client?
Modbus - is it RTU or IP?
Two LMs can't have same IP so in any case this will need to be manually switched to new url.

DALI is controlled via a KNX DALI gateway.
The LM communicates with the Schneider gateway via BACnet, where the LM acts as the BACnet server.
Modbus communication is over RTU.
The two LMs will be assigned different IP addresses.
In the event of a master LM failure, the slave LM must automatically take over control.


RE: Master Slave with LM5 - Daniel - 07.11.2024

OK so we don't care about DALI as for LM it is a KNX anyway

You can connect two LMs to the same TP but you must change multicast on one of them to avoid loops. You could disable KNX IP if it is not needed.
Bacnet IP can be enabled/disabled like this:
Code:
-- disable
os.execute('uci set bacnet.server.enabled=0 && uci commit bacnet && /etc/init.d/bacnet stop')

-- enable
os.execute('uci set bacnet.server.enabled=1 && uci commit bacnet && /etc/init.d/bacnet start')

The client most likely well cache the IP and it might not work straight on, it should expire after some time.

Modbus RTU, if you have both enabled at the same time nothing will work,
Use this event script to emulate a web request to enable/disable RTU. Attach it to a boolean object. 
Code:
value = event.getvalue()

require('uci')
require('json')

function getvar()
  return 'config-save'
end

function json.data()
  return { enabled = value }
end

dofile('/lib/genohm-scada/plugins/modbus/web.lua')

You need to create a script which will monitor if main LM is al live and if not apply the above. An example here but you need to be careful, If LM is still working and you enable both then modbus will not work and probably bacnet too.

https://openrb.com/master-slave-logicmachine/

See also this
https://forum.logicmachine.net/showthread.php?tid=1679&pid=10348#pid10348


RE: Master Slave with LM5 - Kuru - 24.04.2025

Thank you very much for your support.
Unfortunately, the script for turning the RTU on and off only works on the LM with firmware version 20211215. On the LMs with firmware version 20240426, it unfortunately does not work.
Although I can use the script to turn the RTU off, it does not work when trying to turn it back on. When I run "RTU Scan" after turning it back on, I get the message: "RTU (serial) is not enabled."

Could you please help me with this?


RE: Master Slave with LM5 - Daniel - 24.04.2025

Use this to enable/disable modbus
Event script on a boolean object
Code:
value = event.getvalue()


webrequest = require('webrequest')
vars = {
  plugin = 'modbus',
  request = 'config-save',
  data = {
    enabled = value
  }
}

res, err = webrequest('general', 'plugin', vars)
log(res, err)



RE: Master Slave with LM5 - Kuru - 24.04.2025

Unfortunately, this doesn't work either.
I created a group address with a Boolean value: when set to 0, the Modbus switches off; when set to 1, it indicates that RTU 1 is switched on.
However, it doesn’t work as intended – RTU 1 only starts again after restarting the LM.


RE: Master Slave with LM5 - Daniel - 24.04.2025

I just tried it on 20240402 and it works fine.


RE: Master Slave with LM5 - Kuru - 24.04.2025

(24.04.2025, 12:45)Daniel Wrote: I just tried it on 20240402 and it works fine.

Here my Project, so u can test it.


RE: Master Slave with LM5 - Daniel - 25.04.2025

You protected your backup with password but I tried the script also on newer firmware and it works fine.


RE: Master Slave with LM5 - Kuru - 28.04.2025

Here is the project.
The password is 'Modbus123'.
After sending the value 1 to the address '1/1/1', test whether the 'RTU Scan' is working.
It doesn't work for me.


RE: Master Slave with LM5 - Daniel - 28.04.2025

I'm testing on live device.
https://app.screencast.com/wIeTcUWPrVK6N


RE: Master Slave with LM5 - Kuru - 08.05.2025

It still doesn't work for me. What I have noticed is that the script works on the LM5p2-DW1 device, but we have 140 LM5P2-KCD devices in our project and the switching does not work with this type.


RE: Master Slave with LM5 - Daniel - 08.05.2025

We tried on same hardware and same firmware, also using your backup and it works fine. I think the issue you have is in pool interval. The slave device might not be able to do the whole read cycle in 1 second and then the daemon is fully occupied. Change it to something longer, there is no need to read the values so often.


RE: Master Slave with LM5 - admin - 14.05.2025

Update Modbus package and try again:
https://dl.openrb.com/pkg/genohm-scada-modbus_20250509_imx6.ipk
https://dl.openrb.com/pkg/genohm-scada-modbus_20250509_imx6.sig

Install through System config > System > Packages > Add Package.