For example: Register 020B is sixteen bit number. Let's write it in binary form 0000 0010|0000 1011 Now we can mark 7 groups from the end 00|0000100|0001011 And now we have this number in 7 bit form 00 04 0B
We have received temperature 00 04 38 Let's write 7 bit numbers in binary form 0000000|0000010|0111000 We will mark 8 bit delimiters 00000001|00111000 It is: 138(hex) 312(dec) In that case temperature is 31.2C
We have received temperature 03 7C 1D Let's write 7 bit numbers in binary form 0000011|1111100|0011101 We will mark 8 bit delimiters 11111110|00011101 It is: FE1D(hex) 65053(dec)-483(signed integer) Received temperature is -48.3C
I have succeeded in decoding the values coming from the heat pump with this function but cannot get the reverse to work ie from dec to 7 bit hex.
Code: Select all
var data = Buffer.from(msg.payload);
var decoded_int = (data[1] << 14) + (data[2] << 7) + data[3];
var decoded_buffer = Buffer.from([decoded_int & 0xff, decoded_int >> 8]);
var decoded = decoded_buffer.readInt16LE();
return { "decoded": decoded };