2

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

lorenzo
  • 494
  • 6
  • 23

2 Answers2

1

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

lorenzo
  • 494
  • 6
  • 23
1

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);
Dariusz Seweryn
  • 3,212
  • 2
  • 14
  • 21
楊舜淼
  • 73
  • 6