Posts: 24
Threads: 9
Joined: Jan 2016
Reputation:
1
Trying to integrate Global Cache iTach WF2IR with LM-Ambient.
Scripting done with the help of example in openrb.com ( http://openrb.com/2637-2/)
Still, no command is triggering to the Global Cache.
Also, checked the errors log in LM (no errors there) and commands testing with the iTest software by Global Cache (here, commands are triggering fine).
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
This example comes from our partners, we haven't tested it locally. I've modified it to provide error reporting which can be seen in Alerts tab.
Put this into Common functions:
Code: function sendircmd(cmd, ip, port)
local sock, res, err
sock = require('socket').tcp()
sock:settimeout(3)
res, err = sock:connect(ip, port or 4998)
if res then
res, err = sock:send(cmd .. '\r')
if res then
res, err = sock:receive()
else
alert('send failed: ' .. tostring(err))
end
else
alert('connect failed: ' .. tostring(err))
end
sock:close()
return res, err
end
This goes into event script, make sure to modify cmd and ip:
Code: cmd = 'sendir,1:1,1,37650,1,1,341,171,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64,21,1520,342,85,21,3765'
res, err = sendircmd(cmd, '192.168.1.1', 4998)
log(res, err)
Posts: 24
Threads: 9
Joined: Jan 2016
Reputation:
1
Not able to save the script because of the error " Lua syntax error at line 2: '=' expected near '�' "
Line 2 is " local sock, res, err "
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
You are probably using Chrome which is copying spaces incorrectly. Copy script to any plain text editor like Notepad, then copy it from there to LM script editor.
Posts: 24
Threads: 9
Joined: Jan 2016
Reputation:
1
Okay. Now worked with Notepad.
But, the script not working and still not triggering command into Global Cache.
Posts: 155
Threads: 12
Joined: Sep 2015
Reputation:
13
01.07.2016, 09:50
(This post was last modified: 01.07.2016, 09:52 by AEK.)
(01.07.2016, 09:18)s.prathmesh Wrote: Okay. Now worked with Notepad.
But, the script not working and still not triggering command into Global Cache.
example from Russia:
code for event- based script
Code: local socket = require("socket")
local tcp = assert(socket.tcp())
tcp:connect(IP_adress, port); -- IP_adress: IP adress
-- of GlobalCache
-- port: port number of
-- GlobalCache
-- default port: 4998
tcp:send(GC_Command); -- GC_Command: string to send to
-- GlobalCache
tcp:receive()
tcp:close()
example of command
Code: DevIR05CmdH="sendir,1:1,1,37650,1,1,"; -- constant part of IR command
tcp:send(DevIR05CmdH ..
"341,171,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,
21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,
64,21,21,21,64,21,64,21,64,21,1520,342,85,21,3765\r");
-- "\r" = "0D" (Hex) in LogicMachine.
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
Ok, it looks like GlobalCache does not work without extra receive on the socket. Examples above should work now.
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
01.07.2016, 11:01
(This post was last modified: 01.07.2016, 11:03 by Erwin van der Zwart.)
Hi,
Your first script should work but i think you just missed the carrier return \r on the end of your cmd send string
Must be:
cmd = 'sendir,1:1,1,37650,1,1,341,171,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64,21,1520,342,85,21,3765\r'
BR,
Erwin
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
It's added during send:
Code: res, err = sock:send(cmd .. '\r')
Posts: 24
Threads: 9
Joined: Jan 2016
Reputation:
1
Thanks all for the replies.
At times, Ambient gives commands on GC-WF2IR; but after continuous triggering of commands GC-WF2IR stops receiving the commands. As GC-WF2IR blinks LED alongside the port through which it sends commands, we know about its status/working.
So, after restarting GC-WF2IR/Ambient the problem solves for some time but again after continuous triggering we've to again reboot the devices.
What could be parameters we may be missing?
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
Hi,
You have to send the socket close command to the receiving unit, otherwise each call opens a new socket, i believe global cache has max 8 socket connections.
Each connection has a timeout of 1 minute so if you don't send the socket close to the global cache it will block for x period (the socket relaese auto when the timeout is passed).
The tcp:close() only closes the server side connection.
BR,
Erwin van der Zwart
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
If you are using this script http://forum.logicmachine.net/showthread...17#pid1617 then you should have error reports in Alerts tab when LM cannot connect/send commands. I haven't found a specific "close" command for GC, so maybe a better solution is to have a resident script which has a single connection that is always open. But then you have to take care of timeout disconnects from the GC itself.
Posts: 2
Threads: 0
Joined: Sep 2017
Reputation:
0
Hi every body!
Sorry I working with LM5 Reactor I/O and WF2IR.
after I using script: http://openrb.com/2637-2/ and using Put this into Common functions:"function sendircmd(cmd, ip, port)
local sock, res, err
sock = require('socket').tcp()
sock ettimeout(3)
res, err = sock:connect(ip, port or 4998)
if res then
res, err = sock end(cmd .. '\r')
if res then
res, err = sock:receive()
else
alert('send failed: ' .. tostring(err))
end
else
alert('connect failed: ' .. tostring(err))
end
sock:close()
return res, err
end"
But I am still error after 8 times the same Mr. Erwin van der Zwart say.
Help me
Thank you
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
1. Create resident script to keep TCP connection open and handle reconnect, change IP as needed:
Code: if not udpserver then
require('socket')
tcphost, tcpport = '192.168.2.15', 4998
function tcpclose()
if tcpclient then
tcpclient:close()
tcpclient = nil
end
end
function tcpconnect()
local res, err
-- socket already open
if tcpclient then
return tcpclient
end
-- create new sock
tcpclient = socket.tcp()
-- create ok
if tcpclient then
tcpclient:settimeout(1)
res, err = tcpclient:connect(tcphost, tcpport)
-- connect ok
if res then
return tcpclient
-- connect failed
else
alert('connection failed ' .. tostring(err))
tcpclose()
end
else
alert('failed to create socket ' .. tostring(err))
end
end
function tcpsend(cmd, retry)
local sock = tcpconnect()
if sock then
local res, err = sock:send(cmd)
if res then
sock:receive()
end
-- send failed, retry once
if not res and not retry then
tcpclose()
tcpsend(cmd, true)
end
end
end
udpserver = socket.udp()
udpserver:setsockname('127.0.0.1', 4321)
udpserver:settimeout(1)
end
cmd = udpserver:receive()
if cmd then
tcpsend(cmd)
end
2. Add to common functions:
Code: function irsend(cmd)
require('socket').udp():sendto(cmd, '127.0.0.1', 4321)
end
3. Call from event scripts:
Code: irsend('sendir,1:1,1,37650,1,1,341,171,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64,21,1520,342,85,21,3765\r')
Posts: 2
Threads: 0
Joined: Sep 2017
Reputation:
0
Hi Admin ES
Thank you so much
Posts: 136
Threads: 18
Joined: Apr 2017
Reputation:
1
01.12.2018, 12:17
(This post was last modified: 01.12.2018, 12:55 by Mr.D.)
Hi,
I have been running these scripts for more than a year, but now it seems like my TCP connection is no longer working.... I have done no changes to my network hardware, SpaceLynk scripts or Global Cache.
However, I can see that every time the scripts are triggered the load on the SpaceLynk goes from 0.3 to 3.xx so there is something wrong somewhere!
Any suggestions?
SOLVED:
For some reason my TCP port 4321 has stopped working so changing it to 4322 did the trick
Have no idea why this is the case....
BR,
Mr.D
Posts: 136
Threads: 18
Joined: Apr 2017
Reputation:
1
Hi,
I might have spoken to soon.
I have been running the resident script for a long time, and everything has been working as intended.
However, recently the spacelynk has stopped connecting to the Global Cache.
I have found that disabling the resident script for a couple of minutes, and then re-activating it, the connection seems to work again... it almost seems like there is an issue with timeout or spamming the global cache or an network issue?
As for network I use the Unifi Secure Gateway, Unifi Switch and Unify AC Pro... both spacelynk and GC are running on the same subnetwork.
I have the resident script running at a 30 seconds interval, I have also tried to changing this to 60 seconds, but after a couple of days it still stops working.
Any suggestion?
BR,
Mr.D
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
Try this:
Code: cmd = udpserver:receive()
if cmd then
tcpsend(cmd)
collectgarbage('collect')
end
There's no need to set large sleep for this script, it should work correctly with 0 sleep time.
Posts: 136
Threads: 18
Joined: Apr 2017
Reputation:
1
(17.12.2018, 12:22)admin Wrote: Try this:
Code: cmd = udpserver:receive()
if cmd then
tcpsend(cmd)
collectgarbage('collect')
end
There's no need to set large sleep for this script, it should work correctly with 0 sleep time.
I just add this part to end of the existing script?
And I should set the interval sleep to 0?
BR,
Mr.D
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
Basically you need to add collectgarbage('collect') after tcpsend(cmd). You can set sleep time to 0.
|