Closed danielfaust closed 6 years ago
Nop, I didn't test it. I'll try it in our refrigerator.
Here is the code I'm using to work around this issue.
As I'm sending the data over BLE to an Android phone and the USB port of the ESP32 NodeMCU broke off (I'm using the library with that), making an on-device correction somewhat more laborious, i fixed it in the app which receives the data.
Before sending it to the phone I multiply with 100 and then cast to int, that makes the BLE decoding somewhat easier.
In the app I'm using the following to correct the issue:
int iTemp = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT32, 4);
if (iTemp < 0) {
iTemp = -iTemp - 327700;
}
float fTemp = iTemp / 100.0;
Hi, solution si:
if (ptemperature) {
if ( (temperature & 0x8000 )) {
*ptemperature = (float) (temperature & 0x7FFF)/ -10.0;
} else {
*ptemperature = (float) temperature / 10.0;
}
}
in function SimpleDHT22::read2 and I changed all datatype short to uint16_t but datatype is may not a reason of problem.
Could u please file a PullRequest?
I will look into it
BTW, using a compressed gas duster (holding it upside down) can give you temps below the freezing point very quickly, then you can heat it up again with the fingers.
Merged
Please fix it for DHT11.
I don't have a DHT11 to test with. But since the DHT11 only works with temperatures equal to or above 0 °C, I think that sign flag never gets set. I preferred not to touch that code.
👌
Unfortunately still not displayed correctly :/
@mapmelad on what device are you running it? For me this works on an ESP32, maybe this is device dependent? When you use a previous commit, what does it show?
First, I obtained the values of the similarity -3277.0°C. I used the fix:
if (ptemperature) {
if ( (temperature & 0x8000 )) {
*ptemperature = (float) (temperature & 0x7FFF)/ -10.0;
} else {
*ptemperature = (float) temperature / 10.0;
}
}
Then, after the fix I started getting the values 255, 254 and so on
If I delete in the code the minus sign *ptemperature = (float) (temperature & 0x7FFF)/ 10.0;
, it displays the temperature correctly, but there is no minus sign in the output.
Maybe this is due to the ArduinoBT -- which you're apparently using, judging from the screenshot -- being an 8 bit mcu while the ESP32 has a 32 bit cpu.
Should we reopen this issue? @danielfaust
Please test 1.0.9
I put DHT11 into refrigerator, its data is:
Sample DHT11 with RAW bits...
Sample RAW Bits: 0010 1100 0000 0000 0000 0001 0000 0000 0010 1101
Sample OK: 1 *C, 44 H
Always above 0C.
For DHT22:
Sample DHT22 with RAW bits...
Sample RAW Bits: 0000 0011 1110 0111 1000 0000 0101 1010 1100 0100
Sample OK: -9.00 *C, 99.90 RH%
Sample DHT22 with RAW bits...
Sample RAW Bits: 0000 0010 1101 1101 1000 0000 1000 1000 1110 0111
Sample OK: -13.60 *C, 73.30 RH%
Have you tested this library with negative temperatures?
With a DHT22 I'm getting values like -3276.3°C for values slightly below 0°C (possibly for -0.7°C).
-3277.0°C is not reached, that one is then 0.0°C