question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RSSI Read operation sometimes times out

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, Nov 27, 2020

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.

0reactions
OliverCulleyDeLangecommented, Nov 27, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

RSSI Read operation sometimes times out · Issue #729 - GitHub
I expect the RSSI read operation to complete successfully, and not timeout. Or at least, in the event of a timeout, the retry...
Read more >
RSSI reading too low/unreliable. RSSI Latch always zero.
I believe the call is important for a couple of reasons. 1) from the first link, user Brent_W (a Silicon Labs employee) says...
Read more >
android - onLeScan callback returns oddly positive RSSI values
This is definitely not normal. I have never seen a rssi value in that callback be positive. Typical values are from -30 to...
Read more >
Real time RSSI measurement broken ... - LowPowerLab
I'm confused as to how the receiver might be re-triggering a new RSSI sample event if the receiver is not explicitly being taken...
Read more >
High RSSI, High SNR, but high Data Retries rate (Multipath ...
I have noticed that RSSI is reported at -55dBm and SNR is at 40dBm, which is quite an awesome. However, at the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found