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.

Creating a KNx point for Modbus Device Communication Error Situation
#4
Hi,

Here is a version with writing to KNX objects:

Code:
-- Check all modbus meters for connection

-- Function to send changes to KNX
function writetoknx(name,active)
    if name == 'Meter 1' then  -- name must match modbus device name
   grp.write('1/1/1', toboolean(active))
 elseif name == 'Meter 2' then
   grp.write('1/1/2', toboolean(active))
 elseif name == 'Meter 3' then
   grp.write('1/1/3', toboolean(active))
 elseif name == 'Meter 4' then
   grp.write('1/1/4', toboolean(active))
 elseif name == 'Meter 5' then
   grp.write('1/1/5', toboolean(active))
 end
end

-- Get meter status
query = 'SELECT * FROM modbus_devices'
meter_state = db:getall(query)
previous_state = storage.get('meterstate')
if previous_state == nil then
 for _, device in ipairs(meter_state) do
     writetoknx(device.name,device.active)
 end
 storage.set('meterstate', meter_state)
else
 for _, device in ipairs(meter_state) do
   if device.active ~= previous_state[_].active then
        writetoknx(device.name,device.active)
   end    
 end
 storage.set('meterstate', meter_state)
end
 
BR,
Erwin
Reply


Messages In This Thread
RE: Creating a KNx point for Modbus Device Communication Error Situation - by Erwin van der Zwart - 04.10.2016, 10:54

Forum Jump: