This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Create Modbus client via script
#10
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:
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)
BR,

Erwin
Reply


Messages In This Thread
Create Modbus client via script - by FatMax - 17.02.2017, 11:31
RE: Create Modbus client via script - by AEK - 28.09.2017, 16:04
RE: Create Modbus client via script - by AEK - 29.09.2017, 07:56
RE: Create Modbus client via script - by Erwin van der Zwart - 28.05.2018, 08:16
RE: Create Modbus client via script - by AEK - 02.08.2018, 10:55

Forum Jump: