Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHT_readTemperature for DHT21/DHT22 Temp sensor - wrong negative value #1445

Open
zimmerik opened this issue Nov 30, 2024 · 0 comments
Open

Comments

@zimmerik
Copy link

zimmerik commented Nov 30, 2024

DHT_readTemperature for DHT21/DHT22 Temp sensor - wrong negative values, for negative values only, the first bit is not masked (for negative values & 0x7F) and returns temperature of -3276.7 instead of -0.1

possibly the conversion in src/driver/drv_dht_internal.c is not called from drive_dht.c with correct parameters:

`float DHT_readTemperature(dht_t *dht, bool S, bool force) {
float f = 0;
byte *data;
data = dht->data;

if (DHT_read(dht,force)) {
	switch (dht->_type) {
            .....
            .....
	case DHT22:
	case DHT21:
		f = ((unsigned short)(data[2] & 0x7F)) << 8 | data[3];
		f *= 0.1;
		if (data[2] & 0x80) {
			f *= -1;
		}
		if (S) {
			f = convertCtoF(f);
		}
		break;
	}
}
return f;`

is not performed correctly

when calling this function?

I am observing this issue with
BK7231N
von Beken Corporation
Firmware: 1.17.104

and DHT21/DHT22 temperature sensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant