I have a problem when I try to use cheaper Android phones to communicate with our NordicSemi nRF52832 chip.
I can discover the peripheral and then connect, but when I device.discoverServices() the software pauses for about 10 seconds, and then disconnects with the output:
D/BluetoothGatt: connect() - device: CA:E7:8F:03:82:CE, auto: false
D/BluetoothGatt: registerApp() D/BluetoothGatt: registerApp() -
UUID=b05b54e9-bd20-423f-a6db-461775f954f0 D/BluetoothGatt:
onClientRegistered() - status=0 clientIf=7 D/BluetoothGatt:
onClientConnectionState() - status=0 clientIf=7
device=CA:E7:8F:03:82:CE D/BluetoothGatt: discoverServices() - device:
CA:E7:8F:03:82:CE D/BluetoothGatt: onSearchComplete() =
Device=CA:E7:8F:03:82:CE Status=129 D/BluetoothGatt:
onClientConnectionState() - status=22 clientIf=7
device=CA:E7:8F:03:82:CE D/BluetoothGatt: cancelOpen() - device:
CA:E7:8F:03:82:CE D/BluetoothGatt: close() D/BluetoothGatt:
unregisterApp() - mClientIf=7 D/BluetoothGatt: cancelOpen() - device:
CA:E7:8F:03:82:CE D/BluetoothGatt: close() D/BluetoothGatt:
unregisterApp() - mClientIf=0
With onServicesDiscovered status = 129
The phones are in this case: Samsung Galaxy J3 (J320FN) & Huawei P8lite (ALE-L21)
Related
I'm working on an application connected to a BLE device, and I'm focused on the firmware update of the device (DFU). For that, I'm using the android lib created by Nordic and I'm trying to make it autonomous, so a user doesn't have to browse his files and pick the zip of the firmware update.
However, the DFU always stops at 30%, the app loses the bluetooth connection and I have to finish the update manually with an external app.
Is there anyone that has already made this kind of thing with DFU and can help me?
Here is a link to the lib's github: https://github.com/NordicSemiconductor/Android-DFU-Library
Here is the code I'm currently using, it's a standard DFU procedure with Nordic lib for Android.
val starter = DfuServiceInitiator(deviceMacAddress!!)
.setDeviceName(deviceName)
.setKeepBond(true)
starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)
starter.setZip(uri)
val controller = starter.start(context!!, DfuService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
DfuServiceInitiator.createDfuNotificationChannel(context!!)
}
Edit: Here are some logs that show what happens on runtime
2019-01-08 10:54:35.481 3394-3394/com.thingsaremoving.enovap E/DfuListener: onDeviceConnected
2019-01-08 10:54:35.481 3394-3394/com.thingsaremoving.enovap E/DfuListener: onDfuProcessStarting
2019-01-08 10:54:36.492 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: setCharacteristicNotification() - uuid: 8ec90003-f315-4f60-9fb8-838830daea50 enable: true
2019-01-08 10:54:41.741 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=11 device=FE:E6:FD:B8:13:DE
2019-01-08 10:54:41.741 3394-3592/com.thingsaremoving.enovap D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=12 device=FE:E6:FD:B8:13:DE
2019-01-08 10:54:41.743 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: close()
2019-01-08 10:54:41.743 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: unregisterApp() - mClientIf=12
2019-01-08 10:54:41.755 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: setCharacteristicNotification() - uuid: 23058a49-636d-82ab-d641-badd3648cc9a enable: false
2019-01-08 10:54:41.755 3394-3598/com.thingsaremoving.enovap D/BluetoothManager: getConnectionState()
2019-01-08 10:54:41.755 3394-3598/com.thingsaremoving.enovap D/BluetoothManager: getConnectedDevices
2019-01-08 10:54:41.756 3394-3698/com.thingsaremoving.enovap D/BluetoothAdapter: isLeEnabled(): ON
2019-01-08 10:54:41.757 3394-3406/com.thingsaremoving.enovap E/Companion: Charac change error Disconnected from FE:E6:FD:B8:13:DE with status 8 (GATT_INSUF_AUTHORIZATION)
2019-01-08 10:54:41.757 3394-3406/com.thingsaremoving.enovap E/BleManager: release()
2019-01-08 10:54:41.758 3394-3406/com.thingsaremoving.enovap I/Companion: onConnectionStateChanged : RxBleConnectionState{DISCONNECTED}
2019-01-08 10:54:41.758 3394-3406/com.thingsaremoving.enovap E/BleManager: release()
2019-01-08 10:54:41.759 3394-3406/com.thingsaremoving.enovap E/bleManager: error characteristic change : Disconnected from FE:E6:FD:B8:13:DE with status 8 (GATT_INSUF_AUTHORIZATION)
2019-01-08 10:54:41.761 3394-3598/com.thingsaremoving.enovap D/BluetoothGatt: close()
2019-01-08 10:54:41.761 3394-3598/com.thingsaremoving.enovap D/BluetoothGatt: unregisterApp() - mClientIf=11
2019-01-08 10:54:41.764 3394-3406/com.thingsaremoving.enovap D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=12 mScannerId=0
2019-01-08 10:54:41.787 3394-3394/com.thingsaremoving.enovap E/ConnectionState: disconnected
2019-01-08 10:54:41.872 3394-3698/com.thingsaremoving.enovap D/BluetoothAdapter: isLeEnabled(): ON
2019-01-08 10:54:43.905 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: connect() - device: FE:E6:FD:B8:13:DF, auto: false
2019-01-08 10:54:43.906 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: registerApp()
2019-01-08 10:54:43.906 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: registerApp() - UUID=766e5e19-e1f9-48d3-a0a0-9c5eeba2b66a
2019-01-08 10:54:43.910 3394-3592/com.thingsaremoving.enovap D/BluetoothGatt: onClientRegistered() - status=0 clientIf=11
2019-01-08 10:54:44.059 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=11 device=FE:E6:FD:B8:13:DF
2019-01-08 10:54:44.060 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: discoverServices() - device: FE:E6:FD:B8:13:DF
2019-01-08 10:54:44.746 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onConnectionUpdated() - Device=FE:E6:FD:B8:13:DF interval=24 latency=0 timeout=400 status=0
2019-01-08 10:54:45.045 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onConnectionUpdated() - Device=FE:E6:FD:B8:13:DF interval=6 latency=0 timeout=500 status=0
2019-01-08 10:54:45.135 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onSearchComplete() = Device=FE:E6:FD:B8:13:DF Status=0
2019-01-08 10:54:45.224 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onConnectionUpdated() - Device=FE:E6:FD:B8:13:DF interval=24 latency=0 timeout=400 status=0
2019-01-08 10:54:45.825 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onConnectionUpdated() - Device=FE:E6:FD:B8:13:DF interval=24 latency=0 timeout=400 status=0
2019-01-08 10:54:46.149 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: configureMTU() - device: FE:E6:FD:B8:13:DF mtu: 517
2019-01-08 10:54:46.244 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onConfigureMTU() - Device=FE:E6:FD:B8:13:DF mtu=23 status=0
2019-01-08 10:54:46.246 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: setCharacteristicNotification() - uuid: 8ec90001-f315-4f60-9fb8-838830daea50 enable: true
2019-01-08 10:54:49.738 3394-3394/com.thingsaremoving.enovap E/timezone: time : 1.0
2019-01-08 10:54:49.738 3394-3394/com.thingsaremoving.enovap I/LocationUpdate: 2.2889202 : 48.8515689
2019-01-08 10:55:09.687 3394-3394/com.thingsaremoving.enovap E/timezone: time : 1.0
2019-01-08 10:55:09.687 3394-3394/com.thingsaremoving.enovap I/LocationUpdate: 2.2889202 : 48.8515689
2019-01-08 10:55:16.871 3394-3406/com.thingsaremoving.enovap E/DfuImpl: Characteristic write error: 133
2019-01-08 10:55:16.871 3394-3406/com.thingsaremoving.enovap D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=11 device=FE:E6:FD:B8:13:DF
2019-01-08 10:55:16.873 3394-3698/com.thingsaremoving.enovap E/DfuBaseService: Unable to write Op Code 3 (error 133)
2019-01-08 10:55:16.874 3394-3698/com.thingsaremoving.enovap W/removing.enova: Accessing hidden method Landroid/bluetooth/BluetoothGatt;->refresh()Z (light greylist, reflection)
2019-01-08 10:55:16.875 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: refresh() - device: FE:E6:FD:B8:13:DF
2019-01-08 10:55:16.876 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: close()
2019-01-08 10:55:16.876 3394-3698/com.thingsaremoving.enovap D/BluetoothGatt: unregisterApp() - mClientIf=11
We are working on Android BLE & implemented successfully and it’s working fine with all OS version and devices.
We are able to connect successfully using below code:
mBluetoothDevice.connectGatt(this, true, mGattCallback);
connectGatt
But recently Samsung released Android Oreo(8.0.0) for Samsung Galaxy S9, S9+,S8, S8+ etc devices. Now we are not able to connect with BLE in Samsung devices with Android Oreo using above method. We didn’t get any callback in mGattCallback.
When the autoconnect flag true, the log is:
06-16 14:03:39.666 13724-13724/com.ble D/BluetoothGatt: cancelOpen() - device: DA:32:19:58:63:69
06-16 14:03:39.667 13724-13724/com.ble D/BluetoothGatt: close()
06-16 14:03:39.668 13724-13724/com.ble D/BluetoothGatt: unregisterApp() - mClientIf=0
06-16 14:03:39.792 13724-13724/com.ble D/BluetoothGatt: connect() - device: DA:32:19:58:63:69, auto: true
06-16 14:03:39.793 13724-13724/com.ble D/BluetoothGatt: registerApp()
06-16 14:03:39.793 13724-13724/com.ble D/BluetoothGatt: registerApp() - UUID=f672f50e-d321-4785-9af7-0668e5222970
06-16 14:03:39.797 13724-15182/com.ble D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
But if change the autoconnect flag to false then it’s working.
06-16 14:05:29.486 15681-15681/com.ble D/BluetoothGatt: connect() - device: DA:32:19:58:63:69, auto: false
06-16 14:05:29.487 15681-15681/com.ble D/BluetoothGatt: registerApp()
06-16 14:05:29.487 15681-15681/com.ble D/BluetoothGatt: registerApp() - UUID=a7c4d089-4ba2-422e-b2d1-355d56f6cc8b
06-16 14:05:29.489 15681-16134/com.ble D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
06-16 14:05:30.198 15681-16134/com.ble D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=DA:32:19:58:63:69
06-16 14:05:30.202 15681-16134/com.ble D/BluetoothGatt: discoverServices() - device: DA:32:19:58:63:69
06-16 14:05:30.503 15681-16134/com.ble D/BluetoothGatt: onConnectionUpdated() - Device=DA:32:19:58:63:69 interval=6 latency=0 timeout=500 status=0
06-16 14:05:31.033 15681-16134/com.ble D/BluetoothGatt: onSearchComplete() = Device=DA:32:19:58:63:69 Status=0
06-16 14:05:31.055 15681-16134/com.ble D/BluetoothGatt: setCharacteristicNotification() - uuid: 00001734-2927-efef-cdab-eba0fe583711 enable: true
06-16 14:05:31.108 15681-16134/com.ble D/BluetoothGatt: onConnectionUpdated() - Device=DA:32:19:58:63:69 interval=39 latency=0 timeout=500 status=0
When we apply this change it does not connect when the user goes out of range and come again in the range in all devices.
If anyone knows the solutions, please post here.
I'm using RxAndroidBle library for communicating with bluetooth device,
however recently i bumped into strange issue.
When reading one of the device characteristics i receive such error:
BleGattCharacteristicException{macAddress=60:CE:32:BA:9E:70,
status=6 (0x06 -> https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h),
bleGattOperationType=BleGattOperation{description='CHARACTERISTIC_READ'}}
I see that the description states that something is wrong with the characteristic read but I was able to read it on the same device using some commercial scanners or vanilla bluetooth code from google samples.
I checked the characteristic properties - it has PROPERTY_READ.
I bump into same error when using Polidea sample of RxAndroidBle.
Couldn't find similar case anywhere in the internet, maybe someone bumped into such error.
Additional info might be that the device I'm connecting to is a ble device simulator running on an iPhone.
I'm not providing any snippets as I'm using the same code which is in the core examples.
Full verbose log:
06-12 11:00:20.105 22459-22459/? D/RxBle#Radio: QUEUED RxBleRadioOperationConnect(121589482)
06-12 11:00:20.106 22459-22504/? D/RxBle#Radio: STARTED RxBleRadioOperationConnect(121589482)
06-12 11:00:20.131 22459-22459/? D/BluetoothGatt: connect() - device: 41:0A:AE:0E:C2:50, auto: false
06-12 11:00:20.131 22459-22459/? D/BluetoothGatt: registerApp()
06-12 11:00:20.131 22459-22459/? D/BluetoothGatt: registerApp() - UUID=b6c1ef8f-408b-4afb-8e27-97a6ff2c20fb
06-12 11:00:20.137 22459-22473/? D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
06-12 11:00:20.330 22459-22473/? D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=41:0A:AE:0E:C2:50
06-12 11:00:20.333 22459-22473/? D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0
06-12 11:00:20.395 22459-22854/? D/CharacteristicOperationExampleActivity: Hey, connection has been established!
06-12 11:00:20.400 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationConnect(121589482)
06-12 11:00:25.608 22459-22459/? I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
06-12 11:00:25.663 22459-22459/? I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
06-12 11:00:25.675 22459-22459/? D/RxBle#Radio: QUEUED RxBleRadioOperationServicesDiscover(3295555)
06-12 11:00:25.676 22459-22504/? D/RxBle#Radio: STARTED RxBleRadioOperationServicesDiscover(3295555)
06-12 11:00:25.683 22459-22459/? D/BluetoothGatt: discoverServices() - device: 41:0A:AE:0E:C2:50
06-12 11:00:25.726 22459-22473/? D/BluetoothGatt: onSearchComplete() = Device=41:0A:AE:0E:C2:50 Status=0
06-12 11:00:25.727 22459-22473/? D/RxBle#BluetoothGatt: onServicesDiscovered status=0
06-12 11:00:25.732 22459-22854/? D/RxBle#Radio: QUEUED RxBleRadioOperationCharacteristicRead(177013014)
06-12 11:00:25.733 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationServicesDiscover(3295555)
06-12 11:00:25.735 22459-22504/? D/RxBle#Radio: STARTED RxBleRadioOperationCharacteristicRead(177013014)
06-12 11:00:25.827 22459-22471/? W/BluetoothGatt: onCharacteristicRead() - Device=41:0A:AE:0E:C2:50 handle=102 Status=6
06-12 11:00:25.830 22459-22471/? D/RxBle#BluetoothGatt: onCharacteristicRead characteristic=1f26b1a4-2b50-11e7-99a8-fcaa142b0bea status=6
06-12 11:00:25.844 22459-22471/? D/RxBle#Radio: QUEUED RxBleRadioOperationDisconnect(84936079)
06-12 11:00:25.849 22459-22471/? D/elo: error: BleGattCharacteristicException{macAddress=41:0A:AE:0E:C2:50, status=6 (0x06 -> https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h), bleGattOperationType=BleGattOperation{description='CHARACTERISTIC_READ'}}
06-12 11:00:25.879 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationCharacteristicRead(177013014)
06-12 11:00:25.880 22459-22504/? D/RxBle#Radio: STARTED RxBleRadioOperationDisconnect(84936079)
06-12 11:00:25.915 22459-22459/? D/elo: error: BleGattCharacteristicException{macAddress=41:0A:AE:0E:C2:50, status=6 (0x06 -> https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h), bleGattOperationType=BleGattOperation{description='CHARACTERISTIC_READ'}}
06-12 11:00:25.925 22459-22459/? D/BluetoothManager: getConnectionState()
06-12 11:00:25.925 22459-22459/? D/BluetoothManager: getConnectedDevices
06-12 11:00:25.951 22459-22459/? D/BluetoothGatt: cancelOpen() - device: 41:0A:AE:0E:C2:50
06-12 11:00:25.962 22459-22471/? D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=41:0A:AE:0E:C2:50
06-12 11:00:25.966 22459-22471/? D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=0
06-12 11:00:25.971 22459-22459/? D/BluetoothGatt: close()
06-12 11:00:25.971 22459-22459/? D/BluetoothGatt: unregisterApp() - mClientIf=6
06-12 11:00:25.974 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationDisconnect(84936079)
Verbose log from the Google Bluetooth Sample app in which I can read that property
06-12 14:43:36.540 10869-10869/com.example.android.bluetoothlegatt I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
06-12 14:43:36.598 10869-10869/com.example.android.bluetoothlegatt I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
06-12 14:43:36.599 10869-10869/com.example.android.bluetoothlegatt D/BluetoothLeService: Trying to use an existing mBluetoothGatt for connection.
06-12 14:43:41.209 10869-10869/com.example.android.bluetoothlegatt D/BluetoothAdapter: stopLeScan()
06-12 14:43:41.215 10869-10869/com.example.android.bluetoothlegatt D/BluetoothAdapter: scan not started yet
06-12 14:43:43.781 10869-10882/com.example.android.bluetoothlegatt D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=5F:56:F7:E9:8A:38
06-12 14:43:43.789 10869-10882/com.example.android.bluetoothlegatt I/BluetoothLeService: Connected to GATT server.
06-12 14:43:43.789 10869-10882/com.example.android.bluetoothlegatt D/BluetoothGatt: discoverServices() - device: 5F:56:F7:E9:8A:38
06-12 14:43:43.792 10869-10882/com.example.android.bluetoothlegatt I/BluetoothLeService: Attempting to start service discovery:true
06-12 14:43:45.513 10869-10882/com.example.android.bluetoothlegatt D/BluetoothGatt: onSearchComplete() = Device=5F:56:F7:E9:8A:38 Status=0
06-12 14:43:54.958 10869-10869/com.example.android.bluetoothlegatt D/BluetoothGatt: setCharacteristicNotification() - uuid: 1f26b1a4-2b50-11e7-99a8-fcaa142b0bea enable: true
06-12 14:43:55.063 10869-10882/com.example.android.bluetoothlegatt W/BluetoothGatt: onCharacteristicRead() - Device=5F:56:F7:E9:8A:38 handle=110 Status=0
There is a difference indeed, as this app is setting a notification before reading a value. The code in app responsible for that looks like this:
// If a given GATT characteristic is selected, check for supported features. This sample
// demonstrates 'Read' and 'Notify' features. See
// http://d.android.com/reference/android/bluetooth/BluetoothGatt.html for the complete
// list of supported characteristic features.
private final ExpandableListView.OnChildClickListener servicesListClickListner =
new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
if (mGattCharacteristics != null) {
final BluetoothGattCharacteristic characteristic =
mGattCharacteristics.get(groupPosition).get(childPosition);
final int charaProp = characteristic.getProperties();
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
// If there is an active notification on a characteristic, clear
// it first so it doesn't update the data field on the user interface.
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(
mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}
mBluetoothLeService.readCharacteristic(characteristic);
}
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
mNotifyCharacteristic = characteristic;
mBluetoothLeService.setCharacteristicNotification(
characteristic, true);
}
return true;
}
return false;
}
};
As for RxAndroidBle version, I tested it on 1.2.0, 1.2.4 and 1.3.0.
Android versions 7.1, 6.0.1 and 5.1.
Will try to implement this notification before reading characteristic as it's the only difference I can see.
I am receiving the above error on Android BLE app while connecting to my pca10040 based board, and I developed this app with nRF Toolbox as a reference.
I am testing this on multiple Android versions and devices, out of which I dont face any problem on motorolla devic, or nexus device (android 7) or on one plus one with android 6.
I am specifically facing this issue on redmi 3s prime with android 6.0.1. On this device My connection handler will wait for some time and then it throws this error.
I have attached the logs with testing different devices:
**Note : 1 = Connected state
2 = Connecting state
Mi Redme 3s Prime (6.0.1 - Marshmallow)
Result: Fail
04-18 11:56:59.462 8852-8852/com.demo.bledoorlock D/BluetoothGatt: connect() - device: D0:35:52:F8:A9:59, auto: false
04-18 11:56:59.462 8852-8852/com.demo.bledoorlock D/BluetoothGatt: registerApp()
04-18 11:56:59.462 8852-8852/com.demo.bledoorlock D/BluetoothGatt: registerApp() - UUID=dd2097ce-ff94-42e4-a454-4c4401aa5482
04-18 11:56:59.466 8852-8892/com.demo.bledoorlock D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
04-18 11:56:59.467 8852-8852/com.demo.bledoorlock I/System.out: 2
04-18 11:57:00.740 8852-8888/com.demo.bledoorlock V/FA: Inactivity, disconnecting from the service
04-18 11:57:29.490 8852-8992/com.demo.bledoorlock D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=5 device=D0:35:52:F8:A9:59
04-18 11:57:29.491 8852-8852/com.demo.bledoorlock I/System.out: 2
Mi Redme 2 Prime (5.1.1 - Lollipop)
Result: Pass
04-18 11:54:13.871 25251-25251/com.demo.bledoorlock D/BluetoothGatt: connect() - device: D0:35:52:F8:A9:59, auto: false
04-18 11:54:13.871 25251-25251/com.demo.bledoorlock D/BluetoothGatt: registerApp()
04-18 11:54:13.871 25251-25251/com.demo.bledoorlock D/BluetoothGatt: registerApp() - UUID=cb431bbb-bc5e-459b-bdcf-f7ed1929fa01
04-18 11:54:13.871 25251-25580/com.demo.bledoorlock D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
04-18 11:54:13.871 25251-25251/com.demo.bledoorlock I/System.out: 2
04-18 11:54:14.071 25251-25267/com.demo.bledoorlock D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=D0:35:52:F8:A9:59
04-18 11:54:14.071 25251-25251/com.demo.bledoorlock I/System.out: 1
04-18 11:54:14.091 25251-25251/com.demo.bledoorlock D/BluetoothGatt: discoverServices() - device: D0:35:52:F8:A9:59
04-18 11:54:14.091 25251-25251/com.demo.bledoorlock I/ViewRootImpl: CPU Rendering VSync enable = true
04-18 11:54:14.091 25251-25580/com.demo.bledoorlock D/BluetoothGatt: onSearchComplete() = Device=D0:35:52:F8:A9:59 Status=0
04-18 11:54:14.101 25251-25580/com.demo.bledoorlock D/BluetoothGatt: setCharacteristicNotification() - uuid: 6e400003-b5a3-f393-e0a9-e50e24dcca9e enable: true
Oneplus One (6.0.1 - Marshmallow)
Result: Pass
04-18 11:58:16.768 28661-28661/com.demo.bledoorlock D/BluetoothGatt: connect() - device: D0:35:52:F8:A9:59, auto: false
04-18 11:58:16.768 28661-28661/com.demo.bledoorlock D/BluetoothGatt: registerApp()
04-18 11:58:16.768 28661-28661/com.demo.bledoorlock D/BluetoothGatt: registerApp() - UUID=a3af82f0-c095-4b06-a1fb-479d7d5f715e
04-18 11:58:16.770 28661-28674/com.demo.bledoorlock D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
04-18 11:58:16.777 28661-28661/com.demo.bledoorlock I/System.out: 2
04-18 11:58:17.073 28661-28675/com.demo.bledoorlock D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=D0:35:52:F8:A9:59
04-18 11:58:17.074 28661-28661/com.demo.bledoorlock I/System.out: 1
04-18 11:58:17.086 28661-28661/com.demo.bledoorlock D/BluetoothGatt: discoverServices() - device: D0:35:52:F8:A9:59
04-18 11:58:17.089 28661-28674/com.demo.bledoorlock D/BluetoothGatt: onSearchComplete() = Device=D0:35:52:F8:A9:59 Status=0
04-18 11:58:17.092 28661-28674/com.demo.bledoorlock D/BluetoothGatt: setCharacteristicNotification() - uuid: 6e400003-b5a3-f393-e0a9-e50e24dcca9e enable: true
04-18 11:58:17.159 28661-28697/com.demo.bledoorlock V/RenderScript: 0xaeee3000 Launching thread(s), CPUs 4
04-18 11:58:17.571 28661-28693/com.demo.bledoorlock V/FA: Inactivity, disconnecting from the service
Please suggest how to fix this?
When ranging beacons on an android device, an error occurs after some time (about 3-5 minutes). After this, the ranging no longer sees the beacons.
It helps only reboot the Bluetooth. After rebooting the ranging starts working normally, the beacons are detected, but after a while, the failure again occurs.
As far as I understand, client connections overflow.
I learned logcat and determined the following errors:
GATT_Register: can not Register GATT client, MAX client reached!
CycledLeScannerForLollipop Scan failed:app cannot be registered
BluetoothLeScanner onClientRegistered () - status = 133 clientIf = 0
mClientIf = 0
How much I understand status should be 0.
I note once again that the feature of the work is a service that runs in a separate process from the application itself.
Strings from logcat with the BluetoothLeScanner filter at the moment when the service stops seeing the beacons:
Debug 12591 BluetoothLeScanner onClientRegistered() - status=133 clientIf=0 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=133 clientIf=0 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=133 clientIf=0 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=133 clientIf=0 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=0 clientIf=32 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=0 clientIf=32 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=0 clientIf=31 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=0 clientIf=30 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=0 clientIf=29 mClientIf=0
Debug 12591 BluetoothLeScanner onClientRegistered() - status=0 clientIf=28 mClientIf=0
It is possible as that to solve the given problem? Thank you!
EDIT:
This is logcat:
Time Device Name Type PID Tag Message
02-19 18:49:45.395 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=133 clientIf=0 mClientIf=0
02-19 18:49:40.375 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=32 mClientIf=0
02-19 18:49:35.333 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=31 mClientIf=0
02-19 18:49:30.411 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=30 mClientIf=0
02-19 18:49:25.256 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=29 mClientIf=0
02-19 18:49:20.234 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=28 mClientIf=0
02-19 18:49:15.185 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=27 mClientIf=0
02-19 18:49:10.181 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=5 mClientIf=0
02-19 18:49:05.170 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=26 mClientIf=0
02-19 18:49:00.124 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=26 mClientIf=0
02-19 18:48:55.108 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=25 mClientIf=0
02-19 18:48:50.078 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=25 mClientIf=0
02-19 18:48:45.028 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=23 mClientIf=0
02-19 18:48:39.992 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=24 mClientIf=0
02-19 18:48:39.316 AGM A8 Debug 3254 BluetoothLeScanner onClientRegistered() - status=0 clientIf=23 mClientIf=0
02-19 18:48:34.994 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=22 mClientIf=0
02-19 18:48:29.927 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=21 mClientIf=0
02-19 18:48:24.905 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=20 mClientIf=0
02-19 18:48:19.866 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=19 mClientIf=0
02-19 18:48:14.852 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=18 mClientIf=0
02-19 18:48:09.825 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=17 mClientIf=0
02-19 18:48:04.812 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=16 mClientIf=0
02-19 18:47:59.768 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=15 mClientIf=0
02-19 18:47:54.751 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=14 mClientIf=0
02-19 18:47:49.708 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=13 mClientIf=0
02-19 18:47:44.688 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=12 mClientIf=0
02-19 18:47:39.676 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=11 mClientIf=0
02-19 18:47:34.662 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=10 mClientIf=0
02-19 18:47:29.603 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=9 mClientIf=0
02-19 18:47:24.585 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=8 mClientIf=0
02-19 18:47:19.552 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=7 mClientIf=0
02-19 18:47:14.525 AGM A8 Debug 13351 BluetoothLeScanner onClientRegistered() - status=0 clientIf=7 mClientIf=0
On some Android device models, the Bluetooth stack can get into a bad state requiring a power cycle to make it able to scan for bluetooth devices again. In order to automate a fix for this problem, a BluetoothMedic has been added to the Android Beacon Library which will automatically power cycle bluetooth when a problem is detected. As of this writing, this change is still in a pull request so not yet merged into a release build of the library.
While this is a workaround for your problem, the core issue is probably that you have too many Bluetooth scanning apps installed on your phone. Android limits the number of apps simultaneously using a Bluetooth client to 32. If you have more than that many apps installed that are trying to use Bluetooth LE APIs, you will get this error, and only a power cycle of bluetooth (which may be automated by the BluetoothMedic above) can recover from the problem. This will effectively kill the use of the bluetooth APIs on the other apps so your app has a chance to use them.
Simply turn off the Bluetooth of your phone and run a system clean then run the app again. This solved my problem and headache also.