Merge branch 'devel' of https://github.com/LeonGaultier/fhem-XiaomiFlowerMonitor into devel
This commit is contained in:
commit
b272a0cd7c
@ -51,9 +51,9 @@ sub XiaomiFlowerSens_stateRequestTimer($);
|
||||
sub XiaomiFlowerSens_Set($$@);
|
||||
sub XiaomiFlowerSens_Run($);
|
||||
sub XiaomiFlowerSens_BlockingRun($);
|
||||
sub XiaomiFlowerSens_callGatttool($@);
|
||||
sub XiaomiFlowerSens_forRun_encodeJSON($$);
|
||||
sub XiaomiFlowerSens_forDone_encodeJSON($$$$$$);
|
||||
sub XiaomiFlowerSens_gattSensorData($);
|
||||
sub XiaomiFlowerSens_gattBatFwData($);
|
||||
sub XiaomiFlowerSens_forDone_encodeJSON(@);
|
||||
sub XiaomiFlowerSens_BlockingDone($);
|
||||
sub XiaomiFlowerSens_BlockingAborted($);
|
||||
|
||||
@ -262,13 +262,29 @@ sub XiaomiFlowerSens_Set($$@) {
|
||||
|
||||
sub XiaomiFlowerSens_Run($) {
|
||||
|
||||
my ( $hash, $cmd ) = @_;
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
|
||||
$hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiFlowerSens_BlockingRun", $name, "XiaomiFlowerSens_BlockingDone", 30, "XiaomiFlowerSens_BlockingAborted", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_Run ($name) - start blocking call";
|
||||
|
||||
readingsSingleUpdate ( $hash, "state", "read data", 1 ) if( ReadingsVal($name, "state", 0) eq "active" );
|
||||
}
|
||||
|
||||
sub XiaomiFlowerSens_BlockingRun($) {
|
||||
|
||||
my $name = shift;
|
||||
|
||||
my $hci = AttrVal($name,"hciDevice","hci0");
|
||||
my $sshHost = AttrVal($name,"sshHost","none");
|
||||
my $mac = $hash->{BTMAC};
|
||||
my $wresp;
|
||||
my @readSensData;
|
||||
my @readBatFwData;
|
||||
|
||||
my $wfr;
|
||||
|
||||
|
||||
if( ReadingsVal($name, 'firmware', '') eq "2.6.2" ) {
|
||||
$wfr = 0;
|
||||
} else {
|
||||
@ -276,30 +292,12 @@ sub XiaomiFlowerSens_Run($) {
|
||||
}
|
||||
|
||||
|
||||
my $response_encode = XiaomiFlowerSens_forRun_encodeJSON($mac,$wfr);
|
||||
|
||||
$hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiFlowerSens_BlockingRun", $name."|".$response_encode, "XiaomiFlowerSens_BlockingDone", 30, "XiaomiFlowerSens_BlockingAborted", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_Run ($name) - start blocking call";
|
||||
|
||||
readingsSingleUpdate ( $hash, "state", "call data", 1 ) if( ReadingsVal($name, "state", 0) eq "active" );
|
||||
}
|
||||
|
||||
sub XiaomiFlowerSens_BlockingRun($) {
|
||||
|
||||
my ($string) = @_;
|
||||
my ($name,$data) = split("\\|", $string);
|
||||
my $data_json = decode_json($data);
|
||||
|
||||
my $mac = $data_json->{mac};
|
||||
my $wfr = $data_json->{wfr};
|
||||
|
||||
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_BlockingRun ($name) - Running nonBlocking";
|
||||
|
||||
|
||||
##### call sensor data
|
||||
|
||||
my ($sensData,$batFwData) = XiaomiFlowerSens_callGatttool($name,$mac,$wfr);
|
||||
my ($sensData,$batFwData) = XiaomiFlowerSens_callGatttool($name);
|
||||
|
||||
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_BlockingRun ($name) - Processing response data: $sensData";
|
||||
@ -352,16 +350,12 @@ sub XiaomiFlowerSens_BlockingRun($) {
|
||||
return "$name|$response_encode";
|
||||
}
|
||||
|
||||
sub XiaomiFlowerSens_callGatttool($@) {
|
||||
sub XiaomiFlowerSens_gattSensorData($) {
|
||||
|
||||
my ($name,$mac,$wfr) = @_;
|
||||
my $hci = AttrVal($name,"hciDevice","hci0");
|
||||
my $name = shift;
|
||||
|
||||
my $loop;
|
||||
my $wresp;
|
||||
my $sshHost = AttrVal($name,"sshHost","none");
|
||||
my @readSensData;
|
||||
my @readBatFwData;
|
||||
|
||||
|
||||
$loop = 0;
|
||||
@ -385,7 +379,6 @@ sub XiaomiFlowerSens_callGatttool($@) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
#### Read Sensor Data
|
||||
|
||||
## support for Firmware 2.6.6, man muß erst einen Characterwert schreiben
|
||||
@ -421,12 +414,12 @@ sub XiaomiFlowerSens_callGatttool($@) {
|
||||
if( $sshHost ne 'none' ) {
|
||||
|
||||
@readSensData = split(": ",qx(ssh $sshHost 'gatttool -i $hci -b $mac --char-read -a 0x35 2>&1 /dev/null'));
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call data from host $sshHost";
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - read data from host $sshHost";
|
||||
|
||||
} else {
|
||||
|
||||
@readSensData = split(": ",qx(gatttool -i $hci -b $mac --char-read -a 0x35 2>&1 /dev/null));
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call data from local host";
|
||||
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - read data from local host";
|
||||
}
|
||||
|
||||
$loop++;
|
||||
@ -441,6 +434,16 @@ sub XiaomiFlowerSens_callGatttool($@) {
|
||||
unless( $readSensData[0] =~ /^Characteristic value\/descriptor$/ );
|
||||
|
||||
|
||||
### no Error in data string
|
||||
return $readSensData[1];
|
||||
}
|
||||
|
||||
sub XiaomiFlowerSens_gattBatFwData($) {
|
||||
|
||||
my $name = shift;
|
||||
my $loop;
|
||||
|
||||
|
||||
### Read Firmware and Battery Data
|
||||
$loop = 0;
|
||||
do {
|
||||
@ -467,25 +470,11 @@ sub XiaomiFlowerSens_callGatttool($@) {
|
||||
unless( $readBatFwData[0] =~ /^Characteristic value\/descriptor$/ );
|
||||
|
||||
|
||||
|
||||
|
||||
### no Error in data string
|
||||
return ($readSensData[1],$readBatFwData[1])
|
||||
return $readBatFwData[1];
|
||||
}
|
||||
|
||||
sub XiaomiFlowerSens_forRun_encodeJSON($$) {
|
||||
|
||||
my ($mac,$wfr) = @_;
|
||||
|
||||
my %data = (
|
||||
'mac' => $mac,
|
||||
'wfr' => $wfr
|
||||
);
|
||||
|
||||
return encode_json \%data;
|
||||
}
|
||||
|
||||
sub XiaomiFlowerSens_forDone_encodeJSON($$$$$$) {
|
||||
sub XiaomiFlowerSens_forDone_encodeJSON(@) {
|
||||
|
||||
my ($temp,$lux,$moisture,$fertility,$blevel,$fw) = @_;
|
||||
|
||||
@ -550,7 +539,7 @@ sub XiaomiFlowerSens_BlockingDone($) {
|
||||
readingsBulkUpdate($hash, "moisture", $response_json->{moisture});
|
||||
readingsBulkUpdate($hash, "fertility", $response_json->{fertility});
|
||||
readingsBulkUpdate($hash, "firmware", $response_json->{firmware});
|
||||
readingsBulkUpdate($hash, "state", "active") if( ReadingsVal($name,"state", 0) eq "call data" or ReadingsVal($name,"state", 0) eq "unreachable" or ReadingsVal($name,"state", 0) eq "corrupted data" );
|
||||
readingsBulkUpdate($hash, "state", "active") if( ReadingsVal($name,"state", 0) eq "read data" or ReadingsVal($name,"state", 0) eq "unreachable" or ReadingsVal($name,"state", 0) eq "corrupted data" );
|
||||
|
||||
readingsEndUpdate($hash,1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user