0

I'm using RxAndroidBle library v 1.4.1. I'd like to scan every few seconds while being connected to a device. The problem is that when I stop the scan (I do not want to scan all the time, just every few seconds) it closes the connection to the device.

rxBleClient.scanBleDevices(
    newScanSettings.Builder()
               .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
               .build(),
     new ScanFilter.Builder()
                   .setServiceUuid("xyz")
                   .build()
)
.buffer(SCANNING_WINDOW_SECONDS, TimeUnit.SECONDS)
.first()
.repeatWhen(observable -> observable.delay(INTERVAL, TimeUnit.SECONDS));

I know that this behavior is documented "scanBleDevices() - this Observable when unsubscribed closes/cleans up internal resources (i.e. finishes scan, closes a connection, disables notifications)"

Is there any workaround? Or do I have to waste the battery and scan all the time while being connected or do not scan at all?

EDIT The problem occurs only on some devices - eg. Asus Zenfone T100J.

scanDevices()
   .doOnNext(device -> {
        if(disconnected && device!=null){connect();}
    })
malinjir
  • 1,475
  • 2
  • 12
  • 17
  • Unsubscribing from the scan observable disables the scan only. You probably have a different problem. Please show all related code and logs from your application with a setting `RxBleLog.setLogLevel(RxBleLog.VERBOSE)`. – Dariusz Seweryn Oct 04 '17 at 08:46
  • When I remove the first() operator, everything works as expected..... I forgot to mention, that it happens only on some devices - eg. ASUS Zenfone T100J.... Unfortunately, there is too much related code. – malinjir Oct 04 '17 at 09:30
  • I see only the scan without any relations nor I have access to the mentioned phone. I do not know how the scan flow works with the connection flow—I cannot help. What is the `INTERVAL`? If it is 5 seconds then it the same as the system scan interval on Android devices in modes other than `SCAN_MODE_LOW_LATENCY`. – Dariusz Seweryn Oct 04 '17 at 09:40
  • The interval is 10-60s. Nevertheless, the scanBleDevices observable keeps emitting found devices. It doesn't look like there is any delay between scans. – malinjir Oct 04 '17 at 09:45
  • `SCAN_MODE_LOW_POWER` scans for 0.5 second every 5 seconds. – Dariusz Seweryn Oct 04 '17 at 09:47
  • Not sure, but I think I have seen the same behavior where a device is found repeatedly without any apparent delay between scans. Or can a single device be found multiple times during a single scan window? – Robert Lewis Dec 02 '17 at 14:29

0 Answers0