Being new to Lua I was hoping someone could give me some hints on how to do this. I’m working on integrating the Vera with a 3rd party automation system. I can write code in the 3rd party system to communicate with Lua using the http interface. Using this paradigm the 3rd party system needs to periodically poll the Vera for any status changes such as someone unlocking a Schlage door lock that is connected to the Vera.
What I would like to do is to have an event in the Vera that, when the door is unlocked, sends a text message using a predefined Ethernet port to the 3rd party automation system.
Is there a way in Lua to open an Ethernet port, send some text, and the close the port?
If by “Ethernet port” you mean a TCP connection, then absolutely. Vera includes the LuaSocket package. The simple way could be something like this:
require "socket"
local function just_send (addr, port, data)
local s = assert (socket.tcp())
assert (s:connect (addr, port))
assert (s:send(data))
s:close()
end
Another possibility is to define a ‘serial port’ device on a TCP connection to your other system, and use the usual [tt]luup.io.write()[/tt] function. That also allows Luup to invoke your Lua code on any incoming data.
local hex = {
“aa”, “05”, “05”, “01”, “4b”
}
local binary = “”;
for i, v in ipairs(hex) do
binary = binary … string.char(tonumber(v, 16))
end
local socket = require(“socket”)
tcp = assert(socket.connect(“192.168.30.100”, 4999))
tcp:send(binary … “\r\n”)
luup.sleep(100)
tcp:close()
i now just would like to know how to send multiple tcp commands
I would like to also be able to send some http strings to change some status on the multswitch plugin
can any one show me an example og what it sould look like.