10_EQ3BT: alte revision wieder eingespielt nach falschen commit

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@16466 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2018-03-22 04:18:29 +00:00
parent 03de675ac3
commit d4188f03cd

View File

@ -157,7 +157,6 @@ sub EQ3BT_Initialize($) {
$hash->{SetFn} = 'EQ3BT_Set'; $hash->{SetFn} = 'EQ3BT_Set';
$hash->{AttrFn} = 'EQ3BT_Attribute'; $hash->{AttrFn} = 'EQ3BT_Attribute';
$hash->{AttrList} = 'sshHost maxRetries timeout '. $hash->{AttrList} = 'sshHost maxRetries timeout '.
'blockingCallLoglevel:2,3,4,5 '.
$readingFnAttributes; $readingFnAttributes;
return undef; return undef;
@ -173,7 +172,6 @@ sub EQ3BT_Define($$) {
$hash->{STATE} = "initialized"; $hash->{STATE} = "initialized";
$hash->{VERSION} = "2.0.4"; $hash->{VERSION} = "2.0.4";
$hash->{loglevel} = 4;
Log3 $hash, 3, "EQ3BT: EQ-3 Bluetooth Thermostat ".$hash->{VERSION}; Log3 $hash, 3, "EQ3BT: EQ-3 Bluetooth Thermostat ".$hash->{VERSION};
if (int(@a) > 4) { if (int(@a) > 4) {
@ -238,22 +236,13 @@ sub EQ3BT_pairDevice {
sub EQ3BT_Attribute($$$$) { sub EQ3BT_Attribute($$$$) {
my ($mode, $devName, $attrName, $attrValue) = @_; my ($mode, $devName, $attrName, $attrValue) = @_;
my $hash = $defs{$devName};
if($mode eq "set") { if($mode eq "set") {
if( $attrName eq "blockingCallLoglevel" ) {
$hash->{loglevel} = $attrValue;
Log3 $devName, 3, "EQ3BT ($devName) - set blockingCallLoglevel to $attrValue";
}
} elsif($mode eq "del") { } elsif($mode eq "del") {
if( $attrName eq "blockingCallLoglevel" ) {
$hash->{loglevel} = 4;
Log3 $devName, 3, "EQ3BT ($devName) - set blockingCallLoglevel to default";
}
} }
return undef; return undef;
} }
@ -392,7 +381,7 @@ sub EQ3BT_setDesiredTemperature($$) {
my $eq3Temp = sprintf("%02X", $desiredTemp * 2); my $eq3Temp = sprintf("%02X", $desiredTemp * 2);
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setDesiredTemperature|0x0411|41".$eq3Temp, "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setDesiredTemperature|0x0411|41".$eq3Temp, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
@ -416,7 +405,7 @@ sub EQ3BT_setBoost {
my $data = "01"; my $data = "01";
$data = "00" if($onoff eq "off"); $data = "00" if($onoff eq "off");
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setBoost|0x0411|45".$data, "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setBoost|0x0411|45".$data, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
@ -440,7 +429,7 @@ sub EQ3BT_setMode {
my $data = "40"; my $data = "40";
$data = "00" if($mode eq "automatic"); $data = "00" if($mode eq "automatic");
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setMode|0x0411|40".$data."|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setMode|0x0411|40".$data."|listen", "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
@ -461,7 +450,7 @@ sub EQ3BT_setEco {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setEco|0x0411|44|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setEco|0x0411|44|listen", "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
@ -482,7 +471,7 @@ sub EQ3BT_setComfort {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setComfort|0x0411|43|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setComfort|0x0411|43|listen", "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
@ -501,35 +490,29 @@ sub EQ3BT_setComfortRetry {
### Gatttool functions ### ### Gatttool functions ###
sub EQ3BT_retryGatttool { sub EQ3BT_retryGatttool {
my ($hash, $workType) = @_; my ($hash, $workType) = @_;
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $hash->{NAME}."|".$hash->{MAC}."|$workType|".$hash->{helper}{"handle$workType"}."|".$hash->{helper}{"value$workType"}."|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $hash->{NAME}."|".$hash->{MAC}."|$workType|".$hash->{helper}{"handle$workType"}."|".$hash->{helper}{"value$workType"}."|".$hash->{helper}{"listen$workType"}, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
sub EQ3BT_execGatttool($) { sub EQ3BT_execGatttool($) {
my ($string) = @_; my ($string) = @_;
my ($name, $mac, $workType, $handle, $value, $listen) = split("\\|", $string); my ($name, $mac, $workType, $handle, $value, $listen) = split("\\|", $string);
my $wait = 1;
my $hash = $main::defs{$name};
my $hash = $main::defs{$name}; my $gatttool = qx(which gatttool);
my $gatttool = qx(which gatttool);
chomp $gatttool; chomp $gatttool;
if(-x $gatttool) { if(-x $gatttool) {
my $gtResult; my $gtResult;
my $cmd; my $cmd;
my $wait = 1;
my $sshHost = AttrVal($name,"sshHost","none"); my $sshHost = AttrVal($name,"sshHost","none");
my $hciDevice = "hci".$hash->{helper}{hcidevices}[$hash->{helper}{currenthcidevice}];
while($wait) {
my $grepGatttool;
$grepGatttool = qx(ps ax| grep -E \'gatttool -i $hciDevice -b $mac\' | grep -v grep) if($sshHost eq 'none');
$grepGatttool = qx(ssh $sshHost 'ps ax| grep -E "gatttool -i $hciDevice -b $mac" | grep -v grep') if($sshHost ne 'none');
while($wait) {
my $grepGatttool = qx(ps ax| grep -E \'gatttool -b $mac\' | grep -v grep);
if(not $grepGatttool =~ /^\s*$/) { if(not $grepGatttool =~ /^\s*$/) {
Log3 $name, 4, "EQ3BT ($name) - ExecGatttool_Run: another gatttool process is running. waiting..."; #another gattool is running
Log3 $name, 5, "EQ3BT ($name): another gatttool process is running. waiting...";
sleep(1); sleep(1);
} else { } else {
$wait = 0; $wait = 0;
@ -542,16 +525,26 @@ sub EQ3BT_execGatttool($) {
$value .= $currentDate; $value .= $currentDate;
} }
my $hciDevice = "hci".$hash->{helper}{hcidevices}[$hash->{helper}{currenthcidevice}];
#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";
}
$cmd = "ssh $sshHost '" if($sshHost ne 'none'); if(defined($listen) && $listen eq "listen") {
$cmd .= "timeout 10 " if(defined($listen) and $listen eq "listen"); $cmd = "timeout ".AttrVal($name, "timeout", 15)." ".$cmd." --listen";
$cmd .= "gatttool -i $hciDevice -b $mac "; }
$cmd .= "--char-write-req -a $handle -n $value";
$cmd .= " --listen" if(defined($listen) and $listen eq "listen"); #redirect stderr to stdout
$cmd .= " 2>&1 /dev/null"; if( $sshHost ne 'none' ) {
$cmd .= "'" if($sshHost ne 'none'); $cmd .= " 2>&1'";
} else {
$cmd .= " 2>&1";
}
Log3 $name, 4, "EQ3BT ($name): $cmd"; Log3 $name, 5, "EQ3BT ($name): $cmd";
$gtResult = qx($cmd); $gtResult = qx($cmd);
chomp $gtResult; chomp $gtResult;
my @gtResultArr = split("\n", $gtResult); my @gtResultArr = split("\n", $gtResult);
@ -561,7 +554,7 @@ sub EQ3BT_execGatttool($) {
if(defined($gtResultArr[1]) && $gtResultArr[1] =~ /Notification handle = 0x0421 value: (.*)/) { if(defined($gtResultArr[1]) && $gtResultArr[1] =~ /Notification handle = 0x0421 value: (.*)/) {
return "$name|$mac|ok|$workType|$handle|$value|$1"; return "$name|$mac|ok|$workType|$handle|$value|$1";
} else { } else {
if(defined($listen) and $listen eq "listen") { if(defined($listen) && $listen eq "listen") {
return "$name|$mac|error|$workType|$handle|$value|notification missing"; return "$name|$mac|error|$workType|$handle|$value|notification missing";
} else { } else {
return "$name|$mac|ok|$workType|$handle|$value"; return "$name|$mac|ok|$workType|$handle|$value";
@ -758,7 +751,7 @@ sub EQ3BT_setChildlock($$) {
my $data = "01"; my $data = "01";
$data = "00" if($onoff eq "off"); $data = "00" if($onoff eq "off");
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setChildlock|0x0411|80".$data, "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash); $hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setChildlock|0x0411|80".$data, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
return undef; return undef;
} }
@ -816,8 +809,8 @@ sub EQ3BT_Get($$) {
<h3>EQ3BT</h3> <h3>EQ3BT</h3>
<ul> <ul>
EQ3BT is used to control a EQ3 Bluetooth Smart Radiator Thermostat<br><br> EQ3BT is used to control a EQ3 Bluetooth Smart Radiator Thermostat<br><br>
<b>Note:</b> The bluez package is required to run this module. Please check if gatttool executable is available on your system. <b>Note:</b> The bluez package is required to run this module. Please check if gatttool executable is available on your system.
<br> <br>
<br> <br>
<a name="EQ3BTdefine" id="EQ3BTdefine"></a> <a name="EQ3BTdefine" id="EQ3BTdefine"></a>