I am creating an app and have data coming in the function onCharacteristicChanged. The data I am getting is byte[]. I need to be able to take the data type and be able to have float numbers which are sent via Bluetooth to the app.
Here is the code:
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic);
byte[] value = characteristic.getValue();
Log.i(TAG, "" + value);
}
The values I am receiving are:
[B@37719f8
[B@16fced1
[B@444ed36
The byte array length is 2.
I tried using:
float foo = ByteBuffer.wrap(value).order(ByteOrder.LITTLE_ENDIAN).getFloat();
but I get a BufferUnderflowException.
I also tried:
int intBits = value[0] << 16 | (value[1] & 0xFF);
Float.intBitsToFloat(intBits);
but am not getting the right values.
Can anyone please help me? I need to convert from byte array to float values and byte[] value has a length of 2. I am new to android apps. Thanks