weliem / blessed-android

BLESSED, a Bluetooth Low Energy (BLE) library for Android
MIT License
557 stars 120 forks source link

Connection issue on SDK 22 #55

Closed rauliordache closed 3 years ago

rauliordache commented 4 years ago

Hello,

Due to some problems in 7.0, I have downgraded my tablet to the stock version of Android 5.1 (Lollipop) - SDK 22. I cannot connect to my medical device from SDK-22:

01-05 20:27:08.597 749-779/? D/BluetoothManagerService: Message: 20
01-05 20:27:08.597 749-779/? D/BluetoothManagerService: Added callback: android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@1deabccf:true
01-05 20:27:08.601 6158-6158/com.myapp D/BluetoothAdapter: isEnabled
01-05 20:27:08.602 5922-5960/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:08.602 6158-6158/com.myapp D/BluetoothAdapter: 574927617: getState(). Returning 12
01-05 20:27:08.603 5922-5950/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:08.603 6158-6158/com.myapp D/BluetoothAdapter: 574927617: getState(). Returning 12
01-05 20:27:08.605 5922-5942/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:08.605 6158-6158/com.myapp D/BluetoothAdapter: 574927617: getState(). Returning 12
01-05 20:27:08.615 6158-6179/com.myapp D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=1
01-05 20:27:08.619 6158-6158/com.myapp I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.welie.blessed.BluetoothCentral$2@3990b5a6=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@11c87e3d}
01-05 20:27:08.620 5922-5957/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:08.620 5922-5957/? D/BluetoothAdapter: 644363702: getState(). Returning 12
01-05 20:27:08.621 5922-5957/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:08.621 5922-5957/? D/BluetoothAdapter: 644363702: getState(). Returning 12
01-05 20:27:08.622 5922-5957/? D/BluetoothAdapterService: getAdapterService() - returning com.android.bluetooth.btservice.AdapterService@219c6385
01-05 20:27:08.622 5922-5957/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:08.622 5922-5957/? D/BluetoothAdapter: 644363702: getState(). Returning 12
01-05 20:27:08.623 5922-5957/? I/BtGatt.ScanManager: configureScanFilters: client=com.android.bluetooth.gatt.ScanClient@20
01-05 20:27:08.623 5922-5957/? I/BtGatt.ScanManager: gattClientScanFilterEnableNative(com.android.bluetooth.gatt.ScanClient@20,true);
01-05 20:27:09.040 6158-6158/com.myapp D/BluetoothAdapter: isEnabled
01-05 20:27:09.090 5922-5948/? D/BluetoothRemoteDevices: addDeviceProperties: Remote Address = 34:81:F4:4B:E7:48
01-05 20:27:09.091 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.091 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: bdDevice = 34:81:F4:4B:E7:48
01-05 20:27:09.091 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-05 20:27:09.091 5922-5948/? D/BluetoothRemoteDevices: Send Broadcast: Device Name
01-05 20:27:09.091 749-889/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.NAME_CHANGED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{78cc718 5922:com.android.bluetooth/1002}
01-05 20:27:09.092 5922-5948/? D/BluetoothRemoteDevices: Remote Device name is: BerryMed
01-05 20:27:09.092 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-05 20:27:09.092 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-05 20:27:09.092 5922-5948/? D/BluetoothRemoteDevices: Remote Address is:34:81:F4:4B:E7:48
01-05 20:27:09.093 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-05 20:27:09.093 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-05 20:27:09.093 5922-5948/? D/BluetoothRemoteDevices: Send Broadcast: Device Class
01-05 20:27:09.093 5505-5505/? V/BluetoothEventManager: Received android.bluetooth.device.action.NAME_CHANGED
01-05 20:27:09.094 749-1450/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.CLASS_CHANGED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{78cc718 5922:com.android.bluetooth/1002}
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: Remote class is:0
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: Remote type is:3
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: Remote RSSI is:-56
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-05 20:27:09.095 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.095 5922-5948/? D/BluetoothRemoteDevices: deviceFoundCallback: Remote Address is:34:81:F4:4B:E7:48
01-05 20:27:09.096 5505-5505/? V/BluetoothEventManager: Received android.bluetooth.device.action.CLASS_CHANGED
01-05 20:27:09.096 749-1448/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.FOUND flg=0x10 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{78cc718 5922:com.android.bluetooth/1002}
01-05 20:27:09.098 5505-5505/? V/BluetoothEventManager: Received android.bluetooth.device.action.FOUND
01-05 20:27:09.099 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.099 5505-5505/? D/BluetoothEventManager: Device BerryMed ,Class: 0
01-05 20:27:09.102 5922-5942/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.102 5922-5942/? D/BluetoothRemoteDevices: getAlias: mAlias = null
01-05 20:27:09.102 5505-5505/? D/BluetoothDevice: getAlias: alias = null
01-05 20:27:09.104 5922-5941/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.104 5505-5505/? D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:09.104 5505-5505/? D/BluetoothDevice: getAliasName: name = BerryMed
01-05 20:27:09.104 5505-5505/? D/CachedBluetoothDevice: fetchName, AlaisName is BerryMed
01-05 20:27:09.104 5505-5505/? D/CachedBluetoothDevice: fetchName, Return Name BerryMed
01-05 20:27:09.106 5922-5958/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.106 5505-5505/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-05 20:27:09.106 5505-5505/? D/CachedBluetoothDevice: fetchClass, mBtClass is 0
01-05 20:27:09.107 5922-5960/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.108 5505-5505/? D/CachedBluetoothDevice: Bluetooth device get uuid is null
01-05 20:27:09.108 5505-5505/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.108 5505-5505/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.108 5505-5505/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.108 5505-5505/? D/BluetoothEventManager: DeviceFoundHandler created new CachedBluetoothDevice: 34:81:F4:4B:E7:48
01-05 20:27:09.550 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.554 5922-5950/? D/BluetoothAdapterService(563897221): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@b9637f5
01-05 20:27:09.555 6158-6158/com.myapp D/BluetoothAdapter: 574927617: getState(). Returning 12
01-05 20:27:09.555 6158-6158/com.myapp I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.welie.blessed.BluetoothCentral$2@3990b5a6=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@11c87e3d} ,callback=com.welie.blessed.BluetoothCentral$2@3990b5a6
01-05 20:27:09.558 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.558 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.562 5922-5960/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.563 6158-6158/com.myapp D/BluetoothDevice: getType: type = 3
01-05 20:27:09.563 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.563 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.665 5922-5950/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.666 6158-6158/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:09.666 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.674 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:09.674 6158-6158/com.myapp D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: false
01-05 20:27:09.674 6158-6158/com.myapp D/BluetoothGatt: registerApp()
01-05 20:27:09.674 6158-6158/com.myapp D/BluetoothGatt: registerApp() - UUID=906a8d4c-1666-4316-8b2f-5d7817eb742f
01-05 20:27:09.678 6158-6179/com.myapp D/BluetoothGatt: onClientRegistered() - status=0 clientIf=1
01-05 20:27:09.678 6158-6179/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.194 749-1473/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_CONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{78cc718 5922:com.android.bluetooth/1002}
01-05 20:27:10.192 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.193 5922-5948/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:34:81:F4:4B:E7:48
01-05 20:27:10.198 1259-1259/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.203 1259-1794/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.219 5922-5941/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.220 1259-1794/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-05 20:27:10.224 5922-5960/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.224 1259-1794/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-05 20:27:10.228 5922-5950/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.229 1259-1794/? D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:10.231 5922-5942/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:10.231 5922-5942/? D/BluetoothRemoteDevices: getAlias: mAlias = null
01-05 20:27:10.232 1259-1794/? D/BluetoothDevice: getAlias: alias = null
01-05 20:27:10.235 300-300/? D/[BT][CUST]: 6 : dev=MB Bluetooth, config=0xf71dd0d8
01-05 20:27:16.443 300-300/? D/[BT][CUST]: 6 : dev=MB Bluetooth, config=0xf71dd0d8
01-05 20:27:17.154 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:17.154 5922-5948/? I/BluetoothBondStateMachine: bondStateChangeCallback: Status: 0 Address: 34:81:F4:4B:E7:48 newState: 2
01-05 20:27:17.163 5922-5949/? E/BluetoothBondStateMachine: In stable state, received invalid newState: 12
01-05 20:27:17.169 749-1390/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.NAME_CHANGED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{78cc718 5922:com.android.bluetooth/1002}
01-05 20:27:17.164 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:17.165 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: bdDevice = 34:81:F4:4B:E7:48
01-05 20:27:17.165 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-05 20:27:17.165 5922-5948/? D/BluetoothRemoteDevices: Send Broadcast: Device Name
01-05 20:27:17.172 5505-5505/? V/BluetoothEventManager: Received android.bluetooth.device.action.NAME_CHANGED
01-05 20:27:17.172 5505-5505/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:17.183 5922-5948/? D/BluetoothRemoteDevices: Remote Device name is: BerryMed
01-05 20:27:17.183 5922-5948/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-05 20:27:17.186 5922-5958/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:17.186 5922-5958/? D/BluetoothRemoteDevices: getAlias: mAlias = null
01-05 20:27:17.187 5505-5505/? D/BluetoothDevice: getAlias: alias = null
01-05 20:27:17.195 5922-5941/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:17.196 5505-5505/? D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:17.196 5505-5505/? D/BluetoothDevice: getAliasName: name = BerryMed
01-05 20:27:17.196 5505-5505/? D/CachedBluetoothDevice: fetchName, AlaisName is BerryMed
01-05 20:27:17.196 5505-5505/? D/CachedBluetoothDevice: fetchName, Return Name BerryMed
01-05 20:27:44.704 5922-5950/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.705 6158-6158/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:44.709 5922-5942/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.710 6158-6158/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:44.710 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.710 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.710 6158-6158/com.myapp D/BluetoothGatt: cancelOpen() - device: 34:81:F4:4B:E7:48
01-05 20:27:44.711 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.716 6158-6179/com.myapp D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=1 device=34:81:F4:4B:E7:48
01-05 20:27:44.716 6158-6179/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.719 5922-5941/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.720 6158-6179/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:44.720 6158-6179/com.myapp D/BluetoothGatt: close()
01-05 20:27:44.720 6158-6179/com.myapp D/BluetoothGatt: unregisterApp() - mClientIf=1
01-05 20:27:44.724 6158-6179/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.724 6158-6179/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.724 6158-6179/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.724 6158-6179/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.772 5922-5950/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.773 6158-6158/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:44.773 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.774 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.774 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:44.774 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.736 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.736 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.740 5922-5942/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.740 6158-6158/com.myapp D/BluetoothDevice: getType: type = 3
01-05 20:27:49.740 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.740 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.744 5922-5958/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.745 6158-6158/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-05 20:27:49.746 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.755 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.757 6158-6158/com.myapp D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: true
01-05 20:27:49.758 6158-6158/com.myapp D/BluetoothGatt: registerApp()
01-05 20:27:49.758 6158-6158/com.myapp D/BluetoothGatt: registerApp() - UUID=3744111c-c82a-42ae-9b43-e323e88c3fe4
01-05 20:27:49.760 6158-6180/com.myapp D/BluetoothGatt: onClientRegistered() - status=0 clientIf=1
01-05 20:27:49.760 6158-6180/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.774 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.774 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:49.774 6158-6158/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:51.322 749-1450/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_DISCONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{78cc718 5922:com.android.bluetooth/1002}
01-05 20:27:51.319 5922-5948/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:51.320 5922-5948/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:34:81:F4:4B:E7:48
01-05 20:27:51.325 1259-1259/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-05 20:27:51.326 5922-5922/? D/[MAP]BluetoothMapService: [MapBroadcastReceiver] onReceive
01-05 20:27:51.330 1259-1794/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48

