ok I am trying to decode…I have made a few changes but should be the same.
Heading = (roundf ( dH * 100.00));
Pitch = (roundf (dP * 100.00));
Roll = (roundf (dR * 100.00));
unsigned char *puc;
puc = (unsigned char *)(&Heading);
appDataSize = 14;
appData[0] = puc[0];
appData[1] = puc[1];
appData[2] = puc[2];
appData[3] = puc[3];
puc = (unsigned char *)(&Pitch);
appData[4] = puc[0];
appData[5] = puc[1];
appData[6] = puc[2];
appData[7] = puc[3];
puc = (unsigned char *)(&Roll);
appData[8] = puc[0];
appData[9] = puc[1];
appData[10] = puc[2];
appData[11] = puc[3];
appData[12] = (uint8_t)(batteryVoltage >> 8);
appData[13] = (uint8_t)batteryVoltage;
And using the decoder as
function bytesToFloat(by) {
var bits = by[3]<<24 | by[2]<<16 | by[1]<<8 | by[0];
var sign = (bits>>>31 === 0) ? 1.0 : -1.0;
var e = bits>>>23 & 0xff;
var m = (e === 0) ? (bits & 0x7fffff)<<1 : (bits & 0x7fffff) | 0x800000;
var f = sign * m * Math.pow(2, e - 150);
return f;
}
function Decoder(bytes, port) {
var decoded = {};
i = 0;
decoded.Heading= bytesToFloat(bytes.slice(i,i+=4))/100;
decoded.Pitch= bytesToFloat(bytes.slice(i,i+=4))/100;
decoded.Roll= bytesToFloat(bytes.slice(i,i+=4))/100;
decoded.battery = ((bytes[i++] << 8) | bytes[i++]);
return decoded;
}
i get
"payload": "AACcxACgucQAoLlEEHw=",
"payload_size": 14,
as a paylod but the output is “Payload input could not be validly parsed” when I try to decode.