0

We are trying to upgrade existing app with your framework, other things are working fine like connection/read/write however we are facing issues with Notification/Disconnect

Can you please guide for following scenarios:-

  1. Need call back for disconnection
  2. Notification not working we are not able to receive any notification alert
  3. Is there any method to check characteristics of devices, as we have different devices and some characteristics are not present in all devices, when we try to read/write non present chacraterstics on devices, it throws exception and app crashes

Code :-

connection.writeDescriptor(
    Defs.SVC_AUTOMATIONIO_UUID, 
    Defs.CHAR_AUTOMATION_IO,
    Defs.DESC_CLIENT_CHAR_CONFIGURATION_UUID,
    BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
)
    .subscribe(
        this::onWriteSuccess,
        this::onWriteFailure
    );

connection.setupNotification(iCharUuid)
    .flatMap(notificationObservable -> notificationObservable)
    .subscribe(
        this::onNotificationReceived,
        this::onConnectionFailure
    );

Thanks Swayam

Dariusz Seweryn
  • 3,212
  • 2
  • 14
  • 21

1 Answers1

0

In general you don't have to write descriptor manually to enable notifications. The library does it for you.

Try: (example)

rxBleConnection.setupNotification(Defs.DESC_CLIENT_CHAR_CONFIGURATION_UUID)
                    .flatMap(notificationObservable -> notificationObservable)
                    .subscribe(this::onNotificationReceived, this::onNotificationSetupFailure);

In order to get callback for disconnection: (example)

  1. You can observe onError from establishConnection method.
  2. You can setup connection status observable

bleDevice.observeConnectionStateChanges().subscribe(this::onConnectionStateChange);

To check characteristics you can go with service discovery: (example)

 bleDevice.establishConnection(this, false)
                .flatMap(RxBleConnection::discoverServices)
                .first() // Disconnect automatically after discovery
                .subscribe(this::processDiscoveredServices, this::onConnectionFailure);
pawel.urban
  • 1,031
  • 8
  • 10
  • Thanks for quick response, let me try this quickly and post it – Swayam Prakash Agrawal Jul 26 '16 at 09:15
  • Its working now, disconnection and notification, Only guidance i need is about characterstics, if any characterstics is not present in Device and we will try to write/read it, will framework throws exception? – Swayam Prakash Agrawal Jul 26 '16 at 09:16
  • How to avoid following error Caused by: rx.exceptions.OnErrorNotImplementedException at rx.Observable$26.onError(Observable.java:7881) at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:159) at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:120) at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:240) at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:776) at – Swayam Prakash Agrawal Jul 26 '16 at 09:24
  • Ad. How to avoid error - whenever you subscribe to an `Observable` provide error handling. Ad. If you will use `RxBleConnection.readCharacteristic(UUID)` and that `UUID` won't be available then there will be emitted a `BleCharacteristicNotFoundException`. If you will pass a null `BluetoothCharacteristic` to `RxBleConnection.readCharacteristic(BluetoothCharacteristic)` then a NPE will be emitted. – Dariusz Seweryn Jul 26 '16 at 09:35
  • I have added error handler for every subscription, however when device disconnects app crashes with error Caused by: rx.exceptions.OnErrorNotImplementedException at rx.Observable$26.onError(Observable.java:7881) at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:159) at – Swayam Prakash Agrawal Jul 26 '16 at 10:02
  • I don't see the full stacktrace so it is hard to judge where the error handling is not implemented but obviously somewhere it is not implemented. – Dariusz Seweryn Jul 26 '16 at 11:21
  • thanks for reply, as below i have added two method in every scibcribe call on connection connection.writeCharacteristic(iCharUuid, data) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::onWriteSuccess, this::onWriteFailure); which i should work as error handler, is that correct? – Swayam Prakash Agrawal Jul 26 '16 at 11:47
  • is there way, i can prevent app from crashing even if some error occurs? – Swayam Prakash Agrawal Jul 26 '16 at 11:48
  • You're correct. Maybe it's a bug in the library or maybe you have overlooked something in your code. Unfortunately to prevent the app from crashing I don't know any options besides handling errors. If you would post the full stacktrace somewhere or the full code that is using `RxAndroidBle` then maybe I could help you more. – Dariusz Seweryn Jul 26 '16 at 11:52
  • Thanks, i will post full stack trace on web site blog, stacktrace is not allowing to post complete error in comment, however issue is intermittent, when two devices conncects in same time, then error occurs with disconnection – Swayam Prakash Agrawal Jul 26 '16 at 11:54
  • Posted full error stack trace http://stackoverflow.com/questions/38589272/rxandroid-ble-crash-occurs-even-providing-all-error-handlers-to-operation-observ – Swayam Prakash Agrawal Jul 26 '16 at 11:58