On Android 7.0, I can connect to my device for several seconds, then I got a timeout (the famous - status 8). But, at least, an initial connection is estabilished. I have downgraded to 5.1 because Nougat has several problems regarding BLE connection timeout (hard-coded t - 20 seconds). On Nougat

D/BluetoothDevice: getType: type = 3
D/BluetoothDevice: getName: name = BerryMed
D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: true
    registerApp()
D/BluetoothGatt: registerApp() - UUID=7382b766-e028-4eaa-8999-627a8014eb2c
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=7 device=34:81:F4:4B:E7:48
D/BluetoothDevice: getBondState: state = 12
D/BluetoothDevice: getName: name = BerryMed
D/BluetoothDevice: getName: name = BerryMed
D/BluetoothGatt: discoverServices() - device: 34:81::4B:E7:48
D/BluetoothGatt: onSearchComplete() = Device=34:81:F4:4B:E7:48 Status=0
D/BluetoothDevice: getName: name = BerryMed
D/BluetoothGatt: requestConnectionPriority() - params: 1
D/BluetoothGatt: setCharacteristicNotification() - uuid: 49535343-1e4d-4bd9-ba61-23c647249616 enable: true
D/BluetoothGatt: writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onDescriptorWrite() - Device=34:81:F4:4B:E7:48 handle=56
D/BluetoothGatt: onNotify() - Device=34:81:F4:4B:E7:48 handle=55
D/BluetoothGatt: onNotify() - Device=34:81:F4:4B:E7:48 handle=55
D/BluetoothGatt: onNotify() - Device=34:81:F4:4B:E7:48 handle=55
D/BluetoothGatt: onNotify() - Device=34:81:F4:4B:E7:48 handle=55
D/BluetoothGatt: onNotify() - Device=34:81:F4:4B:E7:48 handle=55
D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=7 device=34:81:F4:4B:E7:48

Can you help me, please, at least with the 5.1(SDK22) version? Thanks.

Later Edit: As I can see, the BluetoothGatt.discoverServices() callback is never reached on Lollipop.

weliem commented 4 years ago

And what does this have to do with the Blessed library? You don't seem to be using it.....

rauliordache commented 4 years ago

I am using it ...

/**
     * Start the module. It starts the parsing thread and also scans & connects to a BerryMed device
     */
    private void start(){

        // Create BluetoothCentral
        central = new BluetoothCentral(context, bluetoothCentralCallback, new Handler());

        // Scan for peripherals with a certain service SSID or MAC
        central.startPairingPopupHack();
        central.scanForPeripheralsWithNames(new String[]{"BerryMed"});
        //central.scanForPeripheralsWithAddresses(new String[]{"34:81:F4:4B:E7:48"});
    }
weliem commented 4 years ago

That's odd, I don't see any logs that Blessed would normally create. Did you include Timber as a dependency in your project?

The second log you post looks normal but in the first one, discoverServices() isn't even called. It seems the connection breaks directly after being connected...

rauliordache commented 4 years ago

I have just included Timber. And also, I have found the issue!
By default, in BLESSED the connection timeout is set to 35s

// Timeout to use if no callback on onConnectionStateChange happens
private static final int CONNECTION_TIMEOUT_IN_MS = 35000; // 35s

