15.06.2022, 09:55
Use this. Changing mapping will require full script restart via disable/enable.
This example partially implements parsing of lighting type messages (off and dimming).
Docs for all types: https://developer.legrand.com/documentat...or-myhome/
Code:
if not sock then
mapping = {
['11'] = '1/1/11',
}
function parselighting(what, where)
local addr = mapping[ where ]
what = tonumber(what) or -1
if addr and 0 <= what and what <= 10 then
grp.checkwrite(addr, what * 10)
end
end
function parse(msg)
local who, what, where = unpack(msg:split('*'))
who = tonumber(who)
-- lighting
if who == 1 then
parselighting(what, where)
end
end
function read(sock)
local buf = {}
while true do
local ch, err = sock:receive(1)
if ch then
local pr = buf[ #buf ]
buf[ #buf + 1 ] = ch
if ch == '#' and pr == '#' then
break
end
else
return nil, err
end
end
if #buf > 0 and buf[ 1 ] == '*' then
return table.concat(buf, '', 2, #buf - 2)
end
end
sock = require('socket').tcp()
sock:settimeout(1)
res, err = sock:connect('192.168.1.247', 20000)
if res then
sock:send('*99*1##')
else
log('connect failed', err)
sock:close()
sock = nil
os.sleep(1)
end
end
-- socket handler
if sock then
res, err = read(sock)
if res then
parse(res)
elseif err == 'closed' then
sock:close()
sock = nil
end
end
This example partially implements parsing of lighting type messages (off and dimming).
Docs for all types: https://developer.legrand.com/documentat...or-myhome/