19.02.2026, 12:17
Here's an example of sending commands:
For full integration the response must be parsed. Since the device can only handle a single TCP connection you will need a resident script that handles both sending commands and receiving status message from the device.
Code:
function encodeuint32(value)
local bytes = {}
for i = 1, 4 do
bytes[ i ] = bit.band(value, 0xFF)
value = bit.rshift(value, 8)
end
return string.char(unpack(bytes))
end
function encode(cmd)
if #cmd > 11 then
cmd = cmd .. '&'
end
local csum = 0
for i = 1, #cmd do
csum = csum + cmd:byte(i)
end
return
string.char(0x18, 0x96, 0x18, 0x20) ..
encodeuint32(#cmd) ..
encodeuint32(csum) ..
string.char(0x00):rep(8) ..
cmd
end
sock = require('socket').tcp()
sock:settimeout(5)
res, err = sock:connect('192.168.1.1', 8899)
if res then
data = encode('MCU+VOL+050')
sock:send(data)
log('send ok')
else
log('connection failed', err)
end
sock:close()For full integration the response must be parsed. Since the device can only handle a single TCP connection you will need a resident script that handles both sending commands and receiving status message from the device.