Thus, I have the following behavior

01-06 05:26:15.236 30778-30778/? D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: false
01-06 05:26:15.236 30778-30778/? D/BluetoothGatt: registerApp()
01-06 05:26:15.237 30778-30778/? D/BluetoothGatt: registerApp() - UUID=c314b80e-7ed4-42eb-b76e-31374841fcca
01-06 05:26:15.246 30778-30800/? D/BluetoothGatt: onClientRegistered() - status=0 clientIf=1
01-06 05:26:15.246 30778-30800/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-06 05:26:16.242 29556-29908/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-06 05:26:16.242 29556-29908/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:34:81:F4:4B:E7:48
01-06 05:26:16.244 749-1426/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_CONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{ff4fa4f 29556:com.android.bluetooth/1002}
01-06 05:26:16.247 1259-1259/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
[...]
01-06 05:26:50.280 29556-29920/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-06 05:26:50.282 30778-30778/? D/BluetoothDevice: getName: name = BerryMed
[...]

// After exactly 35s from connect(), 
// It is called the timeoutRunnable from [startConnectionTime](https://github.com/weliem/blessed-android/blob/master/blessed/src/main/java/com/welie/blessed/BluetoothPeripheral.java#L1873)(BluetoothPeripheral)
**01-06 05:26:50.283 30778-30778/? E/BluetoothPeripheral: connection timout, disconnecting 'BerryMed'**
01-06 05:26:50.284 30778-30778/? D/BluetoothGatt: close()
01-06 05:26:50.284 30778-30778/? D/BluetoothGatt: unregisterApp() - mClientIf=1
01-06 05:26:50.307 30778-30778/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
[...]
01-06 05:26:55.336 30778-30778/? I/BluetoothPeripheral: autoConnect to 'BerryMed' (34:81:F4:4B:E7:48) using TRANSPORT_LE
01-06 05:26:55.341 30778-30778/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-06 05:26:55.342 30778-30778/? D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: true
01-06 05:26:55.343 30778-30778/? D/BluetoothGatt: registerApp()
01-06 05:26:55.345 30778-30778/? D/BluetoothGatt: registerApp() - UUID=1686954c-a126-4e5e-995f-c33c2074e318
01-06 05:26:55.349 30778-30800/? D/BluetoothGatt: onClientRegistered() - status=0 clientIf=1
01-06 05:26:55.349 30778-30800/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
// And it remains stuck here.

