【问题标题】:writing to GATT descriptor produces write not permitted error写入 GATT 描述符会产生不允许写入错误
【发布时间】:2021-07-02 15:37:08
【问题描述】:

我正在使用 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() 方法每次都会超时。

【问题讨论】:

    标签: bluetooth-lowenergy bluez bluetooth-gatt


    【解决方案1】:

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

    【讨论】:

    • 所以你的意思是只使用 enableValueNotifications()?因为这样做总是会导致 SIGSEV 致命错误,这就是我开始尝试写入描述符的原因。
    • 是的,是有特点的方法。看起来它在 Tinyb 中被称为 enableValueNotifications()
    • 是的,我发现在您发表评论后的 bluez 文档中,enableValueNotifications() 绝对是正确的方法。以正确的方式执行它仍然会为我生成 SIGSEV,如果您知道为什么这会很棒,否则我将使用轮询。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 2019-06-20
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多