Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fibaro:debug('Starte PING')
- local IP = '192.168.50.3'
- local PORT = 2869
- local versuche = 3
- local iconOFFLINE = "189" -- ANPASSEN; Gerät ist offline
- local iconONLINE = "188" -- ANPASSEN; Gerät ist online
- local iconCHECK = "190" -- ANPASSEN; Gerät wird angepingt
- local function _ping(retry)
- fibaro:call(fibaro:getSelfId(), "setProperty", "currentIcon", iconCHECK)
- retry = retry or 0
- local tcpSocket = Net.FTcpSocket(IP, PORT)
- tcpSocket:setReadTimeout(250)
- fibaro:debug('Suche..., versuche #' .. retry .. ' bitte warten...')
- fibaro:sleep(250)
- local bytes, errorCode = tcpSocket:write('ping')
- if errorCode == 0 then
- return true
- else
- if retry < versuche then
- fibaro:debug('Nicht gefunden, erneut versuchen, bitte warten...')
- fibaro:sleep(1000);
- return _ping(retry + 1)
- end
- return false
- end
- end
- local f, result = pcall(_ping)
- if (f) then
- if (result == true) then
- fibaro:debug(IP.. ':' .. PORT .. ' wurde gefunden.')
- fibaro:setGlobal("Ping_APS_OK", 1);
- fibaro:call(fibaro:getSelfId(), "setProperty", "currentIcon", iconONLINE)
- else
- fibaro:debug(IP.. ':' .. PORT .. ' wurde nicht gefunden.')
- fibaro:setGlobal("Ping_APS_OK", 0);
- fibaro:call(fibaro:getSelfId(), "setProperty", "currentIcon", iconOFFLINE)
- end
- else
- fibaro:debug('Error: ' .. f)
- end
Advertisement
Add Comment
Please, Sign In to add comment