change code for --listen option

This commit is contained in:
Marko Oldenburg 2018-02-10 03:08:12 +01:00
parent 817c315801
commit c04ca68254

View File

@ -53,8 +53,8 @@ my $version = "2.0.8";
my %XiaomiModels = (
flowerSens => {'rdata' => '0x35' ,'wdata' => '0x33' ,'wdataValue' => 'A01F' ,'battery' => '0x38' ,'firmware' => '0x38'},
thermoHygroSens => {'wdata' => '0x10' ,'wdataValue' => '0100' ,'battery' => '0x18' ,'firmware' => '0x24' ,'devicename' => '0x3'},
flowerSens => {'rdata' => '0x35' ,'wdata' => '0x33' ,'wdataValue' => 'A01F' ,'wdatalisten' => 0 ,'battery' => '0x38' ,'firmware' => '0x38'},
thermoHygroSens => {'wdata' => '0x10' ,'wdataValue' => '0100' ,'wdatalisten' => 1 ,'battery' => '0x18' ,'firmware' => '0x24' ,'devicename' => '0x3'},
);
my %CallBatteryAge = ( '8h' => 28800,
@ -416,7 +416,7 @@ sub XiaomiBTLESens_CreateParamGatttool($@) {
Log3 $name, 5, "XiaomiBTLESens ($name) - Read XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle";
} elsif( $mod eq 'write' ) {
$hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|".$mod."|".$handle."|".$value, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless( exists($hash->{helper}{RUNNING_PID}) );
$hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|".$mod."|".$handle."|".$value."|".$XiaomiModels{AttrVal($name,'model','')}{wdatalisten}, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless( exists($hash->{helper}{RUNNING_PID}) );
readingsSingleUpdate($hash,"state","write sensor data",1);
@ -428,14 +428,14 @@ sub XiaomiBTLESens_ExecGatttool_Run($) {
my $string = shift;
my ($name,$mac,$gattCmd,$handle,$value) = split("\\|", $string);
my $sshHost = AttrVal($name,"sshHost","none");
my ($name,$mac,$gattCmd,$handle,$value,$listen) = split("\\|", $string);
my $sshHost = AttrVal($name,"sshHost","none");
my $gatttool;
my $json_notification;
$gatttool = qx(which gatttool) if($sshHost eq 'none');
$gatttool = qx(ssh $sshHost 'which gatttool') if($sshHost ne 'none');
$gatttool = qx(which gatttool) if($sshHost eq 'none');
$gatttool = qx(ssh $sshHost 'which gatttool') if($sshHost ne 'none');
chomp $gatttool;
if(defined($gatttool) and ($gatttool)) {
@ -443,9 +443,24 @@ sub XiaomiBTLESens_ExecGatttool_Run($) {
my $cmd;
my $loop;
my @gtResult;
my $wait = 1;
my $sshHost = AttrVal($name,"sshHost","none");
my $hci = AttrVal($name,"hciDevice","hci0");
my $wait = 1;
my $sshHost = AttrVal($name,"sshHost","none");
my $hci = AttrVal($name,"hciDevice","hci0");
$cmd = "ssh $sshHost '" if($sshHost ne 'none');
$cmd .= "timeout 5 " if($listen);
$cmd .= "gatttool -i $hci -b $mac ";
$cmd .= "--char-read -a $handle" if($gattCmd eq 'read');
$cmd .= "--char-write-req -a $handle -n $value" if($gattCmd eq 'write');
$cmd .= " --listen" if($listen);
$cmd .= " 2>&1 /dev/null";
$cmd .= "'" if($sshHost ne 'none');
#$cmd = "ssh $sshHost 'timeout 5 gatttool -i $hci -b $mac --char-write-req -a $handle -n $value --listen 2>&1 /dev/null'" if( $sshHost ne 'none' and AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
#$cmd = "timeout 5 gatttool -i $hci -b $mac --char-write-req -a $handle -n $value --listen 2>&1 /dev/null" if( $sshHost eq 'none' and AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
$cmd = "ssh $sshHost 'gatttool -i $hci -b $mac --char-write-req -a 0x33 -n A01F && gatttool -i $hci -b $mac --char-read -a 0x35 2>&1 /dev/null'" if($sshHost ne 'none' and $gattCmd eq 'write' and AttrVal($name,"model","none") eq 'flowerSens');
while($wait) {
@ -460,21 +475,7 @@ sub XiaomiBTLESens_ExecGatttool_Run($) {
$wait = 0;
}
}
$cmd .= "ssh $sshHost '" if($sshHost ne 'none');
$cmd .= "gatttool -i $hci -b $mac ";
$cmd .= "--char-read -a $handle" if($gattCmd eq 'read');
$cmd .= "--char-write-req -a $handle -n $value" if($gattCmd eq 'write');
$cmd .= " 2>&1 /dev/null";
$cmd .= "'" if($sshHost ne 'none');
$cmd = "ssh $sshHost 'timeout 5 gatttool -i $hci -b $mac --char-write-req -a $handle -n $value --listen 2>&1 /dev/null'" if( $sshHost ne 'none' and AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
$cmd = "timeout 5 gatttool -i $hci -b $mac --char-write-req -a $handle -n $value --listen 2>&1 /dev/null" if( $sshHost eq 'none' and AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
$cmd = "ssh $sshHost 'gatttool -i $hci -b $mac --char-write-req -a 0x33 -n A01F && gatttool -i $hci -b $mac --char-read -a 0x35 2>&1 /dev/null'" if($sshHost ne 'none' and $gattCmd eq 'write' and AttrVal($name,"model","none") eq 'flowerSens');
$loop = 0;
do {