28.05.2018, 08:16
(This post was last modified: 28.05.2018, 08:19 by Erwin van der Zwart.)
Hi,
The new FW requires a extra parameter 'timeout' that old FW didn't use, and also new browsers are blocking credentials in URL so i changed the script in a new methode for web requests.
Thanks to Admin for that (:
Here is the new script:
BR,
Erwin
The new FW requires a extra parameter 'timeout' that old FW didn't use, and also new browsers are blocking credentials in URL so i changed the script in a new methode for web requests.
Thanks to Admin for that (:
Here is the new script:
Code:
-- Batch adding modbus devices v1.1 - Created by Erwin van der Zwart - Schneider Electric Netherlands -----------
-- For spaceLYnk FW 2.1.1 or higher and Wiser for KNX FW 2.1.1 or higher ----------------------------------------
----------------------------------------------- Start Parameters ------------------------------------------------
Number_of_devices = 10
Device_name_prefix = "Device"
Device_protocol = "tcp"
Device_port = 502
Device_ip_range = "192.168.0"
Device_ip_start = 1
Device_profile = "iEM-iEM3155"
Device_timeout = 3
Device_pollinterval = 5
Device_slave_start = 1
------------------------------------------------ End Parameters -------------------------------------------------
------------------------------------ DON'T CHANGE ANYTHING UNDER THIS LINE --------------------------------------
-- Set counters for creation log
number_of_devices = 0
number_failed = 0
-- Function to send request (in this case to create a modbus device)
function webrequest(mod, act, vars, data)
require('json')
require('dbenv')
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
-- Create devices
for i = 0, Number_of_devices - 1, 1 do
requestdata = {
id = "",
timeout = "" .. Device_timeout,
pollinterval = "" .. Device_pollinterval,
slave = "" .. Device_slave_start + i,
port = "" .. Device_port,
ip = Device_ip_range .. "." .. Device_ip_start + i,
profile = Device_profile,
name = Device_name_prefix .. " " .. i + 1,
proto = Device_protocol,
}
result = webrequest('plugin', 'modbus', {request = 'device-save'}, requestdata)
-- Calculate results for creation devices log
if result == '{"success":true}' then
number_of_devices = number_of_devices + 1
else
number_failed = number_failed + 1
end
end
-- Create result log
if number_failed == 0 then
log ("Created " .. number_of_devices .. " devices succesfully")
else
log ("Created " .. number_of_devices .. " devices succesfully and creation of " .. number_failed .. " devices failed")
end
-- Disable script when done automaticly
script.disable(_SCRIPTNAME)
Erwin