This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I Send Integer Value of UINT16 Type to BLE Device Using Nordic BLE Android Library?

Hi All,

I have arduino ble 33 ble device and able to connect with it using my android application using BLE library. I am trying to write 9000 or 18000 of UINT16 by converting it to byte using Data.opCode(byte, byte) method but on BLE device getting 8978 or 17938. Please suggest which method or way i can write the value to receive the same on BLE device. I have seen that we in BLE library we have three methods available for writing values i.e.

  • writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic, @Nullable final Data data)
  • writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic, @Nullable final byte[] data)
  • writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic, @Nullable final byte[] data, final int offset, final int length)
I am using 1st method for writing value using this function but unable to get the expected result:

byte bType = (byte)Data.FORMAT_UINT16;

byte bVal = (byte)((val >> 8) & 0xFF);
where bVal = 9000 or 18000

Please suggest !!

Related