I can send 4 bytes data to my javascript,
var data = new Uint8Array(data);
console.log('Data received: [ (data[0]) +', ' + (data[1]) +', ' + (data[2]) + ', ' + (data[3]) + ']');
console.log('Data received: [ d2h(data[0]) +', ' + d2h(data[1]) +', ' + d2h(data[2]) + ', ' + d2h(data[3]) + ']');
var hexvalue = ((d2h(data[4]) << 24) | (d2h(data[3]) << 16) | (d2h(data[2]) << 8) | d2h(data[1]));
value = parseFloat(hexvalue);
console.log(value);
In my LOG, I see this
LOG: Data received: [77, 249, 144, 66]
LOG: Data received: [4d, f9, 90, 42]
LOG: 710541312
I expected to get 72.49.. What did I do wrong?
parseFloat()is for parsing a string representation of a floating-point value. Also why does your log message show 6 values in the square brackets when you only have 4 in the code?varthere, when you already use it as argument.