Ping Device

  • 7 Odpowiedzi
  • 5583 Wyświetleń

0 użytkowników i 1 Gość przegląda ten wątek.

*

Offline marecki_0luk1

  • Administratorzy
  • ***** 430
  • 26
  • Nazwa i wersja ID: HC3 5.070.42 / HC2 4.600
Ping Device
« dnia: Marzec 25, 2015, 10:40:12 pm »
Urządzenie wirtualne pokazujące mój komputerek z mozliwościa PING

--[[
%% properties
%% globals
--]]


local virtualId = fibaro:getSelfId();
local iconIdON = 1016;
local iconIdOFF = 1015;
local _deviceIp = fibaro:getValue(virtualId, 'IPAddress');
local _devicePort =  fibaro:getValue(virtualId, 'TCPPort')

local _maxRetryProcess = 5;
local currentICON;



if tostring(fibaro:getGlobalValue('glComputerState')) == "1" then
fibaro:call(virtualId, "setProperty", "currentIcon",  iconIdON);
elseif tostring(fibaro:getGlobalValue('glComputerState')) == "0" then
fibaro:call(virtualId, "setProperty", "currentIcon",  iconIdOFF);
end;


fibaro:log("Start process");

local function _ping(retry)
  retry = retry or 0;
  local tcpSocket = Net.FTcpSocket(_deviceIp, _devicePort);
  tcpSocket:setReadTimeout(250);
  fibaro:log("Search on the local network, try #" .. retry .. " please wait...");
  fibaro:sleep(250);
  --send packet
  local bytes, errorCode = tcpSocket:write("ping");
  --check for error 
  if errorCode == 0 then
  return true;
  else
  if retry < _maxRetryProcess then
      fibaro:call(virtualId, "setProperty", "currentIcon",  iconIdOFF);
    fibaro:log("Retry process, please wait...");
      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:log("Server has been found, is awake and listening.");
    fibaro:call(virtualId, "setProperty", "currentIcon",  iconIdON);
    fibaro:setGlobal('glComputerState', "1")
  else
    fibaro:log("Server was not found!");
    fibaro:call(virtualId, "setProperty", "currentIcon",  iconIdOFF);
    fibaro:setGlobal('glComputerState', "0")
  end
else
  fibaro:log("Error: " .. f);
  fibaro:call(virtualId, "setProperty", "currentIcon",  iconIdOFF);
end

*

Offline tom3sko

  • ** 94
  • 1
  • Nazwa i wersja ID: HC 2 4.110
Odp: Ping Device
« Odpowiedź #1 dnia: Styczeń 30, 2016, 11:00:27 pm »
Czy pomógł by mi ktoś przerobić ten skrypt ?

Chciałbym aby skrypt przeszukał siec  od 192.168.1.1 do 192.168.1.255
Jesli znajdzie  ip zdefiniowane w skrypcie (a bedzie ich 10) to napisze ze to telefon ani, następny że to telefon kamila itd..
a jesłi znajdzie ip ktore nie jest zdefiniowane to napisze ze mamy w sieci goscia

*

Offline marecki_0luk1

  • Administratorzy
  • ***** 430
  • 26
  • Nazwa i wersja ID: HC3 5.070.42 / HC2 4.600
Odp: Ping Device
« Odpowiedź #2 dnia: Luty 21, 2016, 11:24:22 pm »
local lvn_DeviceID = fibaro:getSelfId();
local lvs_SearchDeviceIP = '192.168.1.';
local lvn_SearchDeviceIP ;
local lvn_SearchDevicePort = 80;
local lvn_RetryNum = 1;

fibaro:log("Scan network");

