1

Currently developing an android app to connect with a ble custom service. Scanning is working properly, but now i cant read the characteristics from a service. Im using a PSoC development board. Made a custom service with multiple characteristics, and debugged with the program CySmart, with everything working.

    @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status){
            if (status == BluetoothGatt.GATT_SUCCESS)
            {

                List<BluetoothGattService> gattServices =   mBluetoothGatt.getServices();
                Log.e("onServicesDiscovered", "Services count: "+gattServices.size());

                for (BluetoothGattService gattService : gattServices) {
                    String serviceUUID = gattService.getUuid().toString();
                    Log.e("onServicesDiscovered", "Service uuid "+serviceUUID);
                }

                BluetoothGattService gattService = mBluetoothGatt.getService(UUID.fromString(ServiceUUID));
                if (gattService == null)
                {
                    Log.i("BLEtest", "gattservice null");
                    return; // return if the service is not supported
                }
                Characteristic1 = gattService.getCharacteristic(UUID.fromString(Char1UUID));
                Characteristic2 = gattService.getCharacteristic(UUID.fromString(Char2UUID));

            }
            broadcastUpdate(ACTION_SERVICES_DISCOVERED);
        }

Now in the android app, when discovering services after connecting to the GATT server, mBluetoothGatt.getServices() returns null when trying to discover the services with the UUIDs i implemented in the custom service. After this happened, i added the part of the code that returns all services discovered, not using any UUID. The result is 3 UUIDs, that are not the same as the ones i implemented.

02-18 02:33:29.366 19755-19767/jafs.app E/onServicesDiscovered: Services count: 3
02-18 02:33:29.366 19755-19767/jafs.app E/onServicesDiscovered: Service uuid 00001800-0000-1000-8000-00805f9b34fb
02-18 02:33:29.367 19755-19767/jafs.app E/onServicesDiscovered: Service uuid 00001801-0000-1000-8000-00805f9b34fb
02-18 02:33:29.367 19755-19767/jafs.app E/onServicesDiscovered: Service uuid 88117a52-cce5-40de-a40c-1984a342ea00
02-18 02:33:29.367 19755-19767/jafs.app I/BLEtest: gattservice null

The UUIDs that are on the custom service i implemented are different. Already generated different UUIDs in the custom service, but it still returns the same ones. I think the first 2 UUIDs are the ones initially by default when making the custom BLE service, but i eventually changed. Somehow the 3rd one is not like the others.

Any help is valuable!

  • It sounds like this may be relevant: https://stackoverflow.com/questions/22596951/how-to-programmatically-force-bluetooth-low-energy-service-discovery-on-android – stkent Feb 18 '19 at 03:12
  • 1
    @stkent Thanks man! That indirectly solved my problem by giving me an idea. Just needed to uninstall the app from my smartphone, instead of running the new app from android studio with the last one still installed. – José Salgado Feb 18 '19 at 04:01

0 Answers0