adding the presence check via fritzbox ctlmgr_ctl command
git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2640 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -62,7 +62,8 @@ PRESENCE_Define($$)
|
|||||||
my @a = split("[ \t]+", $def);
|
my @a = split("[ \t]+", $def);
|
||||||
my $dev;
|
my $dev;
|
||||||
|
|
||||||
if($a[2] ne "lan-bluetooth" and not (@a == 4 or @a == 5)) {
|
if($a[2] ne "lan-bluetooth" and not (@a == 4 or @a == 5))
|
||||||
|
{
|
||||||
my $msg = "wrong syntax: define <name> PRESENCE <mode> <device-address> [ <timeout> ]";
|
my $msg = "wrong syntax: define <name> PRESENCE <mode> <device-address> [ <timeout> ]";
|
||||||
Log 2, $msg;
|
Log 2, $msg;
|
||||||
return $msg;
|
return $msg;
|
||||||
@@ -106,10 +107,25 @@ PRESENCE_Define($$)
|
|||||||
{
|
{
|
||||||
my $msg = "given address is not a bluetooth hardware address";
|
my $msg = "given address is not a bluetooth hardware address";
|
||||||
Log 2, "PRESENCE: ".$msg;
|
Log 2, "PRESENCE: ".$msg;
|
||||||
return $msg
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($destination eq "fritzbox" and not -X "/usr/bin/ctlmgr_ctl")
|
||||||
|
{
|
||||||
|
my $msg = "this is not a fritzbox or you running FHEM with the AVM Beta Image. Please use the FHEM FritzBox Image from fhem.de";
|
||||||
|
Log 2, "PRESENCE: ".$msg;
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($destination eq "fritzbox" and not $< == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
my $msg = "FHEM is not running under root (currently ".(getpwuid($<))[0].") This check can only performed with root access to the FritzBox";
|
||||||
|
Log 2, "PRESENCE: ".$msg;
|
||||||
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($destination eq "lan-ping" or $destination eq "local-bluetooth")
|
if($destination eq "lan-ping" or $destination eq "local-bluetooth" or $destination eq "fritzbox")
|
||||||
{
|
{
|
||||||
|
|
||||||
$hash->{MODE} = $destination;
|
$hash->{MODE} = $destination;
|
||||||
@@ -144,6 +160,11 @@ PRESENCE_Define($$)
|
|||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
return "unknown mode: $destination Please use lan-ping, lan-bluetooth or local-bluetooth";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -321,6 +342,11 @@ my ($hash) = @_;
|
|||||||
BlockingCall("PRESENCE_DoLocalPingScan", $hash->{NAME}."|".$hash->{ADDRESS}, "PRESENCE_ProcessLocalScan", 20);
|
BlockingCall("PRESENCE_DoLocalPingScan", $hash->{NAME}."|".$hash->{ADDRESS}, "PRESENCE_ProcessLocalScan", 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
elsif($hash->{MODE} eq "fritzbox")
|
||||||
|
{
|
||||||
|
BlockingCall("PRESENCE_DoLocalFritzBoxScan", $hash->{NAME}."|".$hash->{ADDRESS}, "PRESENCE_ProcessLocalScan", 20);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@@ -351,9 +377,58 @@ return $return;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
PRESENCE_DoLocalFritzBoxScan($)
|
||||||
|
{
|
||||||
|
my ($string) = @_;
|
||||||
|
my ($name, $device) = split("\\|", $string);
|
||||||
|
|
||||||
|
my $number=0;
|
||||||
|
|
||||||
|
my $max = qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice/count);
|
||||||
|
|
||||||
|
chomp $max;
|
||||||
|
|
||||||
|
if(not $max =~ /^\s*\d+\s*$/)
|
||||||
|
{
|
||||||
|
return "$name|error|could not execute ctlmgr_ctl";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my $status=0;
|
||||||
|
my $net_device;
|
||||||
|
|
||||||
|
while($number <= $max)
|
||||||
|
{
|
||||||
|
$net_device=qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/name);
|
||||||
|
|
||||||
|
chomp $net_device;
|
||||||
|
|
||||||
|
if($net_device eq $device)
|
||||||
|
{
|
||||||
|
$status=qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/active);
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
$number++;
|
||||||
|
}
|
||||||
|
|
||||||
|
chomp $status;
|
||||||
|
|
||||||
|
if($status == 1)
|
||||||
|
{
|
||||||
|
return "$name|present";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "$name|absent";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
PRESENCE_DoLocalBluetoothScan($$)
|
PRESENCE_DoLocalBluetoothScan($)
|
||||||
{
|
{
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
my ($name, $device) = split("\\|", $string);
|
my ($name, $device) = split("\\|", $string);
|
||||||
@@ -450,6 +525,7 @@ PRESENCE_ProcessLocalScan($)
|
|||||||
This module provides several operational modes to serve your needs. These are:<br><br>
|
This module provides several operational modes to serve your needs. These are:<br><br>
|
||||||
<ul>
|
<ul>
|
||||||
<li><b>lan-ping</b> - A presence check of a device via network ping in your LAN/WLAN</li>
|
<li><b>lan-ping</b> - A presence check of a device via network ping in your LAN/WLAN</li>
|
||||||
|
<li><b>fritzbox</b> - A presence check by requesting the device state from the FritzBox internals (only available when running FHEM on a FritzBox!)
|
||||||
<li><b>local-bluetooth</b> - A presence check by searching directly for a given bluetooth device nearby</li>
|
<li><b>local-bluetooth</b> - A presence check by searching directly for a given bluetooth device nearby</li>
|
||||||
<li><b>lan-bluetooth</b> - A presence check of a bluetooth device via LAN network by connecting to a presenced or collectord instance</li>
|
<li><b>lan-bluetooth</b> - A presence check of a bluetooth device via LAN network by connecting to a presenced or collectord instance</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -461,6 +537,11 @@ PRESENCE_ProcessLocalScan($)
|
|||||||
<br>
|
<br>
|
||||||
Checks for a network device via PING requests and reports its presence state.<br>
|
Checks for a network device via PING requests and reports its presence state.<br>
|
||||||
<br>
|
<br>
|
||||||
|
<b>Mode: fritzbox</b><br><br>
|
||||||
|
<code>define <name> PRESENCE fritzbox <device-name> [ <timeout> ]</code><br>
|
||||||
|
<br>
|
||||||
|
Checks for a network device by requesting the internal state on a FritzBox via ctlmgr_ctl. The device-name must be the same as shown in the network overview of the FritzBox<br>
|
||||||
|
<br>
|
||||||
<b>Mode: local-bluetooth</b><br><br>
|
<b>Mode: local-bluetooth</b><br><br>
|
||||||
<code>define <name> PRESENCE local-bluetooth <bluetooth-address> [ <timeout> ]</code><br>
|
<code>define <name> PRESENCE local-bluetooth <bluetooth-address> [ <timeout> ]</code><br>
|
||||||
<br>
|
<br>
|
||||||
@@ -516,7 +597,7 @@ Options:
|
|||||||
It listens on TCP port 5222 for incoming connections from a FHEM presence instance.
|
It listens on TCP port 5222 for incoming connections from a FHEM presence instance.
|
||||||
<PRE>
|
<PRE>
|
||||||
Usage:
|
Usage:
|
||||||
collectord -c <configfile> [-d] [-p <port>] [-P <pidfile>]
|
collectord -c <configfile> [-d] [-p <port>] [-P <pidfile>]
|
||||||
collectord [-h | --help]
|
collectord [-h | --help]
|
||||||
|
|
||||||
|
|
||||||
@@ -616,4 +697,4 @@ Options:
|
|||||||
|
|
||||||
=end html
|
=end html
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
Reference in New Issue
Block a user