As the title says, I'm trying to get notifications for characteristics from different services.
However, it seems that only the notifications for characteristics from the first service that was discovered are working.
I'm new to both BLE and this library so maybe I'm doing something wrong here, but basically here's what I'm doing:
- Discover all services
- For each service, discover all characteristics
- For each characteristic, read the descriptor and the value
After reading the value, I set up the notifications for the characteristics' UUIDs I'm interested in as explained on the readme from the library here https://github.com/Polidea/RxAndroidBle#change-notifications
I created a method to set up the notifications which looks like this:
public void setUpNotification(@NonNull String descriptorString, @NonNull UUID characteristicUUID) {
Disposable notificationDisposable = rxBleConnection.setupNotification(characteristicUUID)
.doOnNext(notificationObservable -> {
Log.v(TAG, "setUpNotification # " + descriptorString + ", " + characteristicUUID);
})
.flatMap(notificationObservable -> notificationObservable)
.subscribe(
bytes -> {
Log.v(TAG, "setUpNotification # " + descriptorString + "=" + Arrays.toString(bytes));
handleNotification(descriptorString, bytes);
},
throwable -> {
Log.e(TAG, "setUpNotification # " + descriptorString + ", Error: " + Exceptions.toString(throwable));
}
);
disposables.add(notificationDisposable);
}
I can see in the logs that the notifications are set up for all the characteristics needed, but I'm only receiving the notifications for the characteristics from the first service of the loop. If I skip the notification set up for the first service, I receive only notifications from the second service, but not the third one. I have to get notifications for characteristics from all 3 services but so far I could not manage to make it work.
I did a bit of research but could not find any example showing how to subscribe to notifications for characteristics from different services, so any help would be greatly appreciated!