bluetooth-lowenergy - 写入 GATT 描述符会产生写入不允许错误

标签 bluetooth-lowenergy bluez bluetooth-gatt

我正在使用 java TinyB 连接到 TimeFlip具有蓝牙 LE 的设备。

当尝试写入构面特征的描述符以接收通知时,我总是收到错误:

线程“主”tinyb.BluetoothException 中出现异常:GDBus.Error:org.bluez.Error.NotPermission: 不允许写入

但是当我使用 gatttool 写入同一个描述符时,它可以工作并且我收到通知。

        BluetoothGattService timeFlipService = device.find("f1196f50-71a4-11e6-bdf4-0800200c9a66", Duration.ofSeconds(5));
        BluetoothGattCharacteristic facets = timeFlipService.find("f1196f52-71a4-11e6-bdf4-0800200c9a66", Duration.ofSeconds(5));
        BluetoothGattDescriptor facetsConfig = facets.find("00002902-0000-1000-8000-00805f9b34fb", Duration.ofSeconds(5));  // like this ==> always null, custom method works???

        if(!login(timeFlipService)) {log.error("login to TimeFlip failed");}

        try{
            byte[] enableNotifications = {0x01, 0x00};
            facetsConfig.writeValue(enableNotifications);           //when facesConfig assigned with custom method throws write not permitted error
            facets.enableValueNotifications(new FacetNotification());
        }
        catch(NullPointerException e){
            log.error("NullPointerException in " + (facets == null ? "facet characteristic" : "facet descriptor"));
        }
        catch(BluetoothException b){
            log.error(b.getMessage());
        }
    }

提到的“自定义方法”只是从特征中获取所有描述符并返回与给定 uuid 匹配的描述符,因为 find() 方法每次都会超时。

最佳答案

在 Bluez 中,您应该使用 StartNotify 来打开通知或指示。 Bluez 将为您编写描述符,但如果您尝试自己编写,它确实会出错。

关于bluetooth-lowenergy - 写入 GATT 描述符会产生写入不允许错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66975651/

相关文章:

java - Android 如何使用 PriorityQueue 读取多个 BLE 特征

java - 在 A17-Realtag-BLE-Sensor-Wearable 上获取温度或压力

c - 如何限制通过蓝牙连接到设备的手机数量?

java - 在android studio中,在调试应用程序BluetoothLeGatt时,我得到了以下期望:

android - BluetoothGattServerCallback : onCharacteristicReadRequest() called multiple times

android - 如果值 len > MTU 大小,如何发送 BLE 特性通知?

linux - 从 Bluez 5.48 开始如何写入特性

ios - iOS 上的 BLE 广告和 CBAdvertisementDataLocalNameKey 大小

C代码中的蓝牙接口(interface)控制(Linux操作系统)

linux - 如何使用 bluez 在 Linux 上通过蓝牙 4.0 LE 连接到 FitBit Zip?