RSSI Read operation sometimes times out
See original GitHub issueDescribe the bug Every second, i poll 2 seperate RxBleConnections to capture RSSI values for each. Note, this interval observable is started as soon as the device is connected - so unlikely to be at the same time as the other device.
Observable.interval(1, TimeUnit.SECONDS)
.flatMapSingle { controller.getRssi() }
/* in the controller, which owns an RxBleConnection */
fun getRssi(): Single<RssiResult> = connection.readRssi()
.map<RssiResult> { RssiResult.RssiReading(getSeconds(), it) }
.onErrorReturn { RssiResult.RssiError(it) }
This mostly works. However sometimes it errors and returns RssiError(t=com.polidea.rxandroidble2.exceptions.BleGattCallbackTimeoutException: GATT exception from MAC address D8:AB:B4:6F:B3:86, with type BleGattOperation{description='READ_RSSI'})
Here’s some logs from it working OK for comparison:
12:02:39.819 23935-24018 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(23249374)
12:02:39.821 23935-24080 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(23249374)
12:02:39.822 23935-24080 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:02:39.824 23935-24073 D/BluetoothGatt: readRssi() - device: C8:AA:95:FA:BE:08
12:02:39.829 23935-24044 I/RxBle#GattCallback: RXBLE LOG MAC='XX:XX:XX:XX:XX:XX' onReadRemoteRssi(), status=0, value=-55
12:02:39.833 23935-24080 D/RxBle#ConnectionOperationQueue: RXBLE LOG FINISHED ReadRssiOperation(23249374) in 12 ms
12:02:40.027 23935-24082 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(92681556)
12:02:40.028 23935-24084 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(92681556)
12:02:40.028 23935-24084 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:02:40.029 23935-24073 D/BluetoothGatt: readRssi() - device: EB:E1:02:01:69:E6
12:02:40.031 23935-24044 I/RxBle#GattCallback: RXBLE LOG MAC='XX:XX:XX:XX:XX:XX' onReadRemoteRssi(), status=0, value=-51
12:02:40.034 23935-24084 D/RxBle#ConnectionOperationQueue: RXBLE LOG FINISHED ReadRssiOperation(92681556) in 6 ms
The rate of error seems to be correlated with the two rssi requests happening at the same time. I modified my implementation to request RSSI for both devices simultaneously, and within 3 - 4 seconds, the BleGattCallbackTimeoutException’s would begin, and it would rarely recover.
Here is the more error prone implementation
Observable.interval(1, TimeUnit.SECONDS)
.flatMap {
val rssiL = rxBleConnection.readRssi().onErrorReturn {
Timber.w("Error reading RSSI for Left: $it")
0
}
val rssiR = rxBleConnection.readRssi().onErrorReturn {
Timber.w("Error reading RSSI for Right: $it")
0
}
Single.merge(rssiL, rssiR).toObservable()
}
.doOnNext {
... handle rssi values
}
Here’s some logs of when it first starts off and everything is good
12:05:56.382 24851-24956 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(167934672)
12:05:56.385 24851-24999 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(167934672)
12:05:56.386 24851-24956 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(22665929)
12:05:56.388 24851-24999 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:05:56.389 24851-25004 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(22665929)
12:05:56.391 24851-25004 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:05:56.391 24851-24978 D/BluetoothGatt: readRssi() - device: C8:AA:95:FA:BE:08
12:05:56.394 24851-24978 D/BluetoothGatt: readRssi() - device: EB:E1:02:01:69:E6
12:05:56.395 24851-24873 I/RxBle#GattCallback: RXBLE LOG MAC='XX:XX:XX:XX:XX:XX' onReadRemoteRssi(), status=0, value=-59
12:05:56.400 24851-24873 I/RxBle#GattCallback: RXBLE LOG MAC='XX:XX:XX:XX:XX:XX' onReadRemoteRssi(), status=0, value=-59
12:05:56.404 24851-24999 D/RxBle#ConnectionOperationQueue: RXBLE LOG FINISHED ReadRssiOperation(167934672) in 19 ms
12:05:56.410 24851-25004 D/RxBle#ConnectionOperationQueue: RXBLE LOG FINISHED ReadRssiOperation(22665929) in 21 ms
Then one side starts hanging
12:05:58.382 24851-24956 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(104695851)
12:05:58.384 24851-24999 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(104695851)
12:05:58.386 24851-24956 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(66208904)
12:05:58.387 24851-24999 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:05:58.390 24851-25004 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(66208904)
12:05:58.393 24851-25004 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:05:58.395 24851-24978 D/BluetoothGatt: readRssi() - device: C8:AA:95:FA:BE:08
12:05:58.400 24851-24978 D/BluetoothGatt: readRssi() - device: EB:E1:02:01:69:E6
12:05:58.409 24851-24873 I/RxBle#GattCallback: RXBLE LOG MAC='XX:XX:XX:XX:XX:XX' onReadRemoteRssi(), status=0, value=-58
12:05:58.415 24851-25004 D/RxBle#ConnectionOperationQueue: RXBLE LOG FINISHED ReadRssiOperation(66208904) in 25 ms
Then one side queues the operation but it doesn’t run
12:05:59.387 24851-24956 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(266351258)
12:05:59.391 24851-24956 D/RxBle#ConnectionOperationQueue: RXBLE LOG QUEUED ReadRssiOperation(251439051)
12:05:59.396 24851-25004 D/RxBle#ConnectionOperationQueue: RXBLE LOG STARTED ReadRssiOperation(251439051)
12:05:59.398 24851-25004 I/RxBle#ConnectionOperationQueue: RXBLE LOG RUNNING ReadRssiOperation{MAC='XX:XX:XX:XX:XX:XX'}
12:05:59.400 24851-24978 D/BluetoothGatt: readRssi() - device: EB:E1:02:01:69:E6
12:05:59.405 24851-24873 I/RxBle#GattCallback: RXBLE LOG MAC='XX:XX:XX:XX:XX:XX' onReadRemoteRssi(), status=0, value=-59
12:05:59.412 24851-25004 D/RxBle#ConnectionOperationQueue: RXBLE LOG FINISHED ReadRssiOperation(251439051) in 16 ms
Smartphone (please complete the following information):
- Various devices, captured in the wild from users,
- api “com.polidea.rxandroidble2:rxandroidble:1.10.5”
Additional context
This issue also seems to affect writing data to custom Characteristics on the device. For example, elsewhere i might be doing connection.writeCharacteristic(uuid, data)
- and this will also hang, and not emit any items.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
The library prioritises commands — everything that is called on
BluetoothGatt
object. Usually it is FIFO with an exception of setting notifications if I remember correctly which are prioritised. All callbacks from the system (peripheral) are passes ASAP — no prioritisation here.Ok, i gather from that, that the library does no form of prioritization. Looks like i need to dig into the Android BLE docs a bit more then. Thanks for your time and help, I appreciate it!