2

I am running a custom service with custom characteristics on a BLE 4.2 device. I am working on an android app to read/write the characteristics etc. The first thing I try is to read the characteristics.

I define a list of UUIDs: List chars = new ArrayList<>();

I create a service using my know service UUID: mCustomService = mBluetoothGatt.getService(MY_SERVICE_UUID);

I load the List with 4 know UUIDs from my service:

chars.clear();
chars.add(UUID1);
chars.add(UUID2);
chars.add(UUID3);
chars.add(UUID4);

I read the first characteristic from the end of my list:
BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(chars.get(chars.size() - 1));
    if(mReadCharacteristic != null)
         mBluetoothGatt.readCharacteristic(mReadCharacteristic);

mReadCharacteristic always returns null, the service does not contain my characteristics.

If I use a BLE "sniffer" app then I do see all the characteristics.

Thanks

Rich

PS I cannot figure out the formatting here!

rich
  • 39
  • 2

1 Answers1

0

I have a similar set up - a device with a custom service and characteristics - although the device is BLE 4.0. In your App, perhaps you are doing this but don't mention it in the question - but are you calling

mBluetoothGatt.discoverServices();

That then triggers the callback onServicesDiscovered. I have similar code to yours inside the onServicesDiscovered handler, and it works fine.

public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // getService // getCharactistics } // etc. }

Kirk Bates
  • 101
  • 2
  • 3