From 5ef38a204d87aeafc19a9eb6c16526f9ccf5e91a Mon Sep 17 00:00:00 2001 From: dominikkarall Date: Sat, 18 Nov 2017 19:48:43 +0000 Subject: [PATCH] 10_EQ3BT: support remote Bluetooth via SSH (thx@Cooltux) git-svn-id: https://svn.fhem.de/fhem/trunk@15447 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/10_EQ3BT.pm | 60 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index b2214e2a1..42df5e666 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 10_EQ3BT: support remote Bluetooth interface via SSH (thx@Cooltux!) - feature: 93_DbRep: V6.0.0, FTP transfer dumpfile after dump (MySQL), delete old dumpfiles within Blockingcall, minor fixes - feature: 57_Calendar: new field categories (nils_, Forum #79237) diff --git a/fhem/FHEM/10_EQ3BT.pm b/fhem/FHEM/10_EQ3BT.pm index 6fd789b01..070bcf965 100644 --- a/fhem/FHEM/10_EQ3BT.pm +++ b/fhem/FHEM/10_EQ3BT.pm @@ -6,10 +6,13 @@ # # FHEM module to communicate with EQ-3 Bluetooth thermostats # -# Version: 2.0.1 +# Version: 2.0.2 # ############################################################# # +# v2.0.2 - 20171118 +# - FEATURE: support remote bluetooth interfaces via SSH (thx@Cooltux!) +# # v2.0.1 - 20170204 # - BUGFIX: fix lastChangeBy # - BUGFIX: fix retry of updateStatus, updateSystemInformation @@ -147,7 +150,8 @@ sub EQ3BT_Initialize($) { $hash->{GetFn} = 'EQ3BT_Get'; $hash->{SetFn} = 'EQ3BT_Set'; $hash->{AttrFn} = 'EQ3BT_Attribute'; - $hash->{AttrList} = $readingFnAttributes; + $hash->{AttrList} = 'sshHost '. + $readingFnAttributes; return undef; } @@ -158,16 +162,21 @@ sub EQ3BT_Define($$) { my @a = split("[ \t]+", $def); my $name = $a[0]; my $mac; + my $sshHost; $hash->{STATE} = "initialized"; - $hash->{VERSION} = "2.0.1"; + $hash->{VERSION} = "2.0.2"; Log3 $hash, 3, "EQ3BT: EQ-3 Bluetooth Thermostat ".$hash->{VERSION}; - if (int(@a) > 3) { - return 'EQ3BT: Wrong syntax, must be define EQ3BT '; + if (int(@a) > 4) { + return 'EQ3BT: Wrong syntax, must be define EQ3BT ""'; } elsif(int(@a) == 3) { $mac = $a[2]; $hash->{MAC} = $a[2]; + } elsif(int(@a) == 4) { + $mac = $a[2]; + $hash->{MAC} = $a[2]; + $attr{$name}{sshHost} = $a[3]; } EQ3BT_updateHciDevicelist($hash); @@ -183,9 +192,18 @@ sub EQ3BT_Define($$) { sub EQ3BT_updateHciDevicelist { my ($hash) = @_; + my $name = $hash->{NAME}; #check for hciX devices $hash->{helper}{hcidevices} = (); - my @btDevices = split("\n", qx(hcitool dev)); + my @btDevices; + my $sshHost = AttrVal($name,"sshHost","none"); + + if( $sshHost ne 'none' ) { + @btDevices = split("\n", qx(ssh $sshHost 'hcitool dev')); + } else { + @btDevices = split("\n", qx(hcitool dev)); + } + foreach my $btDevLine (@btDevices) { if($btDevLine =~ /hci(.)/) { push(@{$hash->{helper}{hcidevices}}, $1); @@ -199,8 +217,13 @@ sub EQ3BT_updateHciDevicelist { sub EQ3BT_pairDevice { my ($string) = @_; my ($name, $mac) = split("\\|", $string); + my $sshHost = AttrVal($name,"sshHost","none"); - qx(echo "pair $mac\\n";sleep 7;echo "trust $mac\\ndisconnect $mac\\n";sleep 2; echo "quit\\n" | bluetoothctl); + if( $sshHost ne 'none' ) { + qx(ssh $sshHost 'echo "pair $mac\\n";sleep 7;echo "trust $mac\\ndisconnect $mac\\n";sleep 2; echo "quit\\n" | bluetoothctl'); + } else { + qx(echo "pair $mac\\n";sleep 7;echo "trust $mac\\ndisconnect $mac\\n";sleep 2; echo "quit\\n" | bluetoothctl); + } return $name; } @@ -476,6 +499,8 @@ sub EQ3BT_execGatttool($) { if(-x $gatttool) { my $gtResult; + my $cmd; + my $sshHost = AttrVal($name,"sshHost","none"); while($wait) { my $grepGatttool = qx(ps ax| grep -E \'gatttool -b $mac\' | grep -v grep); @@ -495,13 +520,23 @@ sub EQ3BT_execGatttool($) { } my $hciDevice = "hci".$hash->{helper}{hcidevices}[$hash->{helper}{currenthcidevice}]; - my $cmd = "gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value"; + #my $cmd = "gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value"; + if( $sshHost ne 'none' ) { + $cmd = "ssh $sshHost 'gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value"; + } else { + $cmd = "gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value"; + } + if(defined($listen) && $listen eq "listen") { $cmd = "timeout 15 ".$cmd." --listen"; } #redirect stderr to stdout - $cmd .= " 2>&1"; + if( $sshHost ne 'none' ) { + $cmd .= " 2>&1'"; + } else { + $cmd .= " 2>&1"; + } Log3 $name, 5, "EQ3BT ($name): $cmd"; $gtResult = qx($cmd); @@ -787,6 +822,13 @@ sub EQ3BT_Get($$) { n/a
+ + + attr +
    +
  • sshHost - FQD-Name or IP of ssh remote system / you must configure your ssh system for certificate authentication. For better handling you can config ssh Client with .ssh/config file
  • +
+