From dc8e7c8b7e98867eb1a9095489c34fb63e8f6b54 Mon Sep 17 00:00:00 2001
From: Marko Oldenburg <leongaultier@gmail.com>
Date: Sun, 11 Feb 2018 00:05:55 +0100
Subject: [PATCH] change timeout for listen and BlackingCall

---
 74_XiaomiBTLESens.pm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/74_XiaomiBTLESens.pm b/74_XiaomiBTLESens.pm
index 665afa6..dd5f93f 100644
--- a/74_XiaomiBTLESens.pm
+++ b/74_XiaomiBTLESens.pm
@@ -409,14 +409,14 @@ sub XiaomiBTLESens_CreateParamGatttool($@) {
     Log3 $name, 4, "XiaomiBTLESens ($name) - Run CreateParamGatttool with mod: $mod";
     
      if( $mod eq 'read' ) {
-        $hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|".$mod."|".$handle, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless( exists($hash->{helper}{RUNNING_PID}) );
+        $hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|".$mod."|".$handle, "XiaomiBTLESens_ExecGatttool_Done", 90, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless( exists($hash->{helper}{RUNNING_PID}) );
         
         readingsSingleUpdate($hash,"state","read sensor data",1);
     
         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."|".$XiaomiModels{AttrVal($name,'model','')}{wdatalisten}, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless( exists($hash->{helper}{RUNNING_PID}) );
+        $hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|".$mod."|".$handle."|".$value."|".$XiaomiModels{AttrVal($name,'model','')}{wdatalisten}, "XiaomiBTLESens_ExecGatttool_Done", 90, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless( exists($hash->{helper}{RUNNING_PID}) );
         
         readingsSingleUpdate($hash,"state","write sensor data",1);
     
@@ -448,7 +448,7 @@ sub XiaomiBTLESens_ExecGatttool_Run($) {
         my $hci                                     = AttrVal($name,"hciDevice","hci0");
         
         $cmd                                        = "ssh $sshHost '" if($sshHost ne 'none');
-        $cmd                                        .= "timeout 5 " if($listen);
+        $cmd                                        .= "timeout 10 " if($listen);
         $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');
@@ -707,6 +707,9 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x10($$) {
     
     Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x10";
     
+    return XiaomiBTLESens_stateRequest($hash)
+    unless($notification =~ /^([0-9a-f]{2}(\s?))*$/);
+    
     my @numberOfHex = split(' ',$notification);
 
     $notification =~ s/\s+//g;