27.06.2022, 12:15
You need a separate socket connection for commands. You also need to send another init sequence: *99*0##.
This example should control light point 11 by converting 0..100% value to 0..10. There's some extra logging to check if the message flow is correct. Remove it when the script is working properly.
This example should control light point 11 by converting 0..100% value to 0..10. There's some extra logging to check if the message flow is correct. Remove it when the script is working properly.
Code:
value = event.getvalue()
value = math.ceil(value / 10)
cmd = '*1*' .. value .. '*11##'
sock = require('socket').tcp()
sock:settimeout(1)
res, err = sock:connect('192.168.1.247', 20000)
if res then
sock:send('*99*0##')
res, err = sock:receive(6) -- receive ACK
log('receive 1', res, err)
res, err = sock:send(cmd)
log('send', res, err)
res, err = sock:receive(6) -- receive result ACK/NACK
log('receive 2', res, err)
else
log('connect failed', err)
end
sock:close()