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.

ELK M1 Alarm panel
#9
(19.08.2017, 23:32)rocfusion Wrote: Hi Admin,

Ok so with a slight modification its now working, see the revised code below.  Question in terms of error handling for the connection will this be sufficient for this client script to reconnect if for whatever reason the connection is lost?

Thanks,

Roger



Code:
if not skt then
 skt = socket.tcp()
 skt:settimeout(5)
 skt:connect('192.168.0.11', 2601)
 skt, err = ssl.wrap(skt,'tlsv1')
 if not err then
   skt:dohandshake()
   skt = copas.wrap(skt)
   copas.addthread(function()
       while true do
         local resp,err = copas.receive(skt)
         -- if theres no connection start a new connection
         if not resp or err ~=nil then
           alert("[elk-client] Receive error: %s", err)
           copas.removeserver(skt)
           skt = nil
           break
         end
         if(string.find(resp,'^16XK')==nil)then
           local fd,prtd = pcall(parse,resp)
           if(fd==false)then
             alert("[elk-client] Error with parsemsg %s ",prtd)
           end
         else
           alert('[elk-client] time message: %s', resp)
         end
       end
     end)
 else              
   alert("[elk-client] connection error: %s", err)
   skt = nil
   return
 end
end

Hi Admin,  is this ok?
Thx
Roger
Reply


Messages In This Thread
ELK M1 Alarm panel - by rocfusion - 07.08.2017, 17:04
RE: ELK M1 Alarm panel - by admin - 08.08.2017, 08:50
RE: ELK M1 Alarm panel - by rocfusion - 12.08.2017, 23:21
RE: ELK M1 Alarm panel - by admin - 14.08.2017, 06:13
RE: ELK M1 Alarm panel - by rocfusion - 14.08.2017, 17:14
RE: ELK M1 Alarm panel - by admin - 17.08.2017, 06:30
RE: ELK M1 Alarm panel - by rocfusion - 17.08.2017, 07:07
RE: ELK M1 Alarm panel - by rocfusion - 19.08.2017, 23:32
RE: ELK M1 Alarm panel - by rocfusion - 22.08.2017, 06:31
RE: ELK M1 Alarm panel - by admin - 22.08.2017, 06:52

Forum Jump: