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.

There is no response from writeDescriptor() when used in a chain

See original GitHub issue

Hey. I have encountered such a problem when no response comes from method writeDescriptor when used in a chain. Here is my code:

override fun connectDevice() {
        rxBleClient.scanBleDevices(scanSettings, scanFilter)
            .flatMap { scanResult -> scanResult.bleDevice.establishConnection(false) }
            .flatMapSingle {
                rxBleConnection = it
                it.discoverServices()
            }
            .flatMapSingle { obtainCharacteristics(it) }
            .flatMapCompletable {
                readCharacteristic = it.first
                writeCharacteristic = it.second

                writeDescriptor(it.first)
            }
            .andThen(Single.fromCallable { startConnection() })
            .flatMap { it }
            .subscribeBy(
                onSuccess = { setupAndObserveNotifications(readCharacteristic!!) },
                onError = { Timber.d("$it") }
            )
    }

My method writeDescriptor:

private fun writeDescriptor(readCharacteristic: BluetoothGattCharacteristic): Completable {
        val descriptor = readCharacteristic.getDescriptor(READ_CHARACTERISTIC_CONFIG)
        return rxBleConnection!!.writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
            .doOnComplete { Timber.d("Descriptor wrote.") }
            .doOnError { Timber.e("Error while descriptor is writing: $it") }
    }

The chain comes to writeDescriptor(it.first), also called doOnComplete { Timber.d("Descriptor wrote."), but it does not go further down the chain in andThen(Single.fromCallable { startConnection() }) and next in subscribe. What could be the problem?

P.S. I reproduced the same example with the chain separately (without the library) withflatMapCompletable, andThen and etc., and everything was done correctly.

fun main() {
    Single.just(1)
        .delay(1, TimeUnit.SECONDS)
        .flatMapCompletable { getCompletable() }
        .andThen(Single.fromCallable { getSingle() })
        .flatMap { it }
        .subscribe { i -> println(i) }

    Thread.sleep(5000)
}

private fun getCompletable(): Completable {
    return Completable.fromRunnable {
        Thread.sleep(1000)
    }
}

private fun getSingle(): Single<Int> {
    return Single.just(5)
}

In the console comes the correct answer - 5

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, Dec 7, 2018

.establishConnection() does not complete on its own. You can read about it in the Observable behaviour part of Readme

0reactions
akhbulatovcommented, Dec 7, 2018

Ok, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

There is no response from writeDescriptor() when used in a ...
Hey. I have encountered such a problem when no response comes from method writeDescriptor when used in a chain. Here is my code:...
Read more >
Android BLE BluetoothGatt.writeDescriptor() return sometimes ...
Here is one reply saying that BLE is busy with writeDescriptor() and can not do other write. Here is another thread saying that...
Read more >
use descriptor chain in SGDMA - Intel Communities
Hi all My current goal is to use SGDMA (ST-to-MM) to transfer video data to a memory. Later on, I'll replace the memory...
Read more >
The Ultimate Guide to Android Bluetooth Low Energy
Learn about the basics of Android BLE, get an overview of important glossary terms, and real world examples to better develop Android apps....
Read more >
Example Encryption Software for PC to Synergy Communication
Below is some example Python code that can be used on a PC to generate an encrypted data stream for communicating to a...
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