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