local function fb_ping(ip_retry, ip_SearchDeviceIP, ip_SearchDevicePort)
  ip_retry = ip_retry or 0;
  local tcpSocket = Net.FTcpSocket(lvn_SearchDeviceIP, lvn_SearchDevicePort);
  tcpSocket:setReadTimeout(250);
  fibaro:log("Search on the local network, try #" .. ip_retry .. " please wait...");
  fibaro:sleep(250);
  --send packet
  local bytes, errorCode = tcpSocket:write("ping");
  --check for error 
  if errorCode == 0 then
  return true;
  else
  if ip_retry < lvn_RetryNum then
      fibaro:call(lvn_DeviceID, "setProperty", "currentIcon",  iconIdOFF);
    fibaro:log("Retry process, please wait...");
      fibaro:sleep(1000);
      return fb_ping(ip_retry + 1);
    end
    return false;
  end
end

for i=1, 254, 1 do
lvn_SearchDeviceIP = lvs_SearchDeviceIP .. i;
--fibaro:debug('Searching for IP: ' .. lvn_SearchDeviceIP);
lvb_result = fb_ping(lvn_RetryNum, lvn_SearchDeviceIP, lvn_SearchDevicePort);
if lvb_result then
fibaro:debug('IP: ' .. lvn_SearchDeviceIP .. ' found');
end;
end;

*

Offline confesor

  • ** 82
  • 1
  • Nazwa i wersja ID: Hc2 4.056/4.100 HCLite/ bluboc/Samsung
Odp: Ping Device
« Odpowiedź #3 dnia: Luty 16, 2017, 12:48:42 am »
male pytanko gdzie znajde id ikon??
*

Offline Akronaut

  • ** 71
  • 1
  • Nazwa i wersja ID: HC 2 +HCL, 4.580
Odp: Ping Device
« Odpowiedź #4 dnia: Luty 17, 2017, 08:10:00 am »
LUA nie znam :(
czy ktoś z Koleżanek/Kolegów może zmodyfikować tak, aby po wykryciu w sieci konkretnego IP zmieniało wartość zmiennej?
Fibaro HC2 v 4.580 + HCL v 4.580   13*RS2   6*roleta dachowa Fakro  14*MS   4*DW sensor   9*Dimmer 2   14*Switch  2*1,5kW    2*Button   3*Wall Plug    1*SmokeSensor    2*UBS   1*Keyfob   2*elektrozawór  1*czujnik deszczu   1*GERDALOCK    4*IP kamera   329 scen   68 zmienne  12*VD   3*Android Phone
*

Offline marecki_0luk1

  • Administratorzy
  • ***** 430
  • 26
  • Nazwa i wersja ID: HC3 5.070.42 / HC2 4.600
Odp: Ping Device
« Odpowiedź #5 dnia: Luty 22, 2017, 04:09:05 pm »
*

Offline marecki_0luk1

  • Administratorzy
  • ***** 430
  • 26
  • Nazwa i wersja ID: HC3 5.070.42 / HC2 4.600
Odp: Ping Device
« Odpowiedź #6 dnia: Luty 23, 2017, 03:23:27 pm »
LUA nie znam :(
czy ktoś z Koleżanek/Kolegów może zmodyfikować tak, aby po wykryciu w sieci konkretnego IP zmieniało wartość zmiennej?

ale to właśnie tak działa..... pierwszy post.
*

Offline Akronaut

  • ** 71
  • 1
  • Nazwa i wersja ID: HC 2 +HCL, 4.580
Odp: Ping Device
« Odpowiedź #7 dnia: Luty 23, 2017, 07:03:10 pm »
Czyli wydało się, że się nie znam ...
Możesz mi przygotować ten skrypt z moimi danymi dla jednego urządzenia? Myślę, że mając gotowca z resztą urządzeń sobie poradzę.
Fibaro HC2 v 4.580 + HCL v 4.580   13*RS2   6*roleta dachowa Fakro  14*MS   4*DW sensor   9*Dimmer 2   14*Switch  2*1,5kW    2*Button   3*Wall Plug    1*SmokeSensor    2*UBS   1*Keyfob   2*elektrozawór  1*czujnik deszczu   1*GERDALOCK    4*IP kamera   329 scen   68 zmienne  12*VD   3*Android Phone