2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

74_XiaomiFlowerSens: fix back to blockingDone Routine

git-svn-id: https://svn.fhem.de/fhem/trunk@13283 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2017-01-30 07:29:03 +00:00
parent c896fe3cc8
commit e6bf179cbb
2 changed files with 55 additions and 43 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.
- bugfix: 74_XiaomiFlowerSens: 0.6.3 fix blockingDone Routine
- feature: 75_MSG: support for ReplaceSetMagic; msg command may now be used - feature: 75_MSG: support for ReplaceSetMagic; msg command may now be used
with texts containing [device:reading] to replace with with texts containing [device:reading] to replace with
found readings found readings
@ -14,14 +15,14 @@
- bugfix: 10_EQ3BT: do not run parallel gatttool commands for same dev - bugfix: 10_EQ3BT: do not run parallel gatttool commands for same dev
- feature: FB_CALLMONITOR: new set command "reopen" - feature: FB_CALLMONITOR: new set command "reopen"
- feature: 66_ECMD: new attribute autoReopen - feature: 66_ECMD: new attribute autoReopen
- update: 74_AMAD: Version 2.6.8 new feature sendSMS - update: 74_AMAD: Version 2.6.8 new feature sendSMS
- feature: 66_ECMD: new attribute autoReopen - feature: 66_ECMD: new attribute autoReopen
- bugfix: 98_DOIFtools.pm: fixed bug from last change - bugfix: 98_DOIFtools.pm: fixed bug from last change
- update: 98_DOIFtools.pm: some code rework - update: 98_DOIFtools.pm: some code rework
- update: 98_DOIFtools.pm: dynamic column width in report - update: 98_DOIFtools.pm: dynamic column width in report
- update: 98_DOIFtools.pm: add delete readings in other devices than DOIF - update: 98_DOIFtools.pm: add delete readings in other devices than DOIF
- update: 88_HMCCU.pm: version 3.9 - update: 88_HMCCU.pm: version 3.9
- update: 98_DOIFtools.pm: marking an eventline in DOIFs event monitor - update: 98_DOIFtools.pm: marking an eventline in DOIFs event monitor
shows different representations of the event as operand shows different representations of the event as operand
for DOIF definitions for DOIF definitions
- update: 73_NUKIBridge/74_NUKIDevice 0.6.0 Support for API v1.5 - update: 73_NUKIBridge/74_NUKIDevice 0.6.0 Support for API v1.5

View File

