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

Temperature display below freezing #2

Closed
musimasami opened this issue Feb 10, 2020 · 5 comments
Closed

Temperature display below freezing #2

musimasami opened this issue Feb 10, 2020 · 5 comments

Comments

@musimasami
Copy link

When I got temperature from switchbot advertising data.
I got the following data. for example, -127.9 deg C it may be -0.1 deg C
( 0 - 128 ) + 1 / 10 = -127.9
Currently, I arrange code. and check it.

I'm not familiar with English. I add some Japanese comments.
氷点下の温度表示がおかしくなるようです。コードを見ると、氷点下では補数のデータ出力を
期待しているようですが、符号とデータを分けて掛け算する必要がありそうです。
コードを修正して確認中です。

@musimasami
Copy link
Author

I changed switchbot-advertising.js as below.
Yesterday, I changed. but I don't have below freezing data yet.

_parseServiceDataForWoSensorTH(buf) {
let byte2 = buf.readUInt8(2);
let byte3 = buf.readUInt8(3);
let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);
let temp_sign = 1; //Changed
if ((byte4 & 0x80) == 0x80){temp_sign = 1} //Changed
else{temp_sign = -1} //Changed
// let temp_c = (byte4 - 128) + (byte3 / 10);
let temp_c = temp_sign * ((byte4 & 0x7F) + (byte3 / 10)); //Changed
let temp_f = (temp_c * 9 / 5) + 32;
temp_f = Math.round(temp_f * 10) / 10;
let data = {
model: 'T',
modelName: 'WoSensorTH',
temperature: {
c: temp_c,
f: temp_f
},
fahrenheit: (byte5 & 0b10000000) ? true : false,
humidity: byte5 & 0b01111111,
battery: (byte2 & 0b01111111)
};

return data;

}
}

Below in Japanese.
昨日変更して、観測継続中です。しかし、今日(2020/02/10)は氷点下になりませんでした。

@futomi
Copy link
Collaborator

futomi commented Feb 10, 2020

Thank you so much for your code. It's really helpful. I'll try the code too. I hope it'll get cold tonight :)

[Japanese translation]
コード、ありがとうございます。とても参考になります。今晩私も試してみますね。今晩は冷えると良いですね :)

@musimasami
Copy link
Author

I send you current data in graph plot. Data of this graph I change data by modified algorithm.
It seems natural. 2020/02/07 was 1st below freezing day in this season.
Below in Japanese
こちらも、継続して観測中です。最近のグラププロトを添付します。
グラフはRで記述。
MyHomeTemp

@futomi
Copy link
Collaborator

futomi commented Feb 10, 2020

Thank you for testing your code. I tested the updated code too. Fortunately, the temperature dropped to -1.2 degrees in my town. It worked well.

I published the latest version. I tweaked your code so that it is easy to read for me.

Thank you again.

@futomi futomi closed this as completed Feb 10, 2020
@musimasami
Copy link
Author

Thank you for your works.

Additional comments in Japanese
・条件演算子を学びました。ありがとうございます。
・R で Plotlyを使ってみました。が、次は Node.jsでPlotlyを使ってみようと思います。

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

2 participants