Android – sampling ble API cannot get notification of multiple GATT features

I'm developing an application on Samsung ACE3 to connect Bluetooth low-power devices. Because Samsung doesn't want ACE3 to be upgraded to Android 4.3, I need to use the Samsung ble API. At present, connecting, reading data, sending data and getting notifications from one feature are all OK. However, when I enable notifications of multiple features, Only the first enabled feature can be notified. Does anyone have the same question? Thank you for your help!

The following code enables connection notification

 if (mBluetoothGatt != null && device != null) {
        BluetoothGattService pucService = mBluetoothGatt.getService(device, PROFILE_UART_CONTROL_SERVICE);
        if (pucService == null) {
            showMessage("PUC service not found!");
            return;
        }

        BluetoothGattCharacteristic motion = pucService.getCharacteristic(MOTION_READ);
        if (motion == null) {
            showMessage("charateristic not found!");
            return;
        }
        enableNotification(true, motion);            

        BluetoothGattCharacteristic voltage = pucService.getCharacteristic(VOLTAGE_READ);
        if (voltage == null) {
            showMessage("charateristic not found!");
            return;
        }
        enableNotification(true, voltage);


        BluetoothGattCharacteristic pressure = pucService.getCharacteristic(PRESSURE_READ);
        if (pressure == null) {
            showMessage("charateristic not found!");
            return;
        }
        enableNotification(true, pressure);
    }

The following is the enablenotification method:

    public boolean enableNotification(boolean enable, BluetoothGattCharacteristic characteristic) {
    if (mBluetoothGatt == null)
        return false;
    if (!mBluetoothGatt.setCharacteristicNotification(characteristic, enable))
        return false;

    BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(CCC);
    if (clientConfig == null)
        return false;

    if (enable) {
         Log.i(TAG,"enable notification");
        clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    } else {
        Log.i(TAG,"disable notification");
        clientConfig.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
    }
    return mBluetoothGatt.writeDescriptor(clientConfig);
}

resolvent:

I just realized that this problem was solved by miznick in the second answer of this post. It is mainly because Samsung ble API performs synchronization. Basically, the API can only process 1 GATT instruction at a time, such as write / read feature, w / R descriptor, etc. by calling w / R GATT method, it is like attaching GATT instruction to the system waiting for execution. After execution, the system will activate a related callback method, Such as oncharacterwrite, ondescriptorwrite, etc. only at or after this point should we use another GATT w / R method. The code is given in miznick's post

This post can also be used to understand the behavior of Samsung ble API. Please check the guidelines and tips on Samsung ble's official website

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>