This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LM Ambient with GC-WF2IR
#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).
Reply
#2
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)
Reply
#3
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 "
Reply
#4
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.
Reply
#5
Okay. Now worked with Notepad.
But, the script not working and still not triggering command into Global Cache.
Reply
#6
(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.
Reply
#7
Ok, it looks like GlobalCache does not work without extra receive on the socket. Examples above should work now.
Reply
#8
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
Reply
#9
It's added during send:
Code:
res, err = sock:send(cmd .. '\r')
Reply
#10
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?
Reply
#11
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
Reply
#12
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.
Reply
#13
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()
  sockConfusedettimeout(3)
  res, err = sock:connect(ip, port or 4998)
  
  if res then
    res, err = sockConfusedend(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
Reply
#14
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')
Reply
#15
Hi Admin ES
Thank you so much
Reply
#16
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 Smile
Have no idea why this is the case....
BR,
Mr.D
Reply
#17
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
Reply
#18
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.
Reply
#19
(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
Reply
#20
Basically you need to add collectgarbage('collect') after tcpsend(cmd). You can set sleep time to 0.
Reply


Forum Jump: