From 5fa96ec623519b5f0ea2af8462a921af17017627 Mon Sep 17 00:00:00 2001 From: gernot-h Date: Mon, 7 May 2018 21:10:32 +0000 Subject: [PATCH] 52_I2C_HDC1008.pm: further plausibility check for read values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to datasheet of HDC1008 and HDC1080, least two bits of temp and hum register shall always be "0", so ignore value if we see another value there. This seems to finally eliminate sporadic readings of 125°C and/or 100% rH. git-svn-id: https://svn.fhem.de/fhem/trunk@16705 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/52_I2C_HDC1008.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fhem/FHEM/52_I2C_HDC1008.pm b/fhem/FHEM/52_I2C_HDC1008.pm index ab7aeb8bb..14ec5b0ae 100644 --- a/fhem/FHEM/52_I2C_HDC1008.pm +++ b/fhem/FHEM/52_I2C_HDC1008.pm @@ -192,6 +192,10 @@ sub I2C_HDC1008_GetTemp ($$) my @raw = split(" ",$rawdata); my $tempWord = ($raw[0] << 8 | $raw[1]); + if ( ($tempWord & 0x3) != 0 ) { + Log3 $hash, 4, "[$name] I2C_HDC1008_I2CRec invalid temperature raw value: $tempWord"; + return undef; + } my $temperature = (($tempWord /65536.0)*165.0)-40.0; @@ -210,7 +214,11 @@ sub I2C_HDC1008_GetHum ($$) my @raw = split(" ",$rawdata); my $humWord = ($raw[2] << 8 | $raw[3]); - + if ( ($humWord & 0x3) != 0) { + Log3 $hash, 4, "[$name] I2C_HDC1008_I2CRec invalid humidity raw value: $humWord"; + return undef; + } + my $humidity = ($humWord /65536.0)*100.0; Log3 $hash, 5, "[$name] I2C_HDC1008_I2CRec calced humidity: $humidity";