ParseTemperature(Data[4]); // Data byte 4 (starting at 0, where byte 0 contains the command)
function ParseTemperature(Value: Byte): Double;
begin
Result := Value;
if Result >= $80 then
Result := ($FF - Result + 1) * -1;
Result := Result / 2;
end;
Well, looking at table on VMB1TS protocol… there are 2 BYTES for temperature.
DATABYTE 1
DATABYTE 2 (seems to give resolution on 3 left bits, 5 right bits are always zero).
I was frustrated because I wasn’t able to use the low byte precision of temperature.
Today, I’ve worked a lot to understand, and now, I’m able to get temperature value with 1/10°C.
Here is my JavaScript code :
function TempCurrentCalculation(msg) {
// E6 (Transmit Temp) or EA (Sensor status)
switch (msg[4]) {
case 0xE6:
return msg[5]/2 - Math.round(((4-msg[6])>>5)*0.0625*10)/10
case 0xEA:
return msg[8]/2 - Math.round(((4-msg[9])>>5)*0.0625*10)/10
default:
console.error("ERROR with TempCalculation",msg)
return undefined
}
}
In fact, the low byte gives values from -0.25 to +0.25 step 0.0625: the real operation is ((4-msg[9])>>5)*0.0625
It works for me, I hope to not commit mistake.
For those who want an example, the following code show what happens when HighTemp byte change (50 to 51 give a temperature with 25°C to 25.5°C) while LowTemp byte covers almost all other decimal values.
for (let t=0 ; t<8 ; t++) {
r = 25 - Math.round(((4-t))*0.0625*10)/10
console.log(r,"°c")
}
for (let t=0 ; t<8 ; t++) {
r = 25.5 - Math.round(((4-t))*0.0625*10)/10
console.log(r,"°c")
}
Then, the result (some redundancy caused by rounded number):
(from my point of view, it’s unnecessary to use more than one decimal number)