After changing:

// Timeout to use if no callback on onConnectionStateChange happens
private static final int CONNECTION_TIMEOUT_IN_MS = 60000; // 1 min

Everything is ok, BUT the first attempt is always failing (and it is annoying to wait exactly 50 seconds - see below:)

01-07 02:29:11.393 3764-3764/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:11.398 2951-2970/? D/BluetoothAdapterService(912295957): getState() - mAdapterProperties: com.android.bluetooth.btservice.AdapterProperties@35712ef
01-07 02:29:11.398 3764-3764/com.myapp D/BluetoothAdapter: 898304263: getState(). Returning 12
01-07 02:29:11.402 2751-2751/? D/BluetoothDevice: getAlias: alias = null
01-07 02:29:11.403 3764-3764/com.myapp I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.welie.blessed.BluetoothCentral$1@2b5d2a34=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@16452ea3} ,callback=com.welie.blessed.BluetoothCentral$1@2b5d2a34
01-07 02:29:11.410 3764-3764/com.myapp I/BluetoothCentral: scan stopped
01-07 02:29:11.410 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.410 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.413 2951-3007/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.413 2951-2970/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.414 3764-3764/com.myapp D/BluetoothDevice: getType: type = 3
01-07 02:29:11.414 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.421 2751-2751/? D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:11.421 2751-2751/? D/BluetoothDevice: getAliasName: name = BerryMed
01-07 02:29:11.421 2751-2751/? D/CachedBluetoothDevice: fetchName, AlaisName is BerryMed
01-07 02:29:11.421 2751-2751/? D/CachedBluetoothDevice: fetchName, Return Name BerryMed
01-07 02:29:11.421 2751-2751/? V/BluetoothEventManager: Received android.bluetooth.device.action.CLASS_CHANGED
01-07 02:29:11.422 2751-2751/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.423 2951-2971/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.424 2751-2751/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-07 02:29:11.424 2751-2751/? D/CachedBluetoothDevice: fetchClass, mBtClass is 0
01-07 02:29:11.424 2751-2751/? V/BluetoothEventManager: Received android.bluetooth.device.action.FOUND
01-07 02:29:11.424 2751-2751/? D/BluetoothEventManager: Device BerryMed ,Class: 0
01-07 02:29:11.424 2751-2751/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.520 2951-2975/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.521 3764-3764/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:11.521 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.523 3764-3764/com.myapp I/BluetoothPeripheral: connect to 'BerryMed' (34:81:F4:4B:E7:48) using TRANSPORT_LE
01-07 02:29:11.533 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48

// connect() at 02:29:11

