diff --git a/fhem/FHEM/73_PRESENCE2.pm b/fhem/FHEM/73_PRESENCE2.pm index ab13af9a0..6db91cacd 100644 --- a/fhem/FHEM/73_PRESENCE2.pm +++ b/fhem/FHEM/73_PRESENCE2.pm @@ -33,7 +33,7 @@ use Blocking; use Time::HiRes qw(gettimeofday usleep sleep); use DevIo; -my $ModulVersion = "01.03b"; +my $ModulVersion = "01.03c"; my %LOG_Text = ( 0 => "SERVER:", 1 => "ERROR:", @@ -295,10 +295,24 @@ sub PRESENCE2_Define($$) { :($^O =~ m/solaris/) ? "ping $hash->{ADDRESS} 4" : "ping -c 1 -w 1 $hash->{ADDRESS} 2>&1" ; + $hash->{helper}{os}{search} = $^O =~ m/solaris/? 'is alive' : '(ttl|TTL)=\d+' ; + if ($^O !~ m/solaris/ && $^O !~ m/(Win|cygwin)/) { + my $pingAttr = "disable:0,1 " + . "pingParam " + . "thresholdAbsence " + . "intervalNormal " + . "intervalPresent " + . "prGroup:multiple,static,dynamic " + . "prGroupDisp:condense,verbose " + . "FhemLog3Std:0,1 " + . $readingFnAttributes; + setDevAttrList($hash->{NAME}, $pingAttr); + } + } elsif($a[2] eq "lan-bluetooth") { delete $attr{$name}{nonblockingTimeOut}; @@ -409,7 +423,7 @@ sub PRESENCE2_Define($$) { setDevAttrList($hash->{NAME}, $daemonAttr); } else { - my $msg = "unknown mode \"".$a[2]."\" in define statement: Please use lan-ping, daemon, shellscript, function,bluetooth,lan-bluetooth"; + my $msg = "unknown mode \"".$a[2]."\" in define statement: Please use lan-ping, daemon, shellscript, function, bluetooth, lan-bluetooth"; Log 2, "PRESENCE2 ($name) - ".$msg; return $msg } @@ -430,7 +444,7 @@ sub PRESENCE2_Define($$) { InternalTimer(2,"PRESENCE2_updateConfig", $hash->{helper}{updateConfig}); } - PRESENCE2_Log $name, 2, "define gaceful done"; + PRESENCE2_Log $name, 2, "define done"; return undef; } @@ -865,6 +879,23 @@ sub PRESENCE2_Attr(@) { $hash->{helper}{os}{search} = '([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}'; } } + elsif ($a[2] eq "pingParam" ) { + return $a[2] . " only used by ping for Linux" if($hash->{MODE} ne "lan-ping"); + return $a[2] . " only used by ping for Linux/Windows/CygWin" if($^O =~ m/solaris/ || $^O =~ m/(Win|cygwin)/); + + my $regex = qr/(-[cwi] ?\d{1,3}|-q -[cwi] ?\d{1,3}){0,1} ?(-[cwi] ?\d{1,3}|-q -[cwi] ?\d{1,3}){0,1} ?(-[cwi] ?\d{1,3}|-q -[cwi] ?\d{1,3}|-q){0,1}/ip; + + if ( $a[3] =~ m/$regex/g ) { + return $a[2] . " mismatched parameters $a[3]" if length(${^MATCH}) != length($a[3]); + } else { + return $a[2] . " mismatched parameters $a[3]"; + } + + $hash->{helper}{os}{Cmd} = ($^O =~ m/(Win|cygwin)/) ? "ping $a[3] $hash->{ADDRESS}" + : ($^O =~ m/solaris/) ? "ping $hash->{ADDRESS} 4" + : "ping $a[3] $hash->{ADDRESS} 2>&1" + ; + } } @@ -916,6 +947,13 @@ sub PRESENCE2_Attr(@) { $hash->{helper}{os}{Cmd} .= ' ' . $hash->{helper}{os}{hcitoolParam} . ' ' . $hash->{ADDRESS} . ' 2>/dev/null'; } + elsif ($a[2] eq "pingParam" ) { + + $hash->{helper}{os}{Cmd} = ($^O =~ m/(Win|cygwin)/) ? "ping -n 1 -4 $hash->{ADDRESS}" + : ($^O =~ m/solaris/) ? "ping $hash->{ADDRESS} 4" + : "ping -c 1 -w 1 $hash->{ADDRESS} 2>&1" + ; + } } if($a[2] eq "intervalNormal"){ @@ -1183,7 +1221,7 @@ sub PRESENCE2_daemonScanScheduler($;$) { , $nonBlockingTimeout , "PRESENCE2_daemonAbortedScan" , $hash); -# $hash->{helper}{RUNNING_PID}->{loglevel} = GetVerbose($name); + $hash->{helper}{RUNNING_PID}->{loglevel} = GetVerbose($name); } } } @@ -1218,17 +1256,19 @@ sub PRESENCE2_daemonScanReply($) { delete $hash->{helper}{RUNNING_PID}; foreach my $res (@result){ - my ($eName,$eSstate) = split('\|',$res); + my ($eName, $eSstate) = split('\|',$res); + if ($eName) { readingsBeginUpdate($defs{$eName}); PRESENCE2_ProcessState($defs{$eName}, $eSstate); readingsEndUpdate($defs{$eName}, 1); + } } readingsBeginUpdate($hash); readingsBulkUpdate($hash, "state", "active"); foreach (@result){ - my ($eName,$eSstate) = split('\|',$_); - readingsBulkUpdate($hash, "pr_".$eName, $eSstate); + my ($eName, $eSstate) = split('\|',$_); + readingsBulkUpdate($hash, "pr_".$eName, $eSstate) if $eName; } readingsBulkUpdate($hash, 'daemonMaxScanTime', $duration)if ($duration > ReadingsVal($name,'daemonMaxScanTime',0)); @@ -1703,26 +1743,25 @@ Options:
  • - for future use -
    set <name> intervalPresent <seconds>
    +
    attr <name> intervalPresent <seconds>
    Time in seconds to check status if the device is in state present. It is adjusted to the deamons cycle.
    Not applicable for daemon entity

  • -
    set <name> intervalNormal <seconds>
    +
    attr <name> intervalNormal <seconds>
    Time in seconds to check status if the device is in state present. It is adjusted to the deamons cycle.
    Not applicable for daemon entity

  • -
    nonblockingTimeOut <30..240>
    +
    attr <name> nonblockingTimeOut <30..240>>

    timeout for regularly checking presende. Default is 60 (seconds).

  • -
    set <name> bluetoothHciDevice <hci[0..n]>
    +
    attr <name> bluetoothHciDevice <hci[0..n]>
    (Only applicable in local “bluetooth” mode and not applicable to Daemon device)

    Set a specific bluetooth HCI device to use for scanning. If you have multiple bluetooth modules connected,
    @@ -1730,20 +1769,33 @@ Options:

  • -
    set <name> hcitoolParam <name|info>
    +
    attr <name> hcitoolParam <name|info>
    (Only applicable in local “bluetooth” mode and not applicable to Daemon device)

    Selection of which parameter the hcitool should use to recognize a connected bluetooth device
    Default is <name>

  • +
  • +
    attr <name> pingParam <params>
    + (Only available if OS is not Solaris or Windows/CygWin)
    +
    + Parameters, other than the IP/Host, as available in the command reference for the operating system command 'ping'.
    + Default for Linux: -c 1 -w 1
    + Supported Parameters:
    + -q quiet output
    + -c stop after replies
    + -w reply wait in seconds
    + -i seconds between sending each packet
    +

  • +
  • -
    set <name> disable <0|1>
    +
    attr <name> disable <0|1>
    If activated, any check is disabled and state is set to disabled.

  • -
    set <name> prGroup <static|dynamic|...>
    +
    attr <name> prGroup <static|dynamic|...>
    By defining a group, several presence devices can be assigned to a group and monitored.
    <static> predefined.
    <dynamic> predefined.
    @@ -1752,22 +1804,30 @@ Options:

  • -
    set <name> prGroupDisp <condense|verbose>
    +
    attr <name> prGroupDisp <condense|verbose>
    <condense> - Shows presence group information in condensed mode. [default]
    <verbose> - Shows presence group information in verbose mode.

  • +
    attr <name> thresholdAbsence <seconds>
    child only -
    set <name> thresholdAbsence <seconds>

  • -
  • presentCycle
  • - This attribut may be set to any (ANY) instance in FHEM. It defines the requested cycle time that a reading of the entiy needs to be renewed. The daemon will check the reading's update in its interval. Upon violation of the required timing the reading will toggle to absent.
    - The Reading to be superviced is defined in attr presentReading and defaults to state.
    + for readings that shall be monitored +
  • +
    attr <name> presentCycle <seconds>
    + This attribute is available in every device in FHEM. If set, the reading to be monitored will be from the + Attribute presentReading or the default Reading state by the Presence2 daemon for updating + checked. If no update takes place within the defined period of time, the reading "presentState" is displayed in the device. + set to “send”. In the Presence2 daemon device the reading evt_monitoredDevice is generated and set accordingly.
    +

  • -
  • presentReading
  • - This attribut may be set to any (ANY) instance in FHEM. It defines the reading name that is supervices by presentCycle.
    +
  • +
    attr <name> presentReading <name of the reading>
    + This attribute is available in every device in FHEM. It defines the reading that presentCycle monitors + becomes. If the attribute is not set, the reading state is monitored.
    +


  • @@ -2061,26 +2121,25 @@ Optionen:
  • - noch nicht verfügbar -
    set <name> intervalPresent <Sekunden>
    +
    attr <name> intervalPresent <Sekunden>
    Zeit in Sekunden, um den Status zu überprüfen, ob sich das Gerät im Status „Present“ befindet. Es ist an den Dämonenzyklus angepasst.
    Gilt nicht für Daemon-Entitäten

  • -
    set <name> intervalNormal <Sekunden>
    +
    attr <name> intervalNormal <Sekunden>
    Zeit in Sekunden, um den Status zu überprüfen, ob sich das Gerät im Status „Present“ befindet. Es ist an den Dämonenzyklus angepasst.
    Gilt nicht für Daemon-Entitäten

  • -
    nonblockingTimeOut <30..240>
    +
    attr <name> nonblockingTimeOut <30..240>

    Timeout für das regelmäßige prüfen auf Anwesenheit. Standard ist 60 (Sekunden).

  • -
    set <name> bluetoothHciDevice <hci[0..n]>
    +
    attr <name> bluetoothHciDevice <hci[0..n]>
    (Nur im lokalen Modus "bluetooth" und nicht für Daemon Device anwendbar)

    Sofern man mehrere Bluetooth-Empfänger verfügbar hat, kann man mit diesem Attribut ein bestimmten Empfänger auswählen,
    @@ -2088,20 +2147,33 @@ Optionen:

  • -
    set <name> hcitoolParam <name|info>
    +
    attr <name> hcitoolParam <name|info>
    (Nur im lokalen Modus "bluetooth" und nicht für Daemon Device anwendbar)

    Auswahl über welchen Paramter das hcitool ein verbundenes Bluetooth Device erkennen soll.
    Vorgabe ist <name>

  • +
  • +
    attr <name> pingParam <params>
    + (Nur verfügbar, wenn OS nicht Solaris oder Windows/CygWin)
    +
    + Parameter, außer der IP/Host, wie sie in der Befehlsrefrenz für das Betriebssystem Kommando 'ping' verfügbar sind.
    + Default für Linux: -c 1 -w 1
    + Supported Parameters:
    + -q quiet output
    + -c stop after replies
    + -w reply wait in seconds
    + -i seconds between sending each packet
    +

  • +
  • -
    set <name> disable <0|1>
    +
    attr <name> disable <0|1>
    Wenn aktiviert, ist jede Prüfung deaktiviert und der Status wird auf deaktiviert gesetzt.

  • -
    set <name> prGroup <static|dynamic|...>
    +
    attr <name> prGroup <static|dynamic|...>
    Durch die Definition einer Gruppe können mehrere Präsenzgeräte einer Gruppe zugeordnet und überwacht werden.
    <static> vordefiniert.
    <dynamic> vordefiniert.
    @@ -2110,22 +2182,30 @@ Optionen:

  • -
    set <name> prGroupDisp <condense|verbose>
    +
    attr <name> prGroupDisp <condense|verbose>
    <condense> - Zeigt Informationen zur Anwesenheitsgruppe im komprimierten Modus an. [Standard]
    <verbose> – Zeigt Informationen zur Anwesenheitsgruppe im ausführlichen Modus an.

  • Kind-Prozesse -
    set <name> thresholdAbsence <Sekunden>
    +
    attr <name> thresholdAbsence <Sekunden>

  • -
  • presentCycle
  • - Dieses Attribut kann auf jede (JEDE) Instanz in FHEM gesetzt werden. Es definiert die erforderliche Zykluszeit, die eine erneute Lesung des Objekts benötigt. Der Daemon überprüft die Aktualisierung des Messwerts in seinem Intervall. Bei Verstoß gegen die erforderliche Zeitspanne wechselt die Anzeige auf „Abwesend“.
    - Der zu überwachende Messwert wird in attr presentReading definiert und ist standardmäßig state.
    + für Devices, die überwacht werden sollen +
  • +
    attr <name> presentCycle <Sekunden>
    + Dieses Attribut steht in jedem Device in FHEM zur Verfügung. Wenn gesetzt, wird das zu überwachende Reading aus dem + Attribut presentReading oder dem default Reading state durch den Presence2 Daemon auf Aktualisierung + überprüft. Findet innerhalb der definierten Zeitspanne keine Aktuallisierung statt wird im Device das Reading "presentState" + auf "absend" gesetzt. Im Presence2 Dämon Device wird das Reading evt_monitoredDevice generiert und entsprechend gesetzt.
    +

  • -
  • presentReading
  • - Dieses Attribut kann auf jede (JEDE) Instanz in FHEM gesetzt werden. Es definiert den Lesenamen, der von presentCycle überwacht wird.
    +
  • +
    attr <name> presentReading <name des Readings>
    + Dieses Attribut steht in jedem Device in FHEM zur Verfügung. Es definiert das Reading, dass von presentCycle überwacht + wird. Wird das Attribut nicht gesetzt, wird das Reading state> überwacht.
    +