Detection of BLE device is not stable - most of the time device not found
See original GitHub issueDisclaimer
Before you will post a new issue to the RxAndroidBle library consider if you are filling a bug/feature request or a general question about:
- Usage of RxJava
- Usage of Bluetooth Low Energy
- Usage of RxAndroidBle
- Weird behaviour of the peripheral you are using
- Other not directly related to a new feature request or a bug
If any of the above points seems to match your use case — consider using Google or creating a question on www.stackoverflow.com with
a tag rxandroidble
where it will be easier to access by other people with similar questions. Issues that are not bugs or feature requests
will be closed.
Summary
First thanks for this amazing library! it helps us a lot! Now, I am developing an Android app for a Heart rate sensor The device is scanned and connection is established basically everything works fine but it’s not very stable and users starts to get annoying about this problem. Since user needs to send measurement of the device to the app successfully, the app must always find the device in the scan but unfortunately some times the device is not detected and not found in scan result and i can’t figure out what could be the reason that can make the device not visible to Android!
Library version
1.5.0
Minimum code snippet reproducing the issue
This is what i am using for Scanning:
private Observable<RxBleScanResult> prepareBleScanResultObservable() {
return Observable.defer(() -> rxBleClient.scanBleDevices())
.filter(rxBleScanResult -> {
String name = rxBleScanResult.getBleDevice().getName();
return !TextUtils.isEmpty(name));
})
.observeOn(AndroidSchedulers.mainThread())
.doOnUnsubscribe(() -> scanBleDevicesSubscription = null)
.take(7, TimeUnit.SECONDS);
}
BTW, i am not disconnecting from the device, and even if i disconnect i still get the same problem.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
BT 4.0 devices are not able to be connected and advertise at the same time. If you do not disconnect you may not expect that you will be able to scan the device. Different Android phones have different performance in regards how they scan. It may be that they will not scan the HRM in 7 seconds window. This has nothing to do with the library. Why do you think the thing you experience is a library issue?
Two reasons generally come to mind. Your advertisement interval is long so the scan and advertisements fail to be synchronized.
Scan with the ScanSettings.SCAN_MODE_LOW_LATENCY flag to see if this is true.
Second, you peripheral isn’t advertising because it still thinks you are connected. Implement some sort of heart beat to see if the connection is valid and reset the ble state if it’s not. You can quickly test for this by simply power cycling your peripheral.