2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +00:00

74_XiaomiBTLESens: add special patch from charlie71

git-svn-id: https://svn.fhem.de/fhem/trunk@20864 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2020-01-01 20:06:37 +00:00
parent abd303277f
commit e3e27917d9
2 changed files with 31 additions and 13 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- change: 74_XiaomiBTLESens: add special patch from charlie71
- bugfix: 93_DbLog: fix behavior if value is empty and attribute - bugfix: 93_DbLog: fix behavior if value is empty and attribute
addStateEvent is set (default), Forum: #106769 addStateEvent is set (default), Forum: #106769
- bugfix: 73_AutoShuttersControl: fix IsDay Bug then use Privacy Down - bugfix: 73_AutoShuttersControl: fix IsDay Bug then use Privacy Down

View File

@ -5,6 +5,10 @@
# (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com) # (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
# All rights reserved # All rights reserved
# #
# Special thanks goes to:
# - Charlie71: add special patch
#
#
# This script is free software; you can redistribute it and/or modify # This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@ -218,6 +222,7 @@ sub Initialize($) {
. "minLux " . "minLux "
. "maxLux " . "maxLux "
. "sshHost " . "sshHost "
. "psCommand "
. "model:flowerSens,thermoHygroSens,clearGrassSens " . "model:flowerSens,thermoHygroSens,clearGrassSens "
. "blockingCallLoglevel:2,3,4,5 " . "blockingCallLoglevel:2,3,4,5 "
. $readingFnAttributes; . $readingFnAttributes;
@ -627,6 +632,10 @@ sub CreateParamGatttool($@) {
} }
} }
sub Gatttool_executeCommand{
my $command = join ' ', @_;
($_ = qx{$command 2>&1}, $? >> 8);
}
sub ExecGatttool_Run($) { sub ExecGatttool_Run($) {
my $string = shift; my $string = shift;
@ -657,11 +666,12 @@ 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 .= "'" if ( $sshHost ne 'none' ); $cmd .= "'" if ( $sshHost ne 'none' );
$cmd = # $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'"
"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 '"
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' );
@ -672,11 +682,13 @@ sub ExecGatttool_Run($) {
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' );
$grepGatttool = qx(ps ax| grep -E \'$gatttoolCmdlineStaticEscaped\') Log3 $name, 5, 'Execute Command: $psCommand | grep -E "$gatttoolCmdlineStaticEscaped"';
# $grepGatttool = qx(ps ax| grep -E \'$gatttoolCmdlineStaticEscaped\')
$grepGatttool = qx( $psCommand | grep -E \'$gatttoolCmdlineStaticEscaped\')
if ( $sshHost eq 'none' ); if ( $sshHost eq 'none' );
$grepGatttool = # $grepGatttool = qx(ssh $sshHost 'ps ax| grep -E "$gatttoolCmdlineStaticEscaped"')
qx(ssh $sshHost 'ps ax| 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*$/ ) {
@ -690,22 +702,27 @@ sub ExecGatttool_Run($) {
} }
$loop = 0; $loop = 0;
my $returnString ="";
my $returnCode = "1";
do { do {
Log3 $name, 5, Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop";
"XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop";
@gtResult = split( ": ", qx($cmd) ); ($returnString, $returnCode) = Gatttool_executeCommand($cmd);
@gtResult = split( ": ", $returnString);
# @gtResult = split( ": ", qx($cmd) );
Log3 $name, 5, Log3 $name, 5,
"XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool loop result " "XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool loop result "
. join( ",", @gtResult ); . join( ",", @gtResult );
$loop++; $loop++;
$gtResult[0] = 'connect error' $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" );
Log3 $name, 3,"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\"" if ($returnCode ne "0");
Log3 $name, 4, Log3 $name, 4,
"XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool result " "XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool result "
@ -1535,7 +1552,7 @@ sub BTLE_CmdlinePreventGrepFalsePositive($) {
], ],
"release_status": "stable", "release_status": "stable",
"license": "GPL_2", "license": "GPL_2",
"version": "v2.8.0", "version": "v2.8.1",
"author": [ "author": [
"Marko Oldenburg <leongaultier@gmail.com>" "Marko Oldenburg <leongaultier@gmail.com>"
], ],