new devel Version

This commit is contained in:
Marko Oldenburg 2017-09-29 07:51:43 +02:00
parent b272a0cd7c
commit 4f946d3481

View File

@ -51,9 +51,9 @@ sub XiaomiFlowerSens_stateRequestTimer($);
sub XiaomiFlowerSens_Set($$@);
sub XiaomiFlowerSens_Run($);
sub XiaomiFlowerSens_BlockingRun($);
sub XiaomiFlowerSens_gattSensorData($);
sub XiaomiFlowerSens_gattBatFwData($);
sub XiaomiFlowerSens_forDone_encodeJSON(@);
sub XiaomiFlowerSens_callGatttool($@);
sub XiaomiFlowerSens_forRun_encodeJSON($$);
sub XiaomiFlowerSens_forDone_encodeJSON($$$$$$);
sub XiaomiFlowerSens_BlockingDone($);
sub XiaomiFlowerSens_BlockingAborted($);
@ -262,34 +262,36 @@ sub XiaomiFlowerSens_Set($$@) {
sub XiaomiFlowerSens_Run($) {
my $hash = shift;
my ( $hash, $cmd ) = @_;
my $name = $hash->{NAME};
my $mac = $hash->{BTMAC};
my $wfr;
if( ReadingsVal($name, 'firmware', '') eq "2.6.2" ) {
$wfr = 0;
} else {
$wfr = 1;
}
$hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiFlowerSens_BlockingRun", $name, "XiaomiFlowerSens_BlockingDone", 30, "XiaomiFlowerSens_BlockingAborted", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
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", "read data", 1 ) if( ReadingsVal($name, "state", 0) eq "active" );
readingsSingleUpdate ( $hash, "state", "call data", 1 ) if( ReadingsVal($name, "state", 0) eq "active" );
}
sub XiaomiFlowerSens_BlockingRun($) {
my $name = shift;
my ($string) = @_;
my ($name,$data) = split("\\|", $string);
my $data_json = decode_json($data);
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 {
$wfr = 1;
}
my $mac = $data_json->{mac};
my $wfr = $data_json->{wfr};
Log3 $name, 4, "Sub XiaomiFlowerSens_BlockingRun ($name) - Running nonBlocking";
@ -297,7 +299,7 @@ sub XiaomiFlowerSens_BlockingRun($) {
##### call sensor data
my ($sensData,$batFwData) = XiaomiFlowerSens_callGatttool($name);
my ($sensData,$batFwData) = XiaomiFlowerSens_callGatttool($name,$mac,$wfr);
Log3 $name, 4, "Sub XiaomiFlowerSens_BlockingRun ($name) - Processing response data: $sensData";
@ -350,14 +352,18 @@ sub XiaomiFlowerSens_BlockingRun($) {
return "$name|$response_encode";
}
sub XiaomiFlowerSens_gattSensorData($) {
sub XiaomiFlowerSens_callGatttool($@) {
my $name = shift;
my ($name,$mac,$wfr) = @_;
my $hci = AttrVal($name,"hciDevice","hci0");
my $loop;
my $wresp;
my $sshHost = AttrVal($name,"sshHost","none");
my @readSensData;
my @readBatFwData;
$loop = 0;
if( $sshHost ne 'none') {
@ -377,8 +383,9 @@ sub XiaomiFlowerSens_gattSensorData($) {
$loop++;
}
}
#### Read Sensor Data
## support for Firmware 2.6.6, man muß erst einen Characterwert schreiben
@ -414,12 +421,12 @@ sub XiaomiFlowerSens_gattSensorData($) {
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) - read data from host $sshHost";
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call 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) - read data from local host";
Log3 $name, 4, "Sub XiaomiFlowerSens_callGatttool ($name) - call data from local host";
}
$loop++;
@ -432,18 +439,8 @@ sub XiaomiFlowerSens_gattSensorData($) {
return ($readSensData[1],undef)
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 {
@ -468,13 +465,27 @@ sub XiaomiFlowerSens_gattBatFwData($) {
return ($readBatFwData[1],undef)
unless( $readBatFwData[0] =~ /^Characteristic value\/descriptor$/ );
### no Error in data string
return $readBatFwData[1];
return ($readSensData[1],$readBatFwData[1])
}
sub XiaomiFlowerSens_forDone_encodeJSON(@) {
sub XiaomiFlowerSens_forRun_encodeJSON($$) {
my ($mac,$wfr) = @_;
my %data = (
'mac' => $mac,
'wfr' => $wfr
);
return encode_json \%data;
}
sub XiaomiFlowerSens_forDone_encodeJSON($$$$$$) {
my ($temp,$lux,$moisture,$fertility,$blevel,$fw) = @_;
@ -539,7 +550,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 "read 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 "call data" or ReadingsVal($name,"state", 0) eq "unreachable" or ReadingsVal($name,"state", 0) eq "corrupted data" );
readingsEndUpdate($hash,1);