26.04.2018, 12:30
Code:
function tcpsend(data, ip, port)
local sock, res, err
sock = require('socket').tcp()
sock:settimeout(5)
res, err = sock:connect(ip, port or 20554)
if res then
res, err = sock:receive(5)
if res == 'PJ_OK' then
sock:send('PJREQ')
res, err = sock:receive(5)
if res == 'PJACK' then
sock:send(data)
res, err = sock:receive(6)
else
alert('invalid/no ack: ' .. tostring(res))
end
else
alert('invalid/no init: ' .. tostring(res))
end
else
alert('connect failed: ' .. tostring(err))
end
sock:close()
return res, err
end
cmdon = string.char(0x21, 0x89, 0x01, 0x52, 0x43, 0x37, 0x33, 0x30, 0x35, 0x0A)
cmdoff = string.char(0x21, 0x89, 0x01, 0x52, 0x43, 0x37, 0x33, 0x30, 0x36, 0x0A)
res, err = tcpsend(cmdon, '192.168.1.111')