question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

discoverServices() returning null service?

See original GitHub issue

Hi. I’m facing with discoverServices() error.

BLE logs below. Just tell if You need something more… Or what is wrong in this code?

final Subscription subscription = bleDevice.establishConnection(false)
                .takeUntil(disconnectTriggerSubject)
                .flatMap(new Func1<RxBleConnection, Observable<RxBleDeviceServices>>() {
                    @Override
                    public Observable<RxBleDeviceServices> call(RxBleConnection rxBleConnection) {
                        Log.d(TAG, "BLE connection to " + bleMac + " done!");*

                    // Add this connection to a map for later use
                    connectionMap.put(bleMac, rxBleConnection);

                    return rxBleConnection.discoverServices();
                }
            })
            .map(new Func1<RxBleDeviceServices, ConnectedDevice>() {
                @Override
                public ConnectedDevice call(RxBleDeviceServices rxBleDeviceServices) {
                    Log.d(TAG, "Got service BLE from " + bleMac);

                    BluetoothGattService ngService = null;
                    for (BluetoothGattService service : rxBleDeviceServices.getBluetoothGattServices()) {
                        Log.e(TAG, "ngServices UUID: " + service.getUuid());
                        Log.e(TAG, "ngServices Instance Id: " + service.getInstanceId());
                        if (NG_SERVICE_UUID.equals(service.getUuid())) {
                            ngService = service;
                            break;
                        }
                    }

                    // If there are no proper service, just throw an error
                    if (ngService == null) {
                        throw new IllegalArgumentException("Connected device not a proper ng device");
                    }

BLE LOGS:

E/BleManager: isConnected: RxBleConnectionState{DISCONNECTED}
D/BluetoothGatt: connect() - device: E5:07:96:5E:94:CD, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=04b2518b-01e4-4160-9296-461bfea33036
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=14
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=14 device=E5:07:96:5E:94:CD
D/BleManager: BLE connection to E5:07:96:5E:94:CD done!
D/BluetoothGatt: discoverServices() - device: E5:07:96:5E:94:CD
D/BluetoothGatt: onSearchComplete() = Device=E5:07:96:5E:94:CD Status=0
D/BleManager: Got service BLE from E5:07:96:5E:94:CD
E/BleManager: Connected device not a proper ng device

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, Jul 7, 2017

But you can check on the device that does not exhibit the bug if a Generic Attribute Service is discovered.

0reactions
dariuszseweryncommented, Mar 12, 2019

Never seen this behaviour

Read more comments on GitHub >

github_iconTop Results From Across the Web

discoverServices() returning null service? · Issue #242 - GitHub
Hi. I'm facing with discoverServices() error. BLE logs below. Just tell if You need something more.. Or what is wrong in this code ......
Read more >
BluetoothGatt.discoverServices() returns null - Stack Overflow
I'm using Android studio to make a simple app, that connects to a ble device and reveives data from it. Already checked the...
Read more >
src/com/android/bluetooth/gatt/GattService.java - Google Git
if (service == null) return new ArrayList<BluetoothDevice>();. return service. ... Log.e(TAG, "discoverServices() - No connection for " + address + "..."); }.
Read more >
BluetoothGatt - Android Developers
GATT write operation is not permitted ... public boolean discoverServices () ... or null if the requested service is not offered by the...
Read more >
QLowEnergyController Class | Qt Bluetooth 6.4.1
This process is started via discoverServices() and has finished once the ... This function returns a null pointer if no service with serviceUuid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found