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
Teknihall: Fix negative temperatures #221
Conversation
Not sure if this is a permanent fix... |
There are similar fixes in other protocols (alecto_ws1700 for example), and I doubt that people will measure temperatures above 80°… But if temperatures go below -22.4, it will be a problem again I guess. |
I know, but we should be able to calculate what the crossover point is. |
How do you propose to do so? |
Getting new values to check when the values are incorrect. We a smaller range to be sure when it happens. |
Hm, at least i can put my sensor in a freezer to check? |
Exactly, then try to reach -15 and let it raise until the pilight recognizes a valid temperature again. If we know that temperature we know when to set the fix. |
The problem is in pilight/libs/pilight/core/binary.c function binToDecRev(). The binary values are 2's complement signed. This function have to handle this or is a secondary function is needed for signed values. The values need a sign expansion as well. Have a look at https://en.wikipedia.org/wiki/Sign_extension. |
Binary is always unsigned. These devices often have a signed bit. Could be that this device also uses a signed bit, but that should be investigated. |
auriol_protocol_v20.pdf page 6: " temperature This 12 bits wide 2's complement signed binary number represents the actual temperature value in 0.1 °C units" Actually pilight is showing 201.8, real value is -2.9. (protocol: alecto_wx500) |
alecto_ws1700.c has already a fix: For auriol.c this would be: |
Ariol is ofc a different topic, but please, if you think you can improve on of our protocols, do a pull request (according to the guidelines). |
Sorry I looked at the wrong file. My sensor uses the file alecto_wx500.c. |
If that so, please do a PR with that fix and let's focus on Teknihall here, |
Has this been confirmed? |
Am 24.05.16 um 20:17 schrieb CurlyMoo:
Kind regards |
Am 24.05.16 um 20:17 schrieb CurlyMoo:
Sorry, for long time no answer. The coldest temp was -15.9, pilight But with the manually compiled version, which pilino1234 posted works I think everthing works fine with this bugfix. |
So at what temperature does pilight show the correct value again when the sensor warms up? |
Without fix, pilight Shows the correct Temp in the Sensor is >0. Von meinem iPhone gesendet
|
What temperature does pilight (without the fix) show at <0, at the highest temperature that gives the wrong value? |
Hm, i think in the Forum of pilight i show all test i did. Von meinem iPhone gesendet
|
Hi! I'm wondering whether we can get this merged or if something is missing? I also have several teknihall receivers and I just got negative temperatures today. In pilight this temperature is wrong though. Real: -0.5 °C Real: -0.1 °C Everything above 0.0 °C was working fine |
@ChristianKreuzberger, can you check if you can get the sensor lower then 20C? |
I got it down to -18.5 °C (83.9 in Pilight). At least now I know the temperature of my freezer. |
The point it that the value 800 doesn't make much sense binary wise. |
Last update: -19.7 °C (82.7 in pilight) if(temperature>800) {
temperature -= 1024;
} rather than a value that someone actually measured: if(temperature > 827) {
temperature -= 1024;
} ? |
Not that it's 800 but that it's not a number you'd expect in binary. I would expect 512 ( |
Let's apply some logic
For negative values, using two's complement works (which is also why subtracing -1024 leads to the correct values). |
What do other think? 768 sounds indeed better. |
Yes, I think this sounds reasonable. I'll update the PR to use 768 as the rollover value. |
d0f8480
to
53670b1
Compare
Seems like my logical explaination isn't convincing enough. To validate my claim I went to the danger zone and tried to literally grill one of my sensor. The highest temperature shown on my stations display was this: The last reading I got from pilight was 75.0 °C (750), binary value: Considering I already got the temperature of the sensor down to -19.7 °C ( For sanity reasons they could have used a more symmetrical representation (e.g., two complement), and have a range of
|
Thanks alot @ChristianKreuzberger! |
So I'll change the implementation to check whether the first two bits are |
Also the description could be possible, it sounds a very inconvenient. If I had a short look to the wiki and the forum (Protocol Development) I really wonder, why should be the temperature from bit 14 to 23? @ChristianKreuzberger can you record and publish the raw code for negative temperatures? |
I will try to record some raw data of negative values, though my experience with that is very limited as I have so much noise on the 433 Mhz band. |
(offtopic: @anx-ckreuzberger https://wiki.pilight.org/doku.php/low-pass_filter helps with that.) |
@pilino1234 thx for the link. I'm not really that much into hardware and doing such things myself. carry = binary[13]; // int
temperature = binToDecRev(binary, 14, 23); // int
if (carry == 1) {
temperature = temperature ^ 0xFFFFFC00; // keep the last 10 bits, set the rest to 1
} is sufficient to get correct values. I guess that now your |
Yep, I can confirm that
@CurlyMoo I guess we can wait on PR #314 to be merged and then (again) change this PR to use |
@ChristianKreuzberger Thanks for testing. Did you checked for positive and negative Temperatures. temperature = binToDecRev(binary, 12, 23);
if (binary[12] == 1) {
temperature -= 4096;
} The binary operation results in the same but is only valid if int is a 32 bit value. Comparing the teknihall and the auriol protocol, they are very similar (timing, bit positions), thought auriol has no humidity. That is why I expect that the temperature value is 12 bit long. |
I did look at bit 12 too, though it was always 0 (as far as I remember). |
Now that #314 is in, should we redo this here or should I just quickly make a new PR for it? |
Try to redo it. |
Fix negative temperatures beign shown as very high values by converting the temperature to a signed value. Discussion: https://forum.pilight.org/Thread-negative-Temperature-for?pid=16687#pid16687
53670b1
to
2f97e6a
Compare
Done |
@@ -77,7 +77,7 @@ static void parseCode(void) { | |||
|
|||
id = binToDecRev(binary, 0, 7); | |||
battery = binary[8]; | |||
temperature = binToDecRev(binary, 14, 23); | |||
temperature = binToSignedRev(binary, 14, 23); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work. As discussed we need to include bit 13: temperature = binToSignedRev(binary, 13, 23);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely agree, this will not work as intended, needs to be temperature = binToSignedRev(binary, 13, 23);
I've simply added signed binToDec(Rev) functions to binary.c:
The function will sign extend a variable bit number in two complement notation to a normal signed int. No more subtraction is needed anymore. It is working well in my build. |
The values were distorted, fixed by checking for unreasonably high value and subtracting 102.4°.
Discussion: https://forum.pilight.org/Thread-negative-Temperature-for?pid=16687#pid16687