sendto uses ascii in my experience, e.g. here is code I wrote for a different use case to send the text D:101:E to turn on device 01 for example;
[code] local socket = require “socket”
local udp = socket.try(socket.udp())
local broadcast_ip = ‘255.255.255.255’
local port = 53008
assert(udp:setoption(“broadcast”, true))
udp:settimeout (10) – wait 10 seconds
socket.try (udp:setsockname (‘*’, port))
local device_address=luup.devices[lul_device].mac
luup.variable_set( "urn:upnp-org:serviceId:SwitchPower1", "Status", lul_settings.newTargetValue, lul_device)
if (lul_settings.newTargetValue=="1") then
socket.try(udp:sendto("D:1"..device_address..":E", broadcast_ip, port))
else
socket.try(udp:sendto("D:0"..device_address..":E", broadcast_ip, port))
end
socket.try(udp:close())
I’ve added the following function to the startup Lua:
function sendUDP(msg)
local socket = require "socket"
local udp = assert(socket.udp())
assert(udp:sendto(msg, "<ip address here>", <port number here>))
assert(udp:close())
end
and in my scenes I just use:
sendUDP("garage door open")
On the listener (simple perl script) side I have routines which do different things dependent on different text.
I was wondering if someone could help me achieve the same kind of thing but for tcp packet ?
I need to send the ascii code “!000D000c;” to 192.168.1.101:9000 in TCP from my vera controller.
I tried multiple things without success yet.
local IP = “xxx.xxx.xxx.xxx”
local Port = “9000”
local Command = “!000D000c;\r”
local socket = require(“socket”)
c = assert(socket.connect(IP, Port))
c:settimeout(5)
local sres, serr = c:send(Command)
c:close()
Best Home Automation shopping experience. Shop at Ezlo!