You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java TinyB写GATT描述符启用TimeFlip通知报无权限 gatttool正常如何解决?

问题描述
  • 使用Java TinyB连接TimeFlip蓝牙低功耗(BLE)设备。
  • 尝试写入Facet特征的描述符以接收通知时,始终出现如下错误:

Exception in thread "main" tinyb.BluetoothException: GDBus.Error:org.bluez.Error.NotPermitted: Write not permitted

  • 同一操作场景下,使用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));  
// 按原生find方式查找得到的facetsConfig始终为null,自定义方法可正常获取

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

try{
    byte[] enableNotifications = {0x01, 0x00};
    facetsConfig.writeValue(enableNotifications);           
    // 使用自定义方法为facetsConfig赋值时,写入操作会抛出无权限错误
    facets.enableValueNotifications(new FacetNotification());
}
catch(NullPointerException e){
    log.error("NullPointerException in " + (facets == null ? "facet characteristic" : "facet descriptor"));
}
catch(BluetoothException b){
    log.error(b.getMessage());
}

补充现象说明

  • 由于TinyB原生的find()方法每次调用都会超时,因此实现了自定义查找逻辑:先获取某特征下的所有描述符,再返回与指定UUID匹配的项,通过该逻辑可以正常获取到目标描述符。
  • 即便拿到了有效的目标描述符对象,调用writeValue方法写入通知使能配置时,仍然会抛出无权限错误,但完全相同的写入操作通过gatttool执行时无任何异常。

内容的提问来源于stack exchange,提问作者Moritz Perschke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.27 04:24:04