h_tag

Erweiterung VD

Mar 6th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. fibaro:debug('Starte PING')
  2.  
  3.  local IP = '192.168.50.3'
  4. local PORT = 2869
  5. local versuche = 3
  6. local iconOFFLINE = "189" -- ANPASSEN; Gerät ist offline
  7. local iconONLINE = "188" -- ANPASSEN; Gerät ist online
  8. local iconCHECK = "190" -- ANPASSEN; Gerät wird angepingt
  9.  
  10. local function _ping(retry)
  11.   fibaro:call(fibaro:getSelfId(), "setProperty", "currentIcon", iconCHECK)
  12.   retry = retry or 0
  13.   local tcpSocket = Net.FTcpSocket(IP, PORT)
  14.   tcpSocket:setReadTimeout(250)
  15.   fibaro:debug('Suche..., versuche #' .. retry .. ' bitte warten...')
  16.   fibaro:sleep(250)
  17.   local bytes, errorCode = tcpSocket:write('ping')
  18.    
  19.   if errorCode == 0 then
  20.     return true
  21.   else
  22.     if retry < versuche then
  23.       fibaro:debug('Nicht gefunden, erneut versuchen, bitte warten...')
  24.       fibaro:sleep(1000);
  25.       return _ping(retry + 1)
  26.     end
  27.     return false
  28.   end
  29. end
  30.  
  31. local f, result = pcall(_ping)
  32.  
  33. if (f) then
  34.   if (result == true) then
  35.     fibaro:debug(IP.. ':' .. PORT .. ' wurde gefunden.')
  36.     fibaro:setGlobal("Ping_APS_OK", 1);
  37.     fibaro:call(fibaro:getSelfId(), "setProperty", "currentIcon", iconONLINE)
  38.   else
  39.     fibaro:debug(IP.. ':' .. PORT .. ' wurde nicht gefunden.')
  40.     fibaro:setGlobal("Ping_APS_OK", 0);
  41.     fibaro:call(fibaro:getSelfId(), "setProperty", "currentIcon", iconOFFLINE)
  42.   end
  43. else
  44.   fibaro:debug('Error: ' .. f)
  45. end
Advertisement
Add Comment
Please, Sign In to add comment