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
#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


Messages In This Thread
LM Ambient with GC-WF2IR - by s.prathmesh - 01.07.2016, 07:42
RE: LM Ambient with GC-WF2IR - by admin - 01.07.2016, 07:54
RE: LM Ambient with GC-WF2IR - by s.prathmesh - 01.07.2016, 08:54
RE: LM Ambient with GC-WF2IR - by admin - 01.07.2016, 08:57
RE: LM Ambient with GC-WF2IR - by s.prathmesh - 01.07.2016, 09:18
RE: LM Ambient with GC-WF2IR - by AEK - 01.07.2016, 09:50
RE: LM Ambient with GC-WF2IR - by admin - 01.07.2016, 10:02
RE: LM Ambient with GC-WF2IR - by admin - 01.07.2016, 11:03
RE: LM Ambient with GC-WF2IR - by s.prathmesh - 11.07.2016, 11:50
RE: LM Ambient with GC-WF2IR - by admin - 12.07.2016, 06:03
RE: LM Ambient with GC-WF2IR - by Anh Nguyen - 22.11.2017, 09:38
RE: LM Ambient with GC-WF2IR - by admin - 22.11.2017, 13:50
RE: LM Ambient with GC-WF2IR - by Anh Nguyen - 24.11.2017, 02:04
RE: LM Ambient with GC-WF2IR - by Mr.D - 01.12.2018, 12:17
RE: LM Ambient with GC-WF2IR - by Mr.D - 17.12.2018, 11:21
RE: LM Ambient with GC-WF2IR - by admin - 17.12.2018, 12:22
RE: LM Ambient with GC-WF2IR - by Mr.D - 17.12.2018, 12:25
RE: LM Ambient with GC-WF2IR - by admin - 17.12.2018, 12:27
RE: LM Ambient with GC-WF2IR - by Mr.D - 17.12.2018, 12:32
RE: LM Ambient with GC-WF2IR - by admin - 17.12.2018, 12:42
RE: LM Ambient with GC-WF2IR - by Mr.D - 03.01.2019, 23:00
RE: LM Ambient with GC-WF2IR - by Sumit - 30.01.2020, 06:29
RE: LM Ambient with GC-WF2IR - by admin - 30.01.2020, 08:05

Forum Jump: