{"action":"created","issue":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/61","repository_url":"https://api.github.com/repos/Polidea/RxAndroidBle","labels_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/61/comments","events_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/61/events","html_url":"https://github.com/Polidea/RxAndroidBle/issues/61","id":172850133,"number":61,"title":"Is possible to subscribe to multiple characteristic notifications at once?","user":{"login":"aldoborrero","id":82811,"avatar_url":"https://avatars.githubusercontent.com/u/82811?v=3","gravatar_id":"","url":"https://api.github.com/users/aldoborrero","html_url":"https://github.com/aldoborrero","followers_url":"https://api.github.com/users/aldoborrero/followers","following_url":"https://api.github.com/users/aldoborrero/following{/other_user}","gists_url":"https://api.github.com/users/aldoborrero/gists{/gist_id}","starred_url":"https://api.github.com/users/aldoborrero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldoborrero/subscriptions","organizations_url":"https://api.github.com/users/aldoborrero/orgs","repos_url":"https://api.github.com/users/aldoborrero/repos","events_url":"https://api.github.com/users/aldoborrero/events{/privacy}","received_events_url":"https://api.github.com/users/aldoborrero/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-24T02:21:50Z","updated_at":"2016-08-24T09:31:48Z","closed_at":null,"body":"Is there any possibility where I can subscribe to those characteristics that allow notifications in one row?\r\n\r\nIn the demos you only listen to one characteristic at a time but would be great to have in `RxBleDeviceServices`:\r\n\r\n```Java\r\npublic Observable<List<BluetoothGattCharacteristic>> getCharacteristics(@NonNull UUID serviceUuid) {\r\n    return getService(serviceUuid).map(BluetoothGattService::getCharacteristics)\r\n        .filter(bluetoothGattCharacteristics -> (bluetoothGattCharacteristics != null && bluetoothGattCharacteristics.size() > 0))\r\n        .switchIfEmpty(Observable.error(new BleCharacteristicNotFoundException(serviceUuid)));\r\n  }\r\n```\r\n\r\nAs I'm quite new to RxJava (and your codebase) I don't know if is a good idea to do this (or even the approach) but I would gladly code it if I'm given more explanations on how to achieve it (or maybe I'm thinking a bad assumption and is already implemented).\r\n\r\nThe use case is that I have one object that acts as a model with different parameters and those parameters are filled with the notifications that each characteristic sends with the updated value. As I have 10 characteristics sending notifications, I have to setup every notification by hand, then listen to the change and then update the object.\r\n\r\nBelow is an example of what to achieve (don't look too much to the code as I know that is faulty)\r\n\r\n```Java\r\nconnectionObservable.flatMap(RxBleConnection::discoverServices)\r\n        .flatMap(rxBleDeviceServices -> rxBleDeviceServices.getCharacteristics(ALDeviceUuids.SERVICE_ID))\r\n        .flatMapIterable(bluetoothGattCharacteristics -> bluetoothGattCharacteristics)\r\n        .filter(characteristic -> BleUtils.hasNotificationProperty(characteristic.getProperties()))\r\n        .doOnNext(rxBleConnection::setupNotification)\r\n        .observeOn(AndroidSchedulers.mainThread())\r\n        //.flatMap(characteristic -> characteristic)\r\n        .subscribe(this::onNotificationWritten);\r\n```\r\n\r\nThe same could apply if I would like to read all the values at once by filtering those characteristics that allow reading. \r\n\r\nThanks :)"},"comment":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/comments/242007730","html_url":"https://github.com/Polidea/RxAndroidBle/issues/61#issuecomment-242007730","issue_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/61","id":242007730,"user":{"login":"dariuszseweryn","id":1412475,"avatar_url":"https://avatars.githubusercontent.com/u/1412475?v=3","gravatar_id":"","url":"https://api.github.com/users/dariuszseweryn","html_url":"https://github.com/dariuszseweryn","followers_url":"https://api.github.com/users/dariuszseweryn/followers","following_url":"https://api.github.com/users/dariuszseweryn/following{/other_user}","gists_url":"https://api.github.com/users/dariuszseweryn/gists{/gist_id}","starred_url":"https://api.github.com/users/dariuszseweryn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dariuszseweryn/subscriptions","organizations_url":"https://api.github.com/users/dariuszseweryn/orgs","repos_url":"https://api.github.com/users/dariuszseweryn/repos","events_url":"https://api.github.com/users/dariuszseweryn/events{/privacy}","received_events_url":"https://api.github.com/users/dariuszseweryn/received_events","type":"User","site_admin":false},"created_at":"2016-08-24T09:31:48Z","updated_at":"2016-08-24T09:31:48Z","body":"Hello there.\r\n\r\nQuestion: Is possible to subscribe to multiple characteristic notifications at once?\r\nAnswer: It is possible to subscribe to notifications from multiple characteristics but not in one line.\r\nExplanation: There are almost infinite use cases for the BLE applications and it is impossible to cover them all. I feel that with the current state of the code it is quite easy to implement such a feature but baking it into the library won't benefit many people.\r\n\r\nFrom what I understand you would like to map characteristics values into a POJO model in this scenario either to manually assign a characteristic value to a property or have a model that is very generic (a `Map<UUID, byte[]> perhaps). In the first situation you would need to either set notifications by hand or match the resulting `byte[]` by hand. In the second situation you will end up with something like:\r\n\r\n        final UUID serviceUuid = // your service UUID\r\n        final Map<UUID, byte[]> genericModel = new HashMap<>();\r\n        final Observable<RxBleConnection> connectionObservable = // your connectionObservable\r\n        \r\n        connectionObservable\r\n                .flatMap(connection -> \r\n                        connection.discoverServices()\r\n                                .flatMap(services -> services.getService(serviceUuid).map(BluetoothGattService::getCharacteristics)) // get characteristics you're interested in\r\n                                .flatMap(Observable::from) // deal with every characteristic separately\r\n                                .flatMap(characteristic -> connection\r\n                                                .setupNotification(characteristic) // setup notification for each\r\n                                                .flatMap(observable -> observable), // to get the raw bytes from notification\r\n                                        Pair::new) // merge characteristic with byte[] to keep track from which characteristic the bytes came\r\n                )\r\n                .subscribe(\r\n                        pair -> genericModel.put(pair.first.getUuid(), pair.second),\r\n                        throwable -> { /* handle errors */}\r\n                ); \r\n\r\nI hope this answers your question.\r\n\r\nBest Regards"}}
{"actor":{"display_login":"dariuszseweryn"}}