LogicMachine Forum
Backup include modbus settings - Printable Version

+- LogicMachine 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: Backup include modbus settings (/showthread.php?tid=2200)



Backup include modbus settings - MantasJ - 14.08.2019

Hello,

We're using this example: https://openrb.com/e-mail-backup-file-once-a-month-from-lm/ to make our LM backups, but they don't contain modbus settings. Is it possible to integrate these settings in a backup file, or I have to think of a separate way to do this?

Thank You.


RE: Backup include modbus settings - FatMax - 14.08.2019

Heres a function to enable RTU. Change RTU settings as you please.

Call this function in init. You should also set a storage so you know it has been done, so you don't enable RTU each time the device reboots.

Code:
function enableRTU() -- Function to send request (in this case to enable modbus RTU with settings) function webrequest(mod, act, vars, data) require('json') require('dbenv') require('uci') local path vars = vars or {} function getvar(v)     return vars[ v ] end json.data = function()     return data or {} end if mod == 'plugin' then     path = 'plugins/' .. act .. '/web.lua' else     path = 'web/' .. mod .. '/' .. act .. '.lua' end return dofile('/lib/genohm-scada/' .. path) end -- RTU settings (Change these to your liking) Set_enabled = 1 Set_port = "/dev/RS485" Set_baudrate  = 19200 Set_parity = 2 Set_duplex = "H" Set_port1 = "" Set_baudrate1  = 115200 Set_parity1 = 2 Set_duplex1 = "H" Set_port2 = "" Set_baudrate2  = 115200 Set_parity2 = 2 Set_duplex2 = "H" -- Input settings requestdata = {     enabled = "" .. Set_enabled,     port = "" .. Set_port,     baudrate = "" .. Set_baudrate,     parity = "" .. Set_parity,     duplex = "" .. Set_duplex,     port_1 = "" .. Set_port1,     baudrate_1 = "" .. Set_baudrate1,     parity_1 = "" .. Set_parity1,     duplex_1 = "" .. Set_duplex1,     port_2 = "" .. Set_port2,     baudrate_2 = "" .. Set_baudrate2,     parity_2 = "" .. Set_parity2,     duplex_2 = "" .. Set_duplex2,   } result = webrequest('plugin', 'modbus', {request = 'config-save'}, requestdata)   -- Results for log if result == '{"success":true}' then     alert('Modbus RTU enabled') else     alert('Enable Modbus RTU FAILED!') end   end