03.09.2017, 14:34
Hi,
Need help. Using UDP script from forum with my changes. I need receive by LM some data over UDP, and write data to group depending received data.
As example - if LM received "206On" write to group 0/0/1 "1", if LM received "206Off" write to group 0/0/1 "0". UDP server working, received data I see in the alert tab, but groups not changed... If I need receive data in HEX type how check received data is HEX? Can you please help me and correct my script and very needed comments to study this case.
if not ready then
socket = require("socket")
copas = require("copas")
alert('not Ready')
ready=true
function parse(data)
alert('parsing: %s', data)
end
function fromKNX(command)
alert('Command from SoLaVi.. '..command)
--function parse(data)
log(command)
loghex(command)
if command == '206On' then
grp.write('0/0/1', 1)
elseif data == '206Off' then
grp.write('0/0/1', 0)
else
-- log other info, not mapped, if useful
log(data)
log(Command)
end
end
local server = socket.udp()
serveretsockname('*', 8891) -- my
function handler(skts)
skts = copas.wrap(skts)
alert("UDP connection handler")
while true do
local s, err
alert("UDP receiving...")
s, erro = skts:receive(2048)
if not s then
alert("UDP Receive error: ", erro)
break
end
alert("Received data: "..s)
fromKNX(s)
end
end
copas.addserver(server, handler, 1)
loghex(data) --- log the data
log(data)
end
if not skt then
alert('not socket')
if skt then
skt:close()
skt = nil
end
end
copas.loop()
Thanks, Alex
Need help. Using UDP script from forum with my changes. I need receive by LM some data over UDP, and write data to group depending received data.
As example - if LM received "206On" write to group 0/0/1 "1", if LM received "206Off" write to group 0/0/1 "0". UDP server working, received data I see in the alert tab, but groups not changed... If I need receive data in HEX type how check received data is HEX? Can you please help me and correct my script and very needed comments to study this case.
if not ready then
socket = require("socket")
copas = require("copas")
alert('not Ready')
ready=true
function parse(data)
alert('parsing: %s', data)
end
function fromKNX(command)
alert('Command from SoLaVi.. '..command)
--function parse(data)
log(command)
loghex(command)
if command == '206On' then
grp.write('0/0/1', 1)
elseif data == '206Off' then
grp.write('0/0/1', 0)
else
-- log other info, not mapped, if useful
log(data)
log(Command)
end
end
local server = socket.udp()
serveretsockname('*', 8891) -- my
function handler(skts)
skts = copas.wrap(skts)
alert("UDP connection handler")
while true do
local s, err
alert("UDP receiving...")
s, erro = skts:receive(2048)
if not s then
alert("UDP Receive error: ", erro)
break
end
alert("Received data: "..s)
fromKNX(s)
end
end
copas.addserver(server, handler, 1)
loghex(data) --- log the data
log(data)
end
if not skt then
alert('not socket')
if skt then
skt:close()
skt = nil
end
end
copas.loop()
Thanks, Alex