@ -35,7 +35,7 @@ use POSIX;
use JSON; use JSON;
use Blocking; use Blocking;
my $version = "0.6.0"; my $version = "0.6.3";
@ -63,15 +63,15 @@ sub XiaomiFlowerSens_Initialize($) {
my ($hash) = @_; my ($hash) = @_;
$hash->{SetFn} = "XiaomiFlowerSens_Set"; $hash->{SetFn} = "XiaomiFlowerSens_Set";
$hash->{DefFn} = "XiaomiFlowerSens_Define"; $hash->{DefFn} = "XiaomiFlowerSens_Define";
$hash->{UndefFn} = "XiaomiFlowerSens_Undef"; $hash->{UndefFn} = "XiaomiFlowerSens_Undef";
$hash->{AttrFn} = "XiaomiFlowerSens_Attr"; $hash->{AttrFn} = "XiaomiFlowerSens_Attr";
$hash->{AttrList} = "interval ". $hash->{AttrList} = "interval ".
"disable:1 ". "disable:1 ".
"hciDevice:hci0,hci1,hci2 ". "hciDevice:hci0,hci1,hci2 ".
"disabledForIntervals ". "disabledForIntervals ".
$readingFnAttributes; $readingFnAttributes;
@ -89,10 +89,10 @@ sub XiaomiFlowerSens_Define($$) {
return "too few parameters: define <name> XiaomiFlowerSens <BTMAC>" if( @a != 3 ); return "too few parameters: define <name> XiaomiFlowerSens <BTMAC>" if( @a != 3 );
my $name = $a[0]; my $name = $a[0];
my $mac = $a[2]; my $mac = $a[2];
$hash->{BTMAC} = $mac; $hash->{BTMAC} = $mac;
$hash->{VERSION} = $version; $hash->{VERSION} = $version;
$hash->{INTERVAL} = 300; $hash->{INTERVAL} = 300;
@ -125,6 +125,7 @@ sub XiaomiFlowerSens_Undef($$) {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
BlockingKill($hash->{helper}{RUNNING_PID}) if(defined($hash->{helper}{RUNNING_PID}));
delete($modules{XiaomiFlowerSens}{defptr}{$mac}); delete($modules{XiaomiFlowerSens}{defptr}{$mac});
Log3 $name, 3, "Sub XiaomiFlowerSens_Undef ($name) - delete device $name"; Log3 $name, 3, "Sub XiaomiFlowerSens_Undef ($name) - delete device $name";
@ -134,9 +135,9 @@ sub XiaomiFlowerSens_Undef($$) {
sub XiaomiFlowerSens_Attr(@) { sub XiaomiFlowerSens_Attr(@) {
my ( $cmd, $name, $attrName, $attrVal ) = @_; my ( $cmd, $name, $attrName, $attrVal ) = @_;
my $hash = $defs{$name}; my $hash = $defs{$name};
my $orig = $attrVal; my $orig = $attrVal;
if( $attrName eq "disable" ) { if( $attrName eq "disable" ) {
@ -227,8 +228,8 @@ sub XiaomiFlowerSens_stateRequestTimer($) {
sub XiaomiFlowerSens_Set($$@) { sub XiaomiFlowerSens_Set($$@) {
my ($hash, $name, @aa) = @_; my ($hash, $name, @aa) = @_;
my ($cmd, $arg) = @aa; my ($cmd, $arg) = @aa;
my $action; my $action;
if( $cmd eq 'statusRequest' ) { if( $cmd eq 'statusRequest' ) {
@ -257,7 +258,6 @@ sub XiaomiFlowerSens_Run($) {
$wfr = 1; $wfr = 1;
} }
BlockingKill($hash->{helper}{RUNNING_PID}) if(defined($hash->{helper}{RUNNING_PID}));
my $response_encode = XiaomiFlowerSens_forRun_encodeJSON($mac,$wfr); my $response_encode = XiaomiFlowerSens_forRun_encodeJSON($mac,$wfr);
@ -287,7 +287,8 @@ sub XiaomiFlowerSens_BlockingRun($) {
Log3 $name, 4, "Sub XiaomiFlowerSens_BlockingRun ($name) - Processing response data: $sensData"; Log3 $name, 4, "Sub XiaomiFlowerSens_BlockingRun ($name) - Processing response data: $sensData";
return "$name|$sensData" # if error in stdout the error will given to $lux variable
return "$name|Unknown Error, look at verbose 5 output" # if error in stdout the error will given to $sensData variable
unless( defined($batFwData) ); unless( defined($batFwData) );
@ -295,30 +296,30 @@ sub XiaomiFlowerSens_BlockingRun($) {
#### processing sensor respons #### processing sensor respons
my @dataSensor = split(" ",$sensData); my @dataSensor = split(" ",$sensData);
return "$name|charWrite faild" return "$name|charWrite faild"
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"); 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");
my $temp; my $temp;
if( $dataSensor[1] eq "ff" ) { if( $dataSensor[1] eq "ff" ) {
$temp = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff"); $temp = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff");
} else { } else {
$temp = hex("0x".$dataSensor[1].$dataSensor[0]); $temp = hex("0x".$dataSensor[1].$dataSensor[0]);
} }
my $lux = hex("0x".$dataSensor[4].$dataSensor[3]); my $lux = hex("0x".$dataSensor[4].$dataSensor[3]);
my $moisture = hex("0x".$dataSensor[7]); my $moisture = hex("0x".$dataSensor[7]);
my $fertility = hex("0x".$dataSensor[9].$dataSensor[8]); my $fertility = hex("0x".$dataSensor[9].$dataSensor[8]);
### processing firmware and battery response ### processing firmware and battery response
my @dataBatFw = split(" ",$batFwData); my @dataBatFw = split(" ",$batFwData);
my $blevel = hex("0x".$dataBatFw[0]); my $blevel = hex("0x".$dataBatFw[0]);
my $fw = ($dataBatFw[2]-30).".".($dataBatFw[4]-30).".".($dataBatFw[6]-30); my $fw = ($dataBatFw[2]-30).".".($dataBatFw[4]-30).".".($dataBatFw[6]-30);
@ -359,8 +360,10 @@ sub XiaomiFlowerSens_callGatttool($@) {
if($wfr == 1) { if($wfr == 1) {
do { do {
$wresp = qx(gatttool -i $hci -b $mac --char-write-req -a 0x33 -n A01F) if($wfr == 1); $wresp = qx(gatttool -i $hci -b $mac --char-write-req -a 0x33 -n A01F 2>&1 /dev/null) if($wfr == 1);
$loop++; $loop++;
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call gatttool charWrite loop $loop";
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - charWrite wresp: $wresp" if(defined($wresp));
} while( ($loop < 10) and (not defined($wresp)) ); } while( ($loop < 10) and (not defined($wresp)) );
} }
@ -369,11 +372,12 @@ sub XiaomiFlowerSens_callGatttool($@) {
do { do {
@readSensData = split(": ",qx(gatttool -i $hci -b $mac --char-read -a 0x35 2>&1 /dev/null)); @readSensData = split(": ",qx(gatttool -i $hci -b $mac --char-read -a 0x35 2>&1 /dev/null));
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call gatttool charRead loop $loop";
$loop++; $loop++;
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call gatttool charRead loop $loop";
} while( $loop < 10 and $readSensData[0] =~ /connect error/ ); } while( $loop < 10 and $readSensData[0] =~ /connect error/ );
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - processing gatttool response. sensData[0]: $readSensData[0]";
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - processing gatttool response. sensData: $readSensData[1]"; Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - processing gatttool response. sensData: $readSensData[1]";
return ($readSensData[1],undef) return ($readSensData[1],undef)
@ -384,7 +388,7 @@ sub XiaomiFlowerSens_callGatttool($@) {
do { do {
@readBatFwData = split(": ",qx(gatttool -i $hci -b $mac --char-read -a 0x38 2>&1 /dev/null)); @readBatFwData = split(": ",qx(gatttool -i $hci -b $mac --char-read -a 0x38 2>&1 /dev/null));
Log3 $name, 4, "Sub XiaomiFlowerSens ($name) - call gatttool readBatFw loop $loop"; Log3 $name, 4, "Sub XiaomiFlowerSens ($name) - call gatttool readBatFw loop $loop";
$loop++; $loop++;
@ -432,9 +436,9 @@ sub XiaomiFlowerSens_forDone_encodeJSON($$$$$$) {
sub XiaomiFlowerSens_BlockingDone($) { sub XiaomiFlowerSens_BlockingDone($) {
my ($string) = @_; my ($string) = @_;
my ($name,$response) = split("\\|",$string); my ($name,$response) = split("\\|",$string);
my $hash = $defs{$name}; my $hash = $defs{$name};
delete($hash->{helper}{RUNNING_PID}); delete($hash->{helper}{RUNNING_PID});
@ -455,6 +459,13 @@ sub XiaomiFlowerSens_BlockingDone($) {
readingsEndUpdate($hash,1); readingsEndUpdate($hash,1);
return undef; return undef;
} elsif( $response eq "Unknown Error, look at verbose 5 output" ) {
readingsBulkUpdate($hash,"lastGattError","$response");
readingsBulkUpdate($hash,"state","unreachable");
readingsEndUpdate($hash,1);
return undef;
} elsif( ref($response) eq "HASH" ) { } elsif( ref($response) eq "HASH" ) {
readingsBulkUpdate($hash,"lastGattError","$response"); readingsBulkUpdate($hash,"lastGattError","$response");
readingsBulkUpdate($hash,"state","unreachable"); readingsBulkUpdate($hash,"state","unreachable");
@ -482,8 +493,8 @@ sub XiaomiFlowerSens_BlockingDone($) {
sub XiaomiFlowerSens_BlockingAborted($) { sub XiaomiFlowerSens_BlockingAborted($) {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
delete($hash->{helper}{RUNNING_PID}); delete($hash->{helper}{RUNNING_PID});
readingsSingleUpdate($hash,"state","unreachable", 1); readingsSingleUpdate($hash,"state","unreachable", 1);