mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
74_XiaomiBTLESens: fix many bugs with ssh connection, fix negativ temperature bug
git-svn-id: https://svn.fhem.de/fhem/trunk@16122 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
696e794dde
commit
95e43d1904
@ -1,5 +1,7 @@
|
||||
# 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.
|
||||
- bugfix: 74_XiaomiBTLESens: fix many bugs with ssh connection, fix negativ
|
||||
temperature bug
|
||||
- feature: 93_DbRep:V7.8.1, new command "eraseReadings", some fixes
|
||||
- bugfix: 93_DbLog:V3.8.4, cover userCommands, avoid crash (forum:#83973)
|
||||
- feature: 51_MOBILEALERTS: Added directionInt for MA10660
|
||||
|
@ -47,7 +47,7 @@ use JSON;
|
||||
use Blocking;
|
||||
|
||||
|
||||
my $version = "2.0.5";
|
||||
my $version = "2.0.7";
|
||||
|
||||
|
||||
|
||||
@ -413,14 +413,14 @@ sub XiaomiBTLESens_CreateParamGatttool($@) {
|
||||
|
||||
readingsSingleUpdate($hash,"state","read sensor data",1);
|
||||
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - Read XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle";
|
||||
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}) );
|
||||
|
||||
readingsSingleUpdate($hash,"state","write sensor data",1);
|
||||
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - Write XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle|$value";
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Write XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle|$value";
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,7 +454,7 @@ sub XiaomiBTLESens_ExecGatttool_Run($) {
|
||||
$grepGatttool = qx(ssh $sshHost 'ps ax| grep -E "gatttool -i $hci -b $mac" | grep -v grep') if($sshHost ne 'none');
|
||||
|
||||
if(not $grepGatttool =~ /^\s*$/) {
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Run: another gatttool process is running. waiting...";
|
||||
Log3 $name, 3, "XiaomiBTLESens ($name) - ExecGatttool_Run: another gatttool process is running. waiting...";
|
||||
sleep(1);
|
||||
} else {
|
||||
$wait = 0;
|
||||
@ -465,19 +465,23 @@ sub XiaomiBTLESens_ExecGatttool_Run($) {
|
||||
$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 = "timeout 15 ".$cmd." --listen" if( AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
|
||||
$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( 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 {
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command $cmd and loop $loop";
|
||||
@gtResult = split(": ",qx($cmd));
|
||||
@gtResult = split(": ",qx($cmd)); # unless( AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
|
||||
#@gtResult = split(",",qx($cmd)) if( AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool loop result ".join(",", @gtResult);
|
||||
$loop++;
|
||||
|
||||
($gtResult[1]) = split("\n",$gtResult[1]) if( AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
|
||||
$gtResult[1] =~ s/\\n//g if( AttrVal($name,"model","none") eq 'thermoHygroSens' and $gattCmd eq 'write' and $handle eq '0x10');
|
||||
|
||||
$gtResult[0] = 'connect error'
|
||||
unless( defined($gtResult[0]) );
|
||||
|
||||
@ -523,11 +527,11 @@ sub XiaomiBTLESens_ExecGatttool_Done($) {
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Done: Helper is disabled. Stop processing" if($hash->{helper}{DISABLED});
|
||||
return if($hash->{helper}{DISABLED});
|
||||
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - ExecGatttool_Done: gatttool return string: $string";
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Done: gatttool return string: $string";
|
||||
|
||||
my $decode_json = eval{decode_json($json_notification)};
|
||||
if($@){
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Done: JSON error while request: $@";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - ExecGatttool_Done: JSON error while request: $@";
|
||||
}
|
||||
|
||||
|
||||
@ -565,7 +569,7 @@ sub XiaomiBTLESens_ProcessingNotification($@) {
|
||||
my $readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ProcessingNotification";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - ProcessingNotification";
|
||||
|
||||
if( AttrVal($name,'model','none') eq 'flowerSens' ) {
|
||||
if( $handle eq '0x38' ) {
|
||||
@ -624,7 +628,7 @@ sub XiaomiBTLESens_FlowerSensHandle0x38($$) {
|
||||
my %readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - FlowerSens Handle0x38";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x38";
|
||||
|
||||
my @dataBatFw = split(" ",$notification);
|
||||
|
||||
@ -645,7 +649,7 @@ sub XiaomiBTLESens_FlowerSensHandle0x35($$) {
|
||||
my %readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - FlowerSens Handle0x35";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x35";
|
||||
|
||||
my @dataSensor = split(" ",$notification);
|
||||
|
||||
@ -654,7 +658,7 @@ sub XiaomiBTLESens_FlowerSensHandle0x35($$) {
|
||||
unless( $dataSensor[0] ne "aa" and $dataSensor[1] ne "bb" and $dataSensor[2] ne "cc" and $dataSensor[3] ne "dd" and $dataSensor[4] ne "ee" and $dataSensor[5] ne "ff");
|
||||
|
||||
if( $dataSensor[1] eq "ff" ) {
|
||||
$readings{'temperature'} = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff") / 10;
|
||||
$readings{'temperature'} = (hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff")) / 10;
|
||||
} else {
|
||||
$readings{'temperature'} = hex("0x".$dataSensor[1].$dataSensor[0]) / 10;
|
||||
}
|
||||
@ -675,7 +679,7 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x18($$) {
|
||||
my %readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x18";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x18";
|
||||
|
||||
chomp($notification);
|
||||
|
||||
@ -695,7 +699,7 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x10($$) {
|
||||
my %readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x10";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x10";
|
||||
|
||||
$notification =~ s/\s+//g;
|
||||
|
||||
@ -714,7 +718,7 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x24($$) {
|
||||
my %readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x24";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x24";
|
||||
|
||||
$notification =~ s/\s+//g;
|
||||
|
||||
@ -732,7 +736,7 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x3($$) {
|
||||
my %readings;
|
||||
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x3";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x3";
|
||||
|
||||
$notification =~ s/\s+//g;
|
||||
|
||||
@ -794,7 +798,7 @@ sub XiaomiBTLESens_ProcessingErrors($$) {
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - ProcessingErrors";
|
||||
Log3 $name, 4, "XiaomiBTLESens ($name) - ProcessingErrors";
|
||||
$readings{'lastGattError'} = $notification;
|
||||
|
||||
XiaomiBTLESens_WriteReadings($hash,\%readings);
|
||||
|
Loading…
Reference in New Issue
Block a user