bluetooth-lowenergy - 写入 GATT 描述符会产生不允许写入错误
问题描述
我正在使用 java TinyB通过蓝牙 LE连接到TimeFlip设备。
当尝试写入 Facet Characteristic 的描述符以接收通知时,我总是收到错误消息:
线程“main” tinyb.BluetoothException 中的异常:GDBus.Error:org.bluez.Error.NotPermitted:不允许写入
但是当我使用 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 将为您编写描述符,但如果您尝试自己编写,它确实会出错。
推荐阅读
- reactjs - 反应 useState 更新未使用自定义钩子触发
- python - Django:没有这样的表:users_profile
- google-apps-script - 无法从键盘输入文本到已经包含代码的脚本编辑器窗口
- c++ - 如何在一行中分配向量中的所有对象?面向对象 C++
- jmeter - 如何在 1 小时内为 1000 个并发用户实现 65/小时的目标吞吐量?
- javascript - 在托管非跨域上执行的 Tampermonkey 脚本
- php - 在 php 中使用 PDO 通过 json_encode 输出
- python - 使用 numpy 数组将文本覆盖到 OMXPlayer
- angular - 如何使用paystack向我的离子角度应用程序添加定期支付系统?
- javascript - ReactJS - 如何将数据发送到 PayPal 按钮?