01-07 02:29:11.535 3764-3764/com.myapp D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: false
01-07 02:29:11.537 3764-3764/com.myapp D/BluetoothGatt: registerApp()
01-07 02:29:11.537 3764-3764/com.myapp D/BluetoothGatt: registerApp() - UUID=a4be3f2f-9d1d-4f37-8241-af5875908b50
01-07 02:29:11.539 3764-3786/com.myapp D/BluetoothGatt: onClientRegistered() - status=0 clientIf=1
01-07 02:29:11.540 3764-3786/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.974 748-1490/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_CONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{1258d6c4 2951:com.android.bluetooth/1002}
01-07 02:29:11.973 2951-2973/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.973 2951-2973/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:34:81:F4:4B:E7:48
01-07 02:29:11.975 1352-1352/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:11.977 1352-1852/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:12.012 2951-2971/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:12.013 1352-1852/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-07 02:29:12.014 2951-2975/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:12.014 1352-1852/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-07 02:29:12.017 2951-3007/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:12.017 1352-1852/? D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:12.022 2951-2970/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:12.022 2951-2970/? D/BluetoothRemoteDevices: getAlias: mAlias = null
01-07 02:29:12.022 1352-1852/? D/BluetoothDevice: getAlias: alias = null
01-07 02:29:19.026 748-1349/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.NAME_CHANGED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{1258d6c4 2951:com.android.bluetooth/1002}
01-07 02:29:19.014 2951-2973/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:19.014 2951-2973/? I/BluetoothBondStateMachine: bondStateChangeCallback: Status: 0 Address: 34:81:F4:4B:E7:48 newState: 2
01-07 02:29:19.015 2951-2974/? E/BluetoothBondStateMachine: In stable state, received invalid newState: 12
01-07 02:29:19.019 2951-2973/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:19.020 2951-2973/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: bdDevice = 34:81:F4:4B:E7:48
01-07 02:29:19.020 2951-2973/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Acquire Lock - RemoteDevices.mObject
01-07 02:29:19.020 2951-2973/? D/BluetoothRemoteDevices: Send Broadcast: Device Name
01-07 02:29:19.028 2951-2973/? D/BluetoothRemoteDevices: Remote Device name is: BerryMed
01-07 02:29:19.028 2951-2973/? D/BluetoothRemoteDevices: devicePropertyChangedCallback: Release Lock - RemoteDevices.mObject
01-07 02:29:19.040 2751-2751/? V/BluetoothEventManager: Received android.bluetooth.device.action.NAME_CHANGED
01-07 02:29:19.040 2751-2751/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:19.041 2951-2971/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:19.041 2951-2971/? D/BluetoothRemoteDevices: getAlias: mAlias = null
01-07 02:29:19.042 2751-2751/? D/BluetoothDevice: getAlias: alias = null
01-07 02:29:19.043 2951-2975/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:19.044 2751-2751/? D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:19.044 2751-2751/? D/BluetoothDevice: getAliasName: name = BerryMed
01-07 02:29:19.044 2751-2751/? D/CachedBluetoothDevice: fetchName, AlaisName is BerryMed
01-07 02:29:19.044 2751-2751/? D/CachedBluetoothDevice: fetchName, Return Name BerryMed
01-07 02:29:53.104 748-1050/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_DISCONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{1258d6c4 2951:com.android.bluetooth/1002}
01-07 02:29:53.102 2951-2973/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:53.102 2951-2973/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:34:81:F4:4B:E7:48
01-07 02:29:53.110 1352-1352/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:53.110 2951-2951/? D/[MAP]BluetoothMapService: [MapBroadcastReceiver] onReceive
01-07 02:29:53.114 1352-1852/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:53.122 3764-3787/com.myapp D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=1 device=34:81:F4:4B:E7:48
01-07 02:29:53.122 3764-3787/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48

// After 42s ( > 35s) from connect() we get "cancelling connect attempt":

01-07 02:29:53.123 3764-3787/com.myapp I/BluetoothPeripheral: cancelling connect attempt
01-07 02:29:53.123 3764-3787/com.myapp D/BluetoothGatt: close()
01-07 02:29:53.123 3764-3787/com.myapp D/BluetoothGatt: unregisterApp() - mClientIf=1
01-07 02:29:53.127 3764-3787/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:53.127 3764-3787/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.133 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.134 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.137 2951-2975/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.138 3764-3764/com.myapp D/BluetoothDevice: getType: type = 3
01-07 02:29:58.138 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.142 2951-3007/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.143 3764-3764/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:58.143 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:58.144 3764-3764/com.myapp I/BluetoothPeripheral: autoConnect to 'BerryMed' (34:81:F4:4B:E7:48) using TRANSPORT_LE
01-07 02:29:58.147 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48

