code style, fix bug then use ThermoHygro Sensor
This commit is contained in:
parent
89c6e61b85
commit
e8d63495eb
@ -632,10 +632,11 @@ sub CreateParamGatttool($@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Gatttool_executeCommand{
|
sub Gatttool_executeCommand($) {
|
||||||
my $command = join ' ', @_;
|
my $command = join( ' ', @_ );
|
||||||
($_ = qx{$command 2>&1}, $? >> 8);
|
( $_ = qx{$command 2>&1}, $? >> 8 );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ExecGatttool_Run($) {
|
sub ExecGatttool_Run($) {
|
||||||
|
|
||||||
my $string = shift;
|
my $string = shift;
|
||||||
@ -666,12 +667,14 @@ sub ExecGatttool_Run($) {
|
|||||||
$cmd .= "--char-write-req -a $handle -n $value"
|
$cmd .= "--char-write-req -a $handle -n $value"
|
||||||
if ( $gattCmd eq 'write' );
|
if ( $gattCmd eq 'write' );
|
||||||
$cmd .= " --listen" if ($listen);
|
$cmd .= " --listen" if ($listen);
|
||||||
# $cmd .= " 2>&1 /dev/null";
|
|
||||||
|
# $cmd .= " 2>&1 /dev/null";
|
||||||
$cmd .= " 2>&1";
|
$cmd .= " 2>&1";
|
||||||
$cmd .= "'" if ( $sshHost ne 'none' );
|
$cmd .= "'" if ( $sshHost ne 'none' );
|
||||||
|
|
||||||
# $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'"
|
# $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'"
|
||||||
$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 '"
|
$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 '"
|
||||||
if ( $sshHost ne 'none'
|
if ( $sshHost ne 'none'
|
||||||
and $gattCmd eq 'write'
|
and $gattCmd eq 'write'
|
||||||
and AttrVal( $name, "model", "none" ) eq 'flowerSens' );
|
and AttrVal( $name, "model", "none" ) eq 'flowerSens' );
|
||||||
@ -680,15 +683,19 @@ sub ExecGatttool_Run($) {
|
|||||||
|
|
||||||
my $grepGatttool;
|
my $grepGatttool;
|
||||||
my $gatttoolCmdlineStaticEscaped =
|
my $gatttoolCmdlineStaticEscaped =
|
||||||
BTLE_CmdlinePreventGrepFalsePositive(
|
BTLE_CmdlinePreventGrepFalsePositive("gatttool -i $hci -b $mac");
|
||||||
"gatttool -i $hci -b $mac");
|
|
||||||
my $psCommand = AttrVal( $name, 'psCommand', 'ps ax' );
|
my $psCommand = AttrVal( $name, 'psCommand', 'ps ax' );
|
||||||
Log3 $name, 5, 'Execute Command: $psCommand | grep -E "$gatttoolCmdlineStaticEscaped"';
|
Log3 $name, 5,
|
||||||
|
"XiaomiBTLESens ($name) - ExecGatttool_Run: Execute Command $psCommand | grep -E $gatttoolCmdlineStaticEscaped";
|
||||||
|
|
||||||
# $grepGatttool = qx(ps ax| grep -E \'$gatttoolCmdlineStaticEscaped\')
|
# $grepGatttool = qx(ps ax| grep -E \'$gatttoolCmdlineStaticEscaped\')
|
||||||
$grepGatttool = qx( $psCommand | grep -E \'$gatttoolCmdlineStaticEscaped\')
|
$grepGatttool =
|
||||||
|
qx($psCommand | grep -E \'$gatttoolCmdlineStaticEscaped\')
|
||||||
if ( $sshHost eq 'none' );
|
if ( $sshHost eq 'none' );
|
||||||
|
|
||||||
# $grepGatttool = qx(ssh $sshHost 'ps ax| grep -E "$gatttoolCmdlineStaticEscaped"')
|
# $grepGatttool = qx(ssh $sshHost 'ps ax| grep -E "$gatttoolCmdlineStaticEscaped"')
|
||||||
$grepGatttool = qx(ssh $sshHost ' $psCommand | grep -E "$gatttoolCmdlineStaticEscaped"')
|
$grepGatttool =
|
||||||
|
qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"')
|
||||||
if ( $sshHost ne 'none' );
|
if ( $sshHost ne 'none' );
|
||||||
|
|
||||||
if ( not $grepGatttool =~ /^\s*$/ ) {
|
if ( not $grepGatttool =~ /^\s*$/ ) {
|
||||||
@ -702,14 +709,16 @@ sub ExecGatttool_Run($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
my $returnString ="";
|
my $returnString;
|
||||||
my $returnCode = "1";
|
my $returnCode = 1;
|
||||||
do {
|
do {
|
||||||
|
|
||||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop";
|
Log3 $name, 5,
|
||||||
|
"XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop";
|
||||||
|
|
||||||
|
( $returnString, $returnCode ) = Gatttool_executeCommand($cmd);
|
||||||
|
@gtResult = split( ": ", $returnString );
|
||||||
|
|
||||||
($returnString, $returnCode) = Gatttool_executeCommand($cmd);
|
|
||||||
@gtResult = split( ": ", $returnString);
|
|
||||||
# @gtResult = split( ": ", qx($cmd) );
|
# @gtResult = split( ": ", qx($cmd) );
|
||||||
|
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
@ -717,12 +726,14 @@ sub ExecGatttool_Run($) {
|
|||||||
. join( ",", @gtResult );
|
. join( ",", @gtResult );
|
||||||
$loop++;
|
$loop++;
|
||||||
|
|
||||||
$returnCode = "2"
|
$returnCode = 2
|
||||||
unless ( defined( $gtResult[0] ) );
|
unless ( defined( $gtResult[0] ) );
|
||||||
|
|
||||||
# } while ( $loop < 5 and $gtResult[0] eq 'connect error' );
|
# } while ( $loop < 5 and $gtResult[0] eq 'connect error' );
|
||||||
} while ( $loop < 5 and $returnCode ne "0" );
|
} while ( $loop < 5 and $returnCode != 0 );
|
||||||
Log3 $name, 3,"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\"" if ($returnCode ne "0");
|
Log3 $name, 3,
|
||||||
|
"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\""
|
||||||
|
if ( $returnCode != 0 );
|
||||||
|
|
||||||
Log3 $name, 4,
|
Log3 $name, 4,
|
||||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool result "
|
"XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool result "
|
||||||
@ -750,7 +761,7 @@ sub ExecGatttool_Run($) {
|
|||||||
if ( $gtResult[1] =~ /^([0-9a-f]{2}(\s?))*$/ ) {
|
if ( $gtResult[1] =~ /^([0-9a-f]{2}(\s?))*$/ ) {
|
||||||
return "$name|$mac|ok|$gattCmd|$handle|$json_notification";
|
return "$name|$mac|ok|$gattCmd|$handle|$json_notification";
|
||||||
}
|
}
|
||||||
elsif ( $gtResult[0] ne 'connect error' and $gattCmd eq 'write' ) {
|
elsif ( $returnCode == 0 and $gattCmd eq 'write' ) {
|
||||||
if ( $sshHost ne 'none' ) {
|
if ( $sshHost ne 'none' ) {
|
||||||
ExecGatttool_Run( $name . "|" . $mac . "|read|0x35" );
|
ExecGatttool_Run( $name . "|" . $mac . "|read|0x35" );
|
||||||
}
|
}
|
||||||
@ -1552,7 +1563,7 @@ sub BTLE_CmdlinePreventGrepFalsePositive($) {
|
|||||||
],
|
],
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v2.8.1",
|
"version": "v2.8.2",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user