2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

10_EQ3BT: support remote Bluetooth via SSH (thx@Cooltux)

git-svn-id: https://svn.fhem.de/fhem/trunk@15447 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
dominikkarall 2017-11-18 19:48:43 +00:00
parent b37e90ee21
commit 5ef38a204d
2 changed files with 52 additions and 9 deletions

View File

@ -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)

View File

@ -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 <name> EQ3BT <mac address>';
if (int(@a) > 4) {
return 'EQ3BT: Wrong syntax, must be define <name> EQ3BT <mac address> "<sshHost-IP>"';
} 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($$) {
<code>n/a</code>
</ul>
<br>
<a name="EQ3BTattr" id="EQ3BTattr"></a>
<b>attr</b>
<ul>
<li>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</li>
</ul>
<br>
</ul>