// The second attempt works.
01-07 02:29:58.148 3764-3764/com.myapp D/BluetoothGatt: connect() - device: 34:81:F4:4B:E7:48, auto: true
01-07 02:29:58.148 3764-3764/com.myapp D/BluetoothGatt: registerApp()
01-07 02:29:58.148 3764-3764/com.myapp D/BluetoothGatt: registerApp() - UUID=d6f892c0-efa1-486f-a88c-056dbe5a95a0
01-07 02:29:58.150 3764-3787/com.myapp D/BluetoothGatt: onClientRegistered() - status=0 clientIf=1
01-07 02:29:58.150 3764-3787/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.460 2951-2973/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.460 2951-2973/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:34:81:F4:4B:E7:48
01-07 02:29:59.466 748-1349/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_CONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{1258d6c4 2951:com.android.bluetooth/1002}
01-07 02:29:59.470 1352-1352/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.480 3764-3786/com.myapp D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=1 device=34:81:F4:4B:E7:48
01-07 02:29:59.480 3764-3786/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.481 2951-2975/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.481 3764-3786/com.myapp D/BluetoothDevice: getBondState: state = 10
01-07 02:29:59.484 2951-3007/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.484 3764-3786/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:59.487 3764-3786/com.myapp I/BluetoothPeripheral: connected to 'BerryMed' (BOND_NONE) in 1.3s
01-07 02:29:59.489 2951-2970/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.489 3764-3764/com.myapp D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:59.489 3764-3764/com.myapp D/BluetoothPeripheral: discovering services of 'BerryMed' with delay of 0 ms
01-07 02:29:59.490 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.490 3764-3764/com.myapp D/BluetoothGatt: discoverServices() - device: 34:81:F4:4B:E7:48
01-07 02:29:59.490 3764-3764/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.491 1352-1852/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.509 2951-2975/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.510 1352-1852/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-07 02:29:59.511 2951-3007/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.512 1352-1852/? D/BluetoothDevice: getBluetoothClass: classInt = 0
01-07 02:29:59.513 2951-2970/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.514 1352-1852/? D/BluetoothDevice: getName: name = BerryMed
01-07 02:29:59.516 2951-2971/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.516 2951-2971/? D/BluetoothRemoteDevices: getAlias: mAlias = null
01-07 02:29:59.516 1352-1852/? D/BluetoothDevice: getAlias: alias = null
01-07 02:30:01.372 3764-3787/com.myapp D/BluetoothGatt: onGetService() - Device=34:81:F4:4B:E7:48 UUID=00001800-0000-1000-8000-00805f9b34fb
01-07 02:30:01.372 3764-3787/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:30:01.378 3764-3786/com.myapp D/BluetoothGatt: onGetService() - Device=34:81:F4:4B:E7:48 UUID=0000180a-0000-1000-8000-00805f9b34fb
01-07 02:30:01.378 3764-3786/com.myapp D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48

// Now everything is okay, after 50s from the first attempt ...

Later edit:

I have tried a trick - setting the timeout to 100 ms private static final int CONNECTION_TIMEOUT_IN_MS = 100;

But it also temporize the connection with 10 seconds (the entire cycle: connect() - forced timeout - autoConnect() cannot be done in less than 10 s)

weliem commented 4 years ago

Hi, ok now we can see better what is happening.

The basically problem I see is that in the first case, the device seems to connect fairly quickly but the bluetooth stack never calls onClientConnectionState(). So you see:

01-06 05:26:16.242 29556-29908/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:34:81:F4:4B:E7:48

But there is no call to onClientConnectionState(). So Blessed doesn't get to know the device actually connected. Hence after 35 seconds the timeout goes off and a disconnect is issued.

In the second case the onClientConnectionState is called normally:

01-07 02:29:59.460 2951-2973/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:34:81:F4:4B:E7:48
01-07 02:29:59.466 748-1349/? V/ActivityManager: Broadcast: Intent { act=android.bluetooth.device.action.ACL_CONNECTED flg=0x4000010 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{1258d6c4 2951:com.android.bluetooth/1002}
01-07 02:29:59.470 1352-1352/? D/BluetoothDevice: mAddress: 34:81:F4:4B:E7:48
01-07 02:29:59.480 3764-3786/com.myapp D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=1 device=34:81:F4:4B:E7:48

So you can tinker with the timeout delay, but that won't solve the root cause. There is something else that is suspicious and that is this part:

01-07 02:29:19.014 2951-2973/? I/BluetoothBondStateMachine: bondStateChangeCallback: Status: 0 Address: 34:81:F4:4B:E7:48 newState: 2
01-07 02:29:19.015 2951-2974/? E/BluetoothBondStateMachine: In stable state, received invalid newState: 12

...which seems to suggest some 'bonding' is taking place, although things are apparently going wrong. State 12 would normally mean that the device is BOND_BONDED. Can you make sure the device has not been paired via the Bluetooth Settings menu? And if it appears there, remove it...

Anyways, strange things are happening and the bluetooth stack is not working as expected....what device are you using?

rauliordache commented 4 years ago

Calling from the first time autoConnect() (instead of connect()) in BluetoothCentral - connectPeripheral(...) is ok. It works (with a little delay of 4-5 s)

https://github.com/weliem/blessed-android/blob/master/blessed/src/main/java/com/welie/blessed/BluetoothCentral.java#L595

// Now connect peripheral.autoConnect(); // instead of peripheral.connect();

I will try to find the issue in peripheral.connect();

weliem commented 4 years ago

Any update on this issue?

rauliordache commented 4 years ago

I am using peripheral.autoConnect() instead of peripheral.connect() (even from the first attempt). I will let you know if I find the issue in .connect().