Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose between notifications or indications #823

Open
TheAlbertDev opened this issue Nov 22, 2023 · 1 comment
Open

Choose between notifications or indications #823

TheAlbertDev opened this issue Nov 22, 2023 · 1 comment

Comments

@TheAlbertDev
Copy link

TheAlbertDev commented Nov 22, 2023

I tried to look in the documentation and in the code itself for the answer to the question I ask in the title: is it possible to choose whether to subscribe to a characteristic by notification or indication?

(I am in charge of the BLE device firmware, so my knowledge of mobile development is limited. I say this to apologize in advance in case the question is dumb, simple or obvious 😅).

The thing is, I don't know if you can choose whether subscribing to a characteristic via the "subscribeToCharacteristic" method makes use of notifications or indications (i.e. if it will acknowledge or not when receiving data).

I have seen this in the PhilipsHue/flutter_reactive_ble/packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/ble/ReactiveBleClient.kt file:

    private fun setupNotificationOrIndication(
        deviceConnection: EstablishConnectionResult,
        characteristicId: UUID,
        characteristicInstanceId: Int
    ): Observable<Observable<ByteArray>> =
        when (deviceConnection) {
            is EstablishedConnection -> {
                if (rxBleClient.getBleDevice(deviceConnection.deviceId).bluetoothDevice.bondState == BOND_BONDING) {
                    Observable.error(Exception("Bonding is in progress wait for bonding to be finished before executing more operations on the device"))
                } else {
                    deviceConnection.rxConnection.resolveCharacteristic(
                            characteristicId, characteristicInstanceId
                    ).flatMapObservable { characteristic ->
                        val mode = if (characteristic.descriptors.isEmpty()) {
                            NotificationSetupMode.COMPAT
                        } else {
                            NotificationSetupMode.DEFAULT
                        }

                        if ((characteristic.properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
                            deviceConnection.rxConnection.setupNotification(
                                characteristic,
                                mode
                            )
                        } else {
                            deviceConnection.rxConnection.setupIndication(characteristic, mode)
                        }
                    }
                }
            }
            is EstablishConnectionFailure -> {
                Observable.just(Observable.empty())
            }
        }

In the iOS implementation I haven't even dared to go in to check it out...

I am supposed to assume that if a characteristic has notification permission enabled it is subscribed by notification and only if notification permission is not enabled then it is subscribed by indication? Which would mean that I can't have both permissions enabled. (My Kotlin knowledge is 0...)

Thanks in advance and apologies if the question is dumb...🙇‍♂️

@chipweinberger
Copy link

in iOS you can't choose. not allowed.

Flutter Blue Plus allows choosing on android though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants