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

BleManager simply cancels connection to nRF52 device

Hi,

I am trying to use the Android-BLE-Library with my nRF52832 device (I do have another test Android app which can work w/o using the library).

I followed the Github readme document and use the following code to connect to my nRF device:

Log.d(TAG, "+MyDevice()");
mMgr = new MyBleManager(ctx);
mMgr.setGattCallbacks(this);
mMgr.connect(BluetoothAdapter.getDefaultAdapter().getRemoteDevice(addr)).timeout(30000).enqueue();
Log.d(TAG, "-MyDevice()");

However, it never works and the log reads like a simple timeout:

01-23 09:19:33.478 32040 32040 V MyBleManager: Connecting...
01-23 09:19:33.478 32040 32040 D MyBleManager: gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)
01-23 09:20:03.474 32040 32040 V MyBleManager: Cancelling connection...
01-23 09:20:03.474 32040 32040 D MyBleManager: gatt.disconnect()
01-23 09:20:03.477 32040 32040 I MyBleManager: Disconnected

MyBleManager is defined as 

class MyBleManager extends BleManager<BleManagerCallbacks> {

   public MyBleManager(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    protected synchronized BleManagerGattCallback getGattCallback() {
        if (null == mGattCallback) {
            mGattCallback = new BleManagerGattCallback() {
                @Override
                protected boolean isRequiredServiceSupported(@NonNull BluetoothGatt gatt) {
                    return true;
                }

                @Override
                protected void onDeviceDisconnected() {
                    // Device disconnected. Release your references here.
                    Log.d(TAG, "+onDeviceDisconnected()");
                }
            };
        }
        return mGattCallback;
    }
    
    @Override
    public void log(final int priority, @NonNull final String message) {
        // Please, don't log in production.
        if (BuildConfig.DEBUG || priority == Log.ERROR) Log.println(priority, TAG, message);
    }
    
}    

I am wondering if the BleManager has more log to reveal the cause?

I am using 2.1.1 version of the library.

Related