From a5ae65d17bae5077e3f30ba98d5c8e6e86e80843 Mon Sep 17 00:00:00 2001
From: pahenning <>
Date: Tue, 3 May 2016 18:56:58 +0000
Subject: [PATCH] DoorPi.pm: Bugfix
git-svn-id: https://svn.fhem.de/fhem/trunk@11382 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/contrib/DoorPi/70_DoorPi.pm | 157 ++++++++++++++++++++--------
fhem/contrib/DoorPi/doorpi.ini.safe | 42 +++++---
fhem/contrib/DoorPi/getparams.sh | 7 --
fhem/contrib/DoorPi/iButton_NOK.sh | 5 -
fhem/contrib/DoorPi/iButton_OK.sh | 6 --
fhem/contrib/DoorPi/purge.sh | 19 ----
6 files changed, 137 insertions(+), 99 deletions(-)
delete mode 100755 fhem/contrib/DoorPi/getparams.sh
delete mode 100755 fhem/contrib/DoorPi/iButton_NOK.sh
delete mode 100755 fhem/contrib/DoorPi/iButton_OK.sh
delete mode 100755 fhem/contrib/DoorPi/purge.sh
diff --git a/fhem/contrib/DoorPi/70_DoorPi.pm b/fhem/contrib/DoorPi/70_DoorPi.pm
index a5920c800..a67ac585a 100644
--- a/fhem/contrib/DoorPi/70_DoorPi.pm
+++ b/fhem/contrib/DoorPi/70_DoorPi.pm
@@ -39,7 +39,7 @@ use vars qw{%attr %defs};
sub Log($$);
#-- globals on start
-my $version = "1.0beta3";
+my $version = "1.0beta4";
#-- these we may get on request
my %gets = (
@@ -71,7 +71,7 @@ sub DoorPi_Initialize ($) {
"language:de,en ".
"doorbutton dooropencmd doorlockcmd doorunlockcmd ".
"lightbutton lightoncmd lighttimercmd lightoffcmd ".
- "dashlightbutton ".
+ "dashlightbutton iconpic iconaudio ".
$readingFnAttributes;
$hash->{FW_detailFn} = "DoorPi_makeTable";
@@ -115,6 +115,7 @@ sub DoorPi_Define($$) {
my $oid = $init_done;
$init_done = 1;
readingsSingleUpdate($hash,"state","Initialized",1);
+ readingsSingleUpdate($hash,"door","Unknown",1);
DoorPi_GetConfig($hash);
DoorPi_GetHistory($hash);
@@ -154,16 +155,10 @@ sub DoorPi_Attr(@) {
if ( $do eq "set") {
ARGUMENT_HANDLER: {
- $key eq "interval" and do {
- $hash->{interval} = $value;
- if ($main::init_done) {
- # WHAT ?
+ # TODO
}
- last;
- };
- }
}
- return $ret;
+ return
}
########################################################################################
@@ -245,12 +240,12 @@ sub DoorPi_Set ($@) {
$value = shift @a;
return "[DoorPi_Set] With unknown argument $key, choose one of " . join(" ", @{$hash->{HELPER}->{CMDS}})
- if ( !grep( /$key/, @{$hash->{HELPER}->{CMDS}} ) && !($key eq "call") );
+ if ( !grep( /$key/, @{$hash->{HELPER}->{CMDS}} ) && ($key ne "call") && ($key n "door") );
#-- hidden command to be used by DoorPi for adding a new call
if( $key eq "call" ){
if( $value eq "start" ){
- readingsSingleUpdate($hash,"call","started",1);
+ readingsSingleUpdate($hash,"call","started",1);e
}elsif( $value eq "end" ){
readingsSingleUpdate($hash,"call","ended",1);
DoorPi_GetHistory($hash);
@@ -261,13 +256,19 @@ sub DoorPi_Set ($@) {
readingsSingleUpdate($hash,"call","dismissed",1);
DoorPi_GetHistory($hash);
}
- #-- door opening
- }elsif( $key eq "$door" ){
+ #-- door opening - either from FHEM, or just as message from DoorPi
+ }elsif( ($key eq "$door")||($key eq "door" ){
if( $value eq "open" ){
$v=DoorPi_Cmd($hash,"door");
if(AttrVal($name, "dooropencmd",undef)){
fhem(AttrVal($name, "dooropencmd",undef));
}
+ readingsSingleUpdate($hash,$door,"opened",1);
+ }elsif( $value eq "opened" ){
+ if(AttrVal($name, "dooropencmd",undef)){
+ fhem(AttrVal($name, "dooropencmd",undef));
+ }
+ readingsSingleUpdate($hash,$door,"opened",1);
}
#-- scene lighting
}elsif( $key eq "$light" ){
@@ -275,9 +276,23 @@ sub DoorPi_Set ($@) {
if( $value eq "on" ){
$v=DoorPi_Cmd($hash,"lighton");
readingsSingleUpdate($hash,$light,"on",1);
+ if(AttrVal($name, "lightoncmd",undef)){
+ fhem(AttrVal($name, "lightoncmd",undef));
+ }
+ readingsSingleUpdate($hash,$light,"on",1);
}elsif( $value eq "off" ){
$v=DoorPi_Cmd($hash,"lightoff");
+ if(AttrVal($name, "lightoffcmd",undef)){
+ fhem(AttrVal($name, "lightoffcmd",undef));
+ }
readingsSingleUpdate($hash,$light,"off",1);
+ }elsif( $value eq "on-for-timer" ){
+ $v=DoorPi_Cmd($hash,"lightonfortimer");
+ if(AttrVal($name, "lighttimercmd",undef)){
+ fhem(AttrVal($name, "lighttimercmd",undef));
+ }
+ readingsSingleUpdate($hash,$light,"on-for-timer",1);
+ #-- TODO: reset after time
}
#-- dashboard lighting
}elsif( $key eq "$dashlight" ){
@@ -760,6 +775,13 @@ sub DoorPi_makeTable($$$$){
setlocale(LC_ALL, "en_US.utf8");
}
+ my $iconpic = AttrVal($hash->{NAME}, "iconpic", undef);
+ $iconpic = FW_makeImage($iconpic)
+ if($iconpic);
+ my $iconaudio = AttrVal($hash->{NAME}, "iconaudio", undef);
+ $iconaudio = FW_makeImage($iconaudio)
+ if($iconaudio);
+
my $ret = "
";
if(AttrVal($name, "no-heading", "0") eq "0" and defined($FW_ME) and defined($FW_subdir))
@@ -819,11 +841,13 @@ sub DoorPi_makeTable($$$$){
if( $record ne ""){
my $rs = $record;
$rs =~ s/.*$wwwpath\///;
+ $rs = ($iconaudio) ? $iconaudio : $rs;
$record = ''.$rs.'';
}
if( $snapshot ne ""){
- $state = '
';
+ $state = '';
+ $state .= ($iconpic) ? $iconpic : '
';
}
$ret .= '';
@@ -867,7 +891,7 @@ sub DoorPi_makeTable($$$$){
Define
- define <name> DoorPi <IP address>
+ define <DoorPi-Device> DoorPi <IP address>
Define a DoorpiPi instance.
@@ -881,27 +905,27 @@ sub DoorPi_makeTable($$$$){
Set
-
-
set <name> door open[|locked|unlocked]
+ set <DoorPi-Device> door open[|locked|unlocked]
Activate the door opener in DoorPi, accompanied by an optional FHEM command
specified in the dooropencmd attribute.
-
If the Attributes doorlockcmd and doorunlockcmd are specified, these commands may be used to lock and unlock the door
+
If the Attributes doorlockcmd and doorunlockcmd are specified, these commands may be used to lock and unlock the door
Instead of door, one must use the value of the doorbutton attribute.
-
-
set <name> dashlight on|off
+ set <DoorPi-Device> dashlight on|off
Set the dashlight (illuminating the door station) on or off.
Instead of dashlight, one must use the value of the dashlightbutton attribute
-
-
set <name> light on|on-for-timer|off
+ set <DoorPi-Device> light on|on-for-timer|off
Set the scene light (illuminating the visitor) on, on for a minute or off.
Instead of light, one must use the value of the lightbutton attribute
-
-
set <name> buttonDD
- Activate one of the virtual buttons specified in DoorPi.
+ set <DoorPi-Device> buttonDD
+ Activate one of the virtual buttons specified in DoorPi.
-
-
set <name> purge
+ set <DoorPi-Device> purge
Clean all recordings and snapshots which are older than the current process
-
-
set <name> clear
+ set <DoorPi-Device> clear
Clear all recordings and snapshots
@@ -909,50 +933,91 @@ sub DoorPi_makeTable($$$$){
Get
Attributes
- Necessary parts of the DoorPi configuration
- The following Events need to be defined for DoorPi:
-
- - [EVENT_BeforeSipPhoneMakeCall]
- 10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<Device name for DoorPi>=set <Device name for DoorPi> call start
- - [EVENT_OnCallStateDisconnect]
- 10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<Device name for DoorPi>=set <Device name for DoorPi> call end
- - [EVENT_OnCallStateDismissed]
- 10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<Device name for DoorPi>=set <Device name for DoorPi> call dismissed
- - [EVENT_OnCallStateReject]
- 10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<Device name for DoorPi>=set <Device name for DoorPi> call rejected
-
-
+ Necessary ingredients of the DoorPi configuration
+ The following Events need to be defined for DoorPi in order to communicate with FHEM:
+
+[EVENT_BeforeSipPhoneMakeCall]
+10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<DoorPi-Device>=set <DoorPi-Device> call start
+20 = take_snapshot
+
+[EVENT_OnCallStateDisconnect]
+10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<DoorPi-Device>=set <DoorPi-Device> call end
+
+[EVENT_OnCallStateDismissed]
+10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<DoorPi-Device>=set <DoorPi-Device> call dismissed
+
+[EVENT_OnCallStateReject]
+10 = url_call:<URL of FHEM>/fhem?XHR=1&cmd.<DoorPi-Device>=set <DoorPi-Device> call rejected
+
+ DoorPi must have a virtual (= filesystem) keyboard
+
+[keyboards]
+...
+<virtualkeyboardname> = filesystem
+
+[<virtualkeyboardname>_keyboard]
+base_path_input = <dome directory>
+base_path_output = <some directory>
+
+[<virtualkeyboardname>_InputPins]
+door = <some doorpi action>
+lighton = <some doorpi action>
+lightonfortimer = <some doorpi action>
+lightoff = <some doorpi action>
+dashlighton = <some doorpi action>
+dashlightoff = <some doorpi action>
+purge = <some doorpi action>
+clear = <some doorpi action>
+... (optional buttons)
+button1 = <some doorpi action>
+... (further button definitions)
+
=end html
=cut
diff --git a/fhem/contrib/DoorPi/doorpi.ini.safe b/fhem/contrib/DoorPi/doorpi.ini.safe
index 65044fb5e..6cda16c2e 100644
--- a/fhem/contrib/DoorPi/doorpi.ini.safe
+++ b/fhem/contrib/DoorPi/doorpi.ini.safe
@@ -14,7 +14,6 @@ port = 80
public = AREA_public
www = /home/doorpi/records
-
[AREA_public]
.*
@@ -55,19 +54,22 @@ guests = dashboard
[EVENT_OnStartup]
10 = sleep:1
-#-- notify the FHEM module
[EVENT_BeforeSipPhoneMakeCall]
-10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call start
+10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call start
20 = take_snapshot
+30 = mailto:haus271828@henning-weingarten.de,DoorPi,DoorPi initiating call
[EVENT_OnCallStateDisconnect]
-10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call end
+10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call end
[EVENT_OnCallStateDismissed]
-10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call dismissed
+10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call dismissed
[EVENT_OnCallStateReject]
-10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call rejected
+10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call rejected
+
+[EVENT_OnTimeMinuteEvery5]
+10=statuswatchdog:/tmp/doorpi.watchdog
[SIP-Phone]
identity = DoorPi
@@ -75,7 +77,7 @@ local_port = 5060
firewallpolicy = PolicyNoFirewall
#
sipphonetyp = linphone
-sipserver_password = xxxxxxxxxxxx
+sipserver_password = XXXX
sipserver_realm = fritz.box
sipserver_server = 192.168.0.254
sipserver_username = 620
@@ -121,17 +123,19 @@ clear = sleep:0
button1 = sleep:0
button2 = sleep:0
+#-- purge all files older than current PID file
[EVENT_OnKeyPressed_webservice.purge]
-10 = os_execute:/home/doorpi/purge.sh purge
+10 = os_execute:find /home/doorpi/records/ -type f ! -newer var/run/doorpi.pid -delete
+#-- clear all files (NOT YET OK)
[EVENT_OnKeyPressed_webservice.clear]
-10 = os_execute:/home/doorpi/purge.sh clear
+10 = os_execute:/home/doorpi/purge.sh clear > /home/doorpi/yyy
[EVENT_OnKeyPressed_webservice.button1]
10 = call:722622
[EVENT_OnKeyPressed_webservice.button2]
-10 = sleep:0
+10 = echo -e '{ReadingsVal("A.Haus.T","call_number",722622)}' | socat -t50 - TCP:192.168.0.90:7072 > /home/doorpi/callnumber
[onboardpins_keyboard]
pull_up_down = PUD_UP
@@ -152,13 +156,19 @@ pull_up_down = PUD_UP
#-- NOK pin from Arduino
7 = sleep:0
-[EVENT_OnKeyPressed_onboardpins.7]
-10 = os_execute:/home/doorpi/iButton_NOK.sh
-
+#-- OK pin from Arduino
[EVENT_OnKeyPressed_onboardpins.6]
-10 = os_execute:/home/doorpi/iButton_OK.sh
-20 = out:door,1,0,3
+10 = os_execute:aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav
+20 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set GalaxyTab ttsSay Ein Bewohner betritt das Haus
+30 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T door opened
+40 = out:door,1,0,3
+
+#-- NOK pin from Arduino
+[EVENT_OnKeyPressed_onboardpins.7]
+10 = take_snapshot
+20 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set GalaxyTab ttsSay Unerlaubter Zutrittsversuch
+30 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T door wrong_id
[DTMF]
-"2" = out:door,1,0,3
+"#" = out:door,1,0,3
diff --git a/fhem/contrib/DoorPi/getparams.sh b/fhem/contrib/DoorPi/getparams.sh
deleted file mode 100755
index ac27315c2..000000000
--- a/fhem/contrib/DoorPi/getparams.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-# ! /usr/bin/sh
-# get FHEM values
-callnumber='{ReadingsVal("A.Haus.T.Klingel","callnumber",0)}'
-FHEM=`echo -e "$callnumber" | socat -t50 - TCP:192.168.0.90:7072`
-
-echo "$FHEM" > /var/DoorPi/callnumber
-
diff --git a/fhem/contrib/DoorPi/iButton_NOK.sh b/fhem/contrib/DoorPi/iButton_NOK.sh
deleted file mode 100755
index 47e7942f6..000000000
--- a/fhem/contrib/DoorPi/iButton_NOK.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-# ! /usr/bin/sh
-curl "http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set%20GalaxyTab%20ttsSay%20Unerlaubter%20Zutrittsversuch"
-
-
-
diff --git a/fhem/contrib/DoorPi/iButton_OK.sh b/fhem/contrib/DoorPi/iButton_OK.sh
deleted file mode 100755
index 8bc7ea0fb..000000000
--- a/fhem/contrib/DoorPi/iButton_OK.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# ! /usr/bin/sh
-aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav
-curl "http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set%20GalaxyTab%20ttsSay%20Ein%20Bewohner%20betritt%20das%20Haus"
-
-
-
diff --git a/fhem/contrib/DoorPi/purge.sh b/fhem/contrib/DoorPi/purge.sh
deleted file mode 100755
index ef7981a8c..000000000
--- a/fhem/contrib/DoorPi/purge.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-# ! /usr/bin/sh
-action=$1
-
-get_modify_time()
-{
- stat $1 | grep -Po "Modify: \K[0-9- :]*"
-}
-
-
-if [ "$action" == "purge" ]; then
- reference=/var/run/doorpi.pid
- find records/ -type f ! -newer $reference -delete
-elif [ "$action" == "clear" ]; then
- echo "clear"
-
-else
- echo "so what"
-fi
-