SpaceLogic KNX Forum
Schneider Electric SpaceLogic KNX forum to get support and share knowledge including selection, installation and troubleshooting for spaceLYnk, Wiser for KNX, eConfigure KNX, SpaceLogic KNX Hybrid module and other topics.
Link copied. Please paste this link to share this article on your social media post.
Hello,
We are trying to communicate with a Global Caché device that accepts TCP socket connection.
I did some research and LUA is able to this, my questions are:
1 - Is there any library (like this one LuaSocket: Installation) is inside the system? ( or any other )
2 - There is any example available?
The device we are using is this one
http://www.globalcache.com/files/docs/API-GC-100.pdf
Thanks for the help
Link copied. Please paste this link to share this article on your social media post.
Hi Francisco,
1 - Is there any library (like this one LuaSocket: Installation) is inside the system? ( or any other )
There is exactly mentioned LuaSocket library available inside hL.
2 - There is any example available?
I attached one example below but in general there are many options what you can do with LuaSockets. So probably best answer is "try to google what exactly you need": LuaSocket: Introduction to the core, LuaSocket: HTTP support, any demo code for lua socket, Luasocket server and actionscript, lua socket client
-- send POST message in XML format to some url address...
require("socket.http")
require("ltn12")
local response, message, address, timeout
-- table to capture response
response = {}
-- message to send
message = "<envelope><body><message>Hello world</message></body></envelope>"
-- address to send to
address = "http://www.example.com:80/some/path"
-- temporarily shorten the timeout
timeout = socket.http.TIMEOUT
socket.http.TIMEOUT = 2
local _, code, headers, status = socket.http.request{
url = address,
sink = ltn12.sink.table(response),
method = "POST",
headers = {
["Content-Length"] = message:len(),
["Content-Type"] = 'text/xml; charset="utf-8"',
},
source = ltn12.source.string(message),
}
-- restore timeout
socket.http.TIMEOUT = timeout
if 200 ~= code then
-- an error occured, do some action here?
end
response = table.concat(response)
Link copied. Please paste this link to share this article on your social media post.
Hi Francisco,
1 - Is there any library (like this one LuaSocket: Installation) is inside the system? ( or any other )
There is exactly mentioned LuaSocket library available inside hL.
2 - There is any example available?
I attached one example below but in general there are many options what you can do with LuaSockets. So probably best answer is "try to google what exactly you need": LuaSocket: Introduction to the core, LuaSocket: HTTP support, any demo code for lua socket, Luasocket server and actionscript, lua socket client
-- send POST message in XML format to some url address...
require("socket.http")
require("ltn12")
local response, message, address, timeout
-- table to capture response
response = {}
-- message to send
message = "<envelope><body><message>Hello world</message></body></envelope>"
-- address to send to
address = "http://www.example.com:80/some/path"
-- temporarily shorten the timeout
timeout = socket.http.TIMEOUT
socket.http.TIMEOUT = 2
local _, code, headers, status = socket.http.request{
url = address,
sink = ltn12.sink.table(response),
method = "POST",
headers = {
["Content-Length"] = message:len(),
["Content-Type"] = 'text/xml; charset="utf-8"',
},
source = ltn12.source.string(message),
}
-- restore timeout
socket.http.TIMEOUT = timeout
if 200 ~= code then
-- an error occured, do some action here?
end
response = table.concat(response)
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
I'm not sure but the code looks a lot like C# dot NET. (I'm an assembler and C as well as C++ guy)
If I'm correct, a network class library should exist that encapsulates all things Internet such as UDP and TCP as well as some of the popular protocols.
If you have any trouble finding libraries, Sourceforge and GodeGuru are a couple of sites worth searching. They have an amazing array of code, some of it good and some of not so good, but pretty much everything ifs free.
If you plan to use any open source professionally (commercially), beware of the license. Some licenses like BSD are pretty much wide open but some versions of GPL have serious restrictions.
Link copied. Please paste this link to share this article on your social media post.
Code is written in Lua, which is scripting language build on "a few" lines of ANSI C. It combines speed of C language and power of scripting and object oriented languages like PHP or Python, only not so comfortable.
Github is also good choice if U need to find some useful lib, but why to do that when Lua already contains pretty good libs in-build?
Link copied. Please paste this link to share this article on your social media post.
Hello,
I did the test and its working pretty fine...
-- Send TCP message to blink the Global Cache power led
-- load the library
local socket = require("socket")
-- definitions of connection
local port = 4998
local ip = '192.168.0.70'
-- create a new TCP object
local tcp = assert(socket.tcp())
-- connects to the port
tcp:connect(ip, port);
-- send the blink message, important to send the char 13 always for this device
assert(tcp:send('blink,1'..string.char(13)))
alert('Device is blinking')
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.