2
votes

I'm having issues setting up notifications on multiple characteristics. I've reviewed the documentation and many of the examples only cover very granular situations.

My use case is as follows: 1. scan for devices 2. user selects device to connect to (with the connection persisting until the app is closed) 3. subscribe to notifications for many characteristics 4. read/write to either single characteristics at a time, and in some cases read/write to many characteristics at a time

2
Have you tried to write some code? Create a flow of data to suit your needs?Dariusz Seweryn

2 Answers

1
votes

I got it working now. The issue was I needed to be working with an instance of RxBleConnection for later connectivity

1
votes

this my solution for multiple write

 mConnObservable.flatMapSingle(rxBleConnection -> {
        return rxBleConnection.writeCharacteristic(SSID, mSsidView.getText().toString().getBytes())
                .flatMap(ssidBytes -> rxBleConnection.writeCharacteristic(SSID2, mPassPhrase.getText().toString().getBytes())
                .flatMap(ssid2Bytes -> rxBleConnection.writeCharacteristic(SSID3, mSecurityModeSpinner.getSelectedItem().toString().getBytes())));
    })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(ssid3Bytes -> {
               //do something
            }, this::onError, this::onComplete);

you should put the other flatMap operations in first flatMap, beacause you can only get rxBleConnection in first flatMap

Original solution for RxAndroidBle RxJava 1 version:

 mConnObservable.flatMap(rxBleConnection -> {
        return rxBleConnection.writeCharacteristic(SSID, mSsidView.getText().toString().getBytes())
                .flatMap(ssidBytes -> rxBleConnection.writeCharacteristic(SSID2, mPassPhrase.getText().toString().getBytes())
                .flatMap(ssid2Bytes -> rxBleConnection.writeCharacteristic(SSID3, mSecurityModeSpinner.getSelectedItem().toString().getBytes())));
    })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(ssid3Bytes -> {
               //do something
            }, this::onError, this::onComplete);