I'm sending a water depth in mm to my NodeRed server where I'm currently attempting to reconstruct a 16-bit Int that has been split into 8 high bits and 8 low bits.
I've tried just storing the high bits in a var and shifting them left 8 spaces and then adding the low bits to the variable by OR'ing the two but I've had no success.
I saw somewhere someone suggested trying this
var _firstNumber = (((number8Bit2 & 0xff) << 8) | (number8Bit1 & 0xff));
Any suggestions friends?
Here is the node red function
msg1 = {};
msg2 = {};
var buf1 = msg.payload.slice(0,1);
var buf2 = msg.payload.slice(1, 2);
var lvl = (((buf2 & 0xff) << 8) | (buf1 & 0xff));
var buf3 = msg.payload.slice(2,3);
var batt = buf3.readUInt8();
batt = (batt + 127)/100;
msg1.payload = lvl;
msg1.topic = 'waterlevel';
msg2.payload = batt;
msg2.topic = 'battery';
return [msg1, msg2];