I checked this and the problem is not in UDP client-server. It works great but when I try send the command via TCP my connection is refused. I try to send cmd to the RS485 server. This is the script:
Where is the error?
This is the network configuration of the serial server.
Code:
if not server then
-- local UDP server on port 5432
server = require('socket').udp()
server:settimeout(1)
server:setsockname('127.0.0.1', 5432)
-- serial connection
port = require('serial').open('/dev/RS485', {
baudrate = 4800,
parity = 'odd',
duplex = 'half',
databits = 8,
stopbits = 1
})
end
cmd = server:receive()
if cmd then
function somfy_rf(cmd)
serial_server_ip = '192.168.2.15'
host, port = serial_server_ip, 10001
socket = require("socket")
client = socket.tcp()
client:settimeout(1)
client:connect(host, port)
client:send(cmd)
end
somfy_rf(cmd)
if #cmd == 12 then
time = 6
elseif #cmd == 13 then
time = 0.6
elseif msg == set_channel then
time = 0.45
end
os.sleep(time)
end
This is the network configuration of the serial server.