03.10.2022, 12:42 
		
	
	
		Hi
I have a script which I use to monitor the zones in a remote alarm system. It's a looping script which processes the data coming in from a socket connection. I need one instance of the script running continuously.
What's the best place to locate this (script below) - is it as a resident script with a 0 interval time or as an init script or somewhere else?
Many thanks in advance
Kind Regards,
James
	
	
	
	
I have a script which I use to monitor the zones in a remote alarm system. It's a looping script which processes the data coming in from a socket connection. I need one instance of the script running continuously.
What's the best place to locate this (script below) - is it as a resident script with a 0 interval time or as an init script or somewhere else?
Many thanks in advance
Kind Regards,
James
Code:
-- Initialise socket connection
if not sock then
  require('socket')
 
  sock, err = socket.connect('192.168.1.100', 2401)
  if sock then
    sock:settimeout(1)
  else
    log('Error connecting ' .. err)
    sleep(5)
  end
end
 
-- Process data received
if sock then    
  
  while true do
    rec = sock:receive('*l')
    if rec then
      
      data = lmcore.hextostr(rec, true)
      st, addr, len, cmd, event, id, area = data:byte(1, 7)
 
        if (event == 0) then
          log('Door open in Zone ' .. id)
        else
          log('Door closed in Zone ' .. id)
        end
     
    end
  end
  
end