diff --git a/fhem/contrib/DoorPi/70_DoorPi.pm b/fhem/contrib/DoorPi/70_DoorPi.pm
index 6fe135a3d..b54cce0c4 100644
--- a/fhem/contrib/DoorPi/70_DoorPi.pm
+++ b/fhem/contrib/DoorPi/70_DoorPi.pm
@@ -8,6 +8,7 @@
#
# $Id: 70_DoorPi.pm 2016-05 - pahenning $
#
+#
########################################################################################
#
# This programm is free software; you can redistribute it and/or modify
@@ -32,14 +33,15 @@ package main;
use strict;
use warnings;
-use JSON; # imports encode_json, decode_json, to_json and from_json.
+use JSON; # imports encode_json, decode_json, to_json and from_json.
+use Test::JSON;
use vars qw{%attr %defs};
sub Log($$);
#-- globals on start
-my $version = "1.0beta7";
+my $version = "1.0beta8";
#-- these we may get on request
my %gets = (
@@ -225,9 +227,9 @@ sub DoorPi_Set ($@) {
#-- commands
my $door = AttrVal($name, "doorbutton", "door");
my $doorsubs = "open";
- $doorsubs .= ",lock"
+ $doorsubs .= ",locked"
if(AttrVal($name, "doorlockcmd",undef));
- $doorsubs .= ",unlock"
+ $doorsubs .= ",unlocked"
if(AttrVal($name, "doorunlockcmd",undef));
my @tsubs = ();
@@ -260,6 +262,7 @@ sub DoorPi_Set ($@) {
$key = shift @a;
$value = shift @a;
+ #Log 1,"[DoorPi_Set] called with key ".$key." and value ".$value;
return "[DoorPi_Set] With unknown argument $key, choose one of " . join(" ", @{$hash->{HELPER}->{CMDS}})
if ( !grep( /$key/, @{$hash->{HELPER}->{CMDS}} ) && ($key ne "call") && ($key ne "door") );
@@ -282,6 +285,8 @@ sub DoorPi_Set ($@) {
DoorPi_GetHistory($hash);
}elsif( $value eq "snapshot" ){
# TODO
+ }else{
+ Log 1,"[DoorPi_Set] $value";
}
#-- call target
}elsif( $key eq "target" ){
@@ -299,17 +304,35 @@ sub DoorPi_Set ($@) {
}
#-- 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( $value eq "opened" ){
+ $v=DoorPi_Cmd($hash,"dooropen");
+ Log 1,"[DoorPi_Set] sent dooropen command to DoorPi";
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));
+ }elsif( $value eq "locked" ){
+ $v=DoorPi_Cmd($hash,"doorlocked");
+ #-- careful here -
+ # a third parameter indicates that the door is already unlocked
+ if( (AttrVal($name, "doorlockcmd",undef)) && (!$a[0]) ){
+ fhem(AttrVal($name, "doorlockcmd",undef));
+ Log 1,"[DoorPi_Set] sent doorlocked command to DoorPi and executed extra FHEM doorlock command";
+ }else{
+ Log 1,"[DoorPi_Set] sent doorlocked command to DoorPi and NOT executed extra FHEM doorlock command";
}
- readingsSingleUpdate($hash,$door,"opened",1);
+ readingsSingleUpdate($hash,$door,"locked",1);
+ }elsif( $value eq "unlocked" ){
+ $v=DoorPi_Cmd($hash,"doorunlocked");
+ #-- careful here -
+ # a third parameter indicates that the door is already unlocked
+ if( (AttrVal($name, "doorunlockcmd",undef)) && (!$a[0]) ){
+ fhem(AttrVal($name, "doorunlockcmd",undef));
+ Log 1,"[DoorPi_Set] sent doorunlocked command to DoorPi and executed extra FHEM doorunlock command";
+ }else{
+ Log 1,"[DoorPi_Set] sent doorunlocked command to DoorPi and NOT executed extra FHEM doorunlock command";
+ }
+ readingsSingleUpdate($hash,$door,"unlocked",1);
}
#-- snapshot
}elsif( $key eq "$snapshot" ){
@@ -406,8 +429,8 @@ sub DoorPi_GetConfig {
}
#Log 1,"[DoorPi_GetConfig] has obtained data";
- #-- crude test if this is valid JSON or some HTML page
- if( substr($status,0,1) eq "<" ){
+ #-- test if this is valid JSON
+ if( !is_valid_json($status) ){
Log 1,"[DoorPi_GetConfig] but data is invalid";
readingsSingleUpdate($hash,"config","invalid data",0);
readingsSingleUpdate($hash,"state","Error",1);
@@ -431,6 +454,7 @@ sub DoorPi_GetConfig {
$hash->{HELPER}->{vkeyboard}=$fskey;
$fscmds = $jhash0->{"config"}->{$fskey."_InputPins"};
+ my $door = AttrVal($name, "doorbutton", "door");
my $light = AttrVal($name, "lightbutton", "light");
my $dashlight = AttrVal($name, "dashlightbutton", "dashlight");
my $snapshot = AttrVal($name, "snapshotbutton", "snapshot");
@@ -441,8 +465,15 @@ sub DoorPi_GetConfig {
foreach my $key (sort(keys $fscmds)) {
+ #-- check for door buttons
+ if($key =~ /dooropen/){
+ push(@{ $hash->{HELPER}->{CMDS}},"$door");
+ }elsif($key =~ /doorlocked/){
+ #no need to get these
+ }elsif($key =~ /doorunlocked/){
+ #no need to get these
#-- check for stream buttons
- if($key =~ /$stream(on)/){
+ }elsif($key =~ /$stream(on)/){
push(@{ $hash->{HELPER}->{CMDS}},"$stream");
$son = 1;
}elsif($key =~ /$stream(off)/){
@@ -567,14 +598,14 @@ sub DoorPi_GetHistory {
}
#Log 1,"[DoorPi_GetHistory] has obtained data in two calls";
- #-- crude test if this is valid JSON or some HTML page
- if( substr($status1,0,1) eq "<" ){
+ #-- test if this is valid JSON
+ if( !is_valid_json($status1) ){
Log 1,"[DoorPi_GetHistory] but data from first call is invalid";
readingsSingleUpdate($hash,"history","invalid data 1st call",0);
readingsSingleUpdate($hash,"state","Error",1);
return;
}
- if( substr($status2,0,1) eq "<" ){
+ if( !is_valid_json($status2) ){
Log 1,"[DoorPi_GetHistory] but data from second call is invalid";
readingsSingleUpdate($hash,"history","invalid data 2nd call",0);
readingsSingleUpdate($hash,"state","Error",1);
@@ -658,8 +689,8 @@ sub DoorPi_GetHistory {
my $record = $callrecord;
$record =~ s/^.*records\///;
#-- workaround for buggy DoorPi
- $record = sprintf("%d-%02d-%02d_%02d-%02d-%02d.wav", $year,($month+1),$day,$hour, $min, $sec)
- if( $callend eq "ok");
+ $record = sprintf("%d-%02d-%02d_%02d-%02d-%02d.wav", $year,($month+1),$day,$hour, $min, $sec);
+ # if( $callend eq "ok");
#-- this is the snapshot file if taken at the same time
my $snapshot = sprintf("%d-%02d-%02d_%02d-%02d-%02d.jpg", $year,($month+1),$day,$hour, $min, $sec);
@@ -772,10 +803,10 @@ sub DoorPi_GetHistory {
readingsSingleUpdate($hash,"state","Error",1);
return;
}
- #Log 1,"[DoorPi_Cmd] has obtained data";
+ #Log 1,"[DoorPi_Cmd] has obtained data $data";
- #-- crude test if this is valid JSON or some HTML page
- if( substr($data,0,1) eq "<" ){
+ #-- test if this is valid JSON
+ if( !is_valid_json($data) ){
Log 1,"[DoorPi_Cmd] invalid data";
readingsSingleUpdate($hash,"state","Error",1);
return;
@@ -992,16 +1023,24 @@ sub DoorPi_makeTable($$$$){
<IP address>
+ Note: The default configuration for the module assumes that opening the door is done by DoorPi
+ because it controls the local door opener, but locking and unlocking are handled by FHEM. Perl modules JSON and Test:JSON are needed.
set <DoorPi-Device> door open[|locked|unlocked] set <DoorPi-Device> door open[|locked|unlocked] [<string>]set <DoorPi-Device> snapshot set <DoorPi-Device> buttonDD set <DoorPi-Device> purge
[keyboards]
...
@@ -1119,7 +1160,9 @@ base_path_input = <dome directory>
base_path_output = <some directory>
[<virtualkeyboardname>_InputPins]
-door = <doorpi action opeing the door>
+dooropen = <doorpi action opening the door>
+doorlocked = <doorpi action if the door is locked by FHEM>
+doorunlocked = <doorpi action if the door is unlocked by FHEM>
lighton = <doorpi action to switch on scene light>
lightonfortimer = <doorpi action to switch on scene light for some time>
lightoff = <doorpi action to switch off scene light>
diff --git a/fhem/contrib/DoorPi/FHEMHelper.sh.safe b/fhem/contrib/DoorPi/FHEMHelper.sh.safe
new file mode 100644
index 000000000..6157274e4
--- /dev/null
+++ b/fhem/contrib/DoorPi/FHEMHelper.sh.safe
@@ -0,0 +1,61 @@
+# /bin/sh
+
+
+checkstream() {
+ streampid=`pidof mjpg_streamer`
+ if [ -z "$streampid" ]; then
+ stream="off"
+ else
+ stream="on"
+ fi
+}
+
+FHEMDP="A.Door.Pi"
+FHEMIP="192.168.0.90"
+FHEM="http://$FHEMIP:8083/fhem?XHR=1&cmd.$FHEMDP"
+HOME="/home/doorpi"
+default_target="XXXX"
+
+case $1 in
+
+ init) target=`cat $HOME/calltarget`
+ curl "$FHEM=setreading%20$FHEMDP%20call_target%20$target" &
+
+ streampid=`pidof mjpg_streamer`
+ if [ -z "$streampid" ]; then
+ curl "$FHEM=setreading%20$FHEMDP%20stream%20off" &
+ else
+ curl "$FHEM=setreading%20$FHEMDP%20stream%20on" &
+ fi
+ ;;
+
+ dooropen)
+ curl "$FHEM=set%20GalaxyTab%20ttsSay%20Ein%20Bewohner%20betritt%20das%20Haus" &
+ curl "$FHEM=set%20$FHEMDP%20door%20opened" &
+ ;;
+
+ wrongid)
+ curl "$FHEM=set%20GalaxyTab%20ttsSay%20Unerlaubter%20Zutrittsversuch" &
+ curl "$FHEM=set%20$FHEMDP%20door%20wrong_id" &
+ ;;
+
+ softlock)
+ curl "$FHEM=set%20$FHEMDP%20door%20locked" &
+ ;;
+
+ call)
+ curl "$FHEM=set%20$FHEMDP%20call%20$2" &
+ ;;
+
+ gettarget)
+ echo "{ReadingsVal('$FHEMDP','call_target','$default_target')}" | socat -t50 - TCP:$FHEMIP:7072 > $HOME/calltarget
+ ;;
+
+ purge)
+ find $HOME/records/ -type f ! -newer /var/run/doorpi.pid -delete
+ ;;
+
+ clear)
+ ;;
+
+esac
diff --git a/fhem/contrib/DoorPi/doorpi.ini.safe b/fhem/contrib/DoorPi/doorpi.ini.safe
index f96d71dd0..a0c04858b 100644
--- a/fhem/contrib/DoorPi/doorpi.ini.safe
+++ b/fhem/contrib/DoorPi/doorpi.ini.safe
@@ -57,20 +57,20 @@ guests = dashboard
####################### Events #######################
[EVENT_OnStartup]
10 = sleep:1
-20 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call startup
+20 = os_execute:/home/doorpi/FHEMHelper call init
[EVENT_BeforeSipPhoneMakeCall]
-10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call start
+10 = os_execute:/home/doorpi/FHEMHelper call startup
20 = take_snapshot
[EVENT_OnCallStateDisconnect]
-10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call end
+10 = os_execute:/home/doorpi/FHEMHelper call end
[EVENT_OnCallStateDismissed]
-10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call dismissed
+10 = os_execute:/home/doorpi/FHEMHelper call dismissed
[EVENT_OnCallStateReject]
-10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call rejected
+10 = os_execute:/home/doorpi/FHEMHelper call rejected
[EVENT_OnTimeMinuteEvery5]
10=statuswatchdog:/tmp/doorpi.watchdog
@@ -82,9 +82,9 @@ local_port = 5060
firewallpolicy = PolicyNoFirewall
#
sipphonetyp = linphone
-sipserver_password = xxxxxxxxxxxxxxxxxxx
-sipserver_realm = fritz.box
-sipserver_server = 192.168.0.254
+sipserver_password = xxxxxx
+sipserver_realm = cccc
+sipserver_server = ccccc
sipserver_username = 620
stun_server =
#
@@ -110,8 +110,8 @@ video_size = vga
####################### Keyboards ##############################
[keyboards]
-onboardpins = piface
webservice = filesystem
+onboardpins = piface
####################### Virtual keyboard #######################
[webservice_keyboard]
@@ -119,8 +119,10 @@ base_path_input = /home/doorpi/keyboard/inputs/
base_path_output = /home/doorpi/keyboard/outputs/
[webservice_InputPins]
-door = out:door,1,0,3
-snapshot = sleep:0
+dooropen = out:door,1,0,3
+doorlocked = out:hardlock,1
+doorunlocked = out:hardlock,0
+snapshot = sleep:0
streamon = sleep:0
streamoff = sleep:0
lighton = out:light,1
@@ -137,35 +139,34 @@ button2 = sleep:0
#-- communicate to FHEM that a snapshot has been taken
[EVENT_OnKeyPressed_webservice.snapshot]
10 = take_snapshot
-20 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T door snapshot
+20 = os_execute:/home/doorpi/FHEMHelper call snapshot
#-- start video stream
[EVENT_OnKeyPressed_webservice.streamon]
-10 = os_execute:/etc/init.d/mjpg-streamer start
+10 = os_execute:/etc/init.d/mjpg_streamer start
#-- stop video stream
[EVENT_OnKeyPressed_webservice.streamoff]
-10 = os_execute:/etc/init.d/mjpg-streamer stop
+10 = os_execute:/etc/init.d/mjpg_streamer stop
#-- obtain the target call number from FHEM
[EVENT_OnKeyPressed_webservice.gettarget]
-10 = os_execute:echo '{ReadingsVal("A.Haus.T","call_target",722622)}' | socat -t50 - TCP:192.168.0.90:7072 > /home/doorpi/calltarget
+10 = os_execute:/home/doorpi/FHEMHelper gettarget
#-- purge all files older than current PID file
[EVENT_OnKeyPressed_webservice.purge]
-10 = os_execute:find /home/doorpi/records/ -type f ! -newer var/run/doorpi.pid -delete
+10 = os_execute:/home/doorpi/FHEMHelper purge
-#-- clear all files (NOT YET OK)
+#-- clear all files
[EVENT_OnKeyPressed_webservice.clear]
-10 = os_execute:/home/doorpi/purge.sh clear > /home/doorpi/yyy
+10 = os_execute:/home/doorpi/FHEMHelper clear
[EVENT_OnKeyPressed_webservice.button1]
-10 = call:722622
+10 = os_execute:/home/doorpi/FHEMHelper sabotage
[EVENT_OnKeyPressed_webservice.button2]
10 = file_call_value:/home/doorpi/calltarget
-
####################### Real keyboard #######################
[onboardpins_keyboard]
pull_up_down = PUD_UP
@@ -174,27 +175,44 @@ pull_up_down = PUD_UP
0 = door
1 = light
2 = dashlight
-3 = blinking_led
+3 = hardlock
+7 = blinking_led
[onboardpins_InputPins]
-0 = call:722622
-1 = call:**621
-2 = file_call_value:/home/doorpi/calltarget
-3 = take_snapshot
+0 = file_call_value:/home/doorpi/calltarget
+1 = sleep:0
+4 = sleep:0
+5 = sleep:0
6 = sleep:0
7 = sleep:0
-#-- OK pin from Arduino
-[EVENT_OnKeyPressed_onboardpins.6]
-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
+#-- DoorOpen pin from Arduino
+[EVENT_OnKeyPressed_onboardpins.1]
+10 = out:dashlight,1
+20 = os_execute:/home/doorpi/FHEMHelper dooropen
+30 = os_execute:aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav
40 = out:door,1,0,3
+50 = out:dashlight,0
-#-- NOK pin from Arduino
+#-- WrongID pin from Arduino
+[EVENT_OnKeyPressed_onboardpins.4]
+10 = out:dashlight,1
+20 = os_execute:/home/doorpi/FHEMHelper wrongid
+30 = take_snapshot
+40 = out:dashlight,0
+
+#-- LockState pin from Arduino - FHEM will transform softlock into hardlock
+[EVENT_OnKeyPressed_onboardpins.5]
+10 = os_execute:/home/doorpi/FHEMHelper softlock
+
+#-- Movement detection
+[EVENT_OnKeyPressed_onboardpins.6]
+10 = out:dashlight,1,0,60
+20 = os_execute:/home/doorpi/FHEMHelper movement
+
+#-- Sabotage detection
[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
+10 = os_execute:/home/doorpi/FHEMHelper sabotage
+