mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-09 20:57:11 +00:00

introduced GPLv2 git-svn-id: https://svn.fhem.de/fhem/trunk@2099 2b470e98-0d58-463d-a4d8-8e2adae1ed80
214 lines
5.0 KiB
Perl
Executable File
214 lines
5.0 KiB
Perl
Executable File
# $Id$
|
|
##############################################################################
|
|
#
|
|
# 72_FB_CALLMONITOR.pm
|
|
# Connects to a FritzBox Fon via network.
|
|
# When a call is received or takes place it creates an event with further call informations.
|
|
# This module has no sets or gets as it is only used for event triggering.
|
|
#
|
|
# Copyright by Markus Bloch
|
|
# e-mail:
|
|
#
|
|
# This file is part of fhem.
|
|
#
|
|
# Fhem is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Fhem is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
##############################################################################
|
|
|
|
package main;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
sub FB_CALLMONITOR_Read($);
|
|
|
|
sub
|
|
FB_CALLMONITOR_Initialize($)
|
|
{
|
|
my ($hash) = @_;
|
|
|
|
require "$attr{global}{modpath}/FHEM/DevIo.pm";
|
|
|
|
# Provider
|
|
$hash->{ReadFn} = "FB_CALLMONITOR_Read";
|
|
$hash->{ReadyFn} = "FB_CALLMONITOR_Ready";
|
|
$hash->{DefFn} = "FB_CALLMONITOR_Define";
|
|
$hash->{UndefFn} = "FB_CALLMONITOR_Undef";
|
|
$hash->{AttrList}= "event-on-update-reading event-on-change-reading";
|
|
|
|
}
|
|
|
|
#####################################
|
|
sub
|
|
FB_CALLMONITOR_Define($$)
|
|
{
|
|
my ($hash, $def) = @_;
|
|
my @a = split("[ \t][ \t]*", $def);
|
|
|
|
if(@a != 3) {
|
|
my $msg = "wrong syntax: define <name> FB_CALLMONITOR ip[:port]";
|
|
Log 2, $msg;
|
|
return $msg;
|
|
}
|
|
DevIo_CloseDev($hash);
|
|
|
|
my $name = $a[0];
|
|
my $dev = $a[2];
|
|
$dev .= ":1012" if($dev !~ m/:/ && $dev ne "none" && $dev !~ m/\@/);
|
|
|
|
|
|
$hash->{DeviceName} = $dev;
|
|
my $ret = DevIo_OpenDev($hash, 0, "FB_CALLMONITOR_DoInit");
|
|
return $ret;
|
|
}
|
|
|
|
|
|
#####################################
|
|
sub
|
|
FB_CALLMONITOR_Undef($$)
|
|
{
|
|
my ($hash, $arg) = @_;
|
|
my $name = $hash->{NAME};
|
|
|
|
DevIo_CloseDev($hash);
|
|
return undef;
|
|
}
|
|
|
|
|
|
|
|
#####################################
|
|
# No get commands possible, as we just receive the events from the FritzBox.
|
|
sub
|
|
FB_CALLMONITOR_ReadAnswer($$$)
|
|
{
|
|
|
|
return "Get command is not supported by this module";
|
|
|
|
}
|
|
|
|
#####################################
|
|
# Receives an event and creates several readings for event triggering
|
|
sub
|
|
FB_CALLMONITOR_Read($)
|
|
{
|
|
my ($hash) = @_;
|
|
|
|
my $buf = DevIo_SimpleRead($hash);
|
|
return "" if(!defined($buf));
|
|
my $name = $hash->{NAME};
|
|
my @array;
|
|
my $data = "";
|
|
$data .= $buf;
|
|
|
|
|
|
@array = split(";", $data);
|
|
readingsBeginUpdate($hash);
|
|
readingsBulkUpdate($hash, "event", lc($array[1]));
|
|
readingsBulkUpdate($hash, "external_number", $array[3]) if(not $array[3] eq "0" and $array[1] eq "RING");
|
|
readingsBulkUpdate($hash, "internal_number", $array[4]) if($array[1] eq "RING");
|
|
readingsBulkUpdate($hash, "external_number" , $array[5]) if($array[1] eq "CALL");
|
|
readingsBulkUpdate($hash, "internal_number", $array[4]) if($array[1] eq "CALL");
|
|
readingsBulkUpdate($hash, "used_connection", $array[5]) if($array[1] eq "RING");
|
|
readingsBulkUpdate($hash, "used_connection", $array[6]) if($array[1] eq "CALL");
|
|
|
|
|
|
readingsEndUpdate($hash, 1);
|
|
|
|
}
|
|
|
|
sub
|
|
FB_CALLMONITOR_DoInit($)
|
|
{
|
|
|
|
# No Initialization needed
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
sub
|
|
FB_CALLMONITOR_Ready($)
|
|
{
|
|
my ($hash) = @_;
|
|
|
|
return DevIo_OpenDev($hash, 1, "FB_CALLMONITOR_DoInit");
|
|
|
|
}
|
|
|
|
1;
|
|
|
|
=pod
|
|
=begin html
|
|
|
|
<a name="FB_CALLMONITOR"></a>
|
|
<h3>FB_CALLMONITOR</h3>
|
|
<ul>
|
|
<tr><td>
|
|
The FB_CALLMONITOR module connects to a AVM FritzBox Fon and listens for telephone
|
|
events (Receiving incoming call, Making a call)
|
|
<br><br>
|
|
In order to use this module with fhem you <b>must</b> enable the CallMonitor feature via
|
|
telephone shortcode.<br><br>
|
|
<ul>
|
|
<code>#96*5* - for activating<br>#96*4* - for deactivating</code>
|
|
</ul>
|
|
|
|
<br>
|
|
Just dial the shortcode for activating on one of your phones, after 3 seconds just hang up. The feature is now activated.
|
|
<br>
|
|
After activating the CallMonitor-Support in your FritzBox, this module is able to
|
|
generate an event for each call.
|
|
<br><br>
|
|
This module work with any FritzBox Fon model.
|
|
<br><br>
|
|
|
|
<a name="FB_CALLMONITORdefine"></a>
|
|
<b>Define</b>
|
|
<ul>
|
|
<code>define <name> FB_CALLMONITOR <ip-address>[:port]</code><br>
|
|
<br>
|
|
port is 1012 by default.
|
|
<br>
|
|
</ul>
|
|
<br>
|
|
|
|
<a name="FB_CALLMONITORset"></a>
|
|
<b>Set</b>
|
|
<ul>
|
|
N/A
|
|
</ul>
|
|
<br>
|
|
|
|
<a name="FB_CALLMONITORget"></a>
|
|
<b>Get</b>
|
|
<ul>
|
|
N/A
|
|
</ul>
|
|
<br>
|
|
<br>
|
|
|
|
<a name="FB_CALLMONITORattr"></a>
|
|
<b>Attributes</b>
|
|
<ul>
|
|
<li><a href="#loglevel">loglevel</a></li><br>
|
|
<li><a href="#event-on-update-reading">event-on-update-reading</a></li>
|
|
<li><a href="#event-on-change-reading">event-on-change-reading</a></li>
|
|
</ul>
|
|
</ul>
|
|
|
|
|
|
=end html
|
|
=cut
|