From daf4c86055984d0978c1992b5441e2e635aacb32 Mon Sep 17 00:00:00 2001 From: Arne Glaser Date: Mon, 1 Feb 2021 13:27:39 +0100 Subject: [PATCH 1/2] new temperature deserialistation for DHT22 --- DHT.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index b364612..eea4151 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -109,11 +109,8 @@ float DHT::readTemperature(bool S, bool force) { break; case DHT22: case DHT21: - f = ((word)(data[2] & 0x7F)) << 8 | data[3]; - f *= 0.1; - if (data[2] & 0x80) { - f *= -1; - } + int16_t t = ((int16_t)data[2] << 8) | data[3]; + f = t * 0.1; if (S) { f = convertCtoF(f); } From d2164b66b77f7ab7583ebeba2e0dbd44f8efb9ec Mon Sep 17 00:00:00 2001 From: Arne Glaser Date: Wed, 17 Feb 2021 09:25:18 +0100 Subject: [PATCH 2/2] catch minus zero deg on DHT22 --- DHT.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DHT.cpp b/DHT.cpp index eea4151..6c95edf 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -110,7 +110,10 @@ float DHT::readTemperature(bool S, bool force) { case DHT22: case DHT21: int16_t t = ((int16_t)data[2] << 8) | data[3]; - f = t * 0.1; + if(data[2] == 0x80) + f = 0; + else + f = t * 0.1; if (S) { f = convertCtoF(f); }