【问题标题】:Set characteristic notification on Mac BLE Central for an Android(6.0) BLE peripheral characteristics fails在 Mac BLE Central 上为 Android(6.0) BLE 外围设备特性设置特性通知失败
【发布时间】:2017-01-01 21:56:24
【问题描述】:

问题:

我将 Mac book (OS X 10.11.6) 作为 BLE Central 设备,而 Android Phone (Os 6.0) 作为 Peripheral 设备。

Android Peripheral 宣传 characteristic-1 的属性 BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_NOTIFY

Mac book(BLE Central) 成功发现具有 characteristic-1 的 Android Peripheral。 但是,当 BLE Central 尝试对此特征执行 setNotifyValue:YES 时失败并出现以下错误。

更改通知状态时出错:Error Domain=CBErrorDomain Code=0 “未知错误。” UserInfo={NSLocalizedDescription=未知错误。}

以防万一,如果外围设备是具有相似特征的 iPhone(iOS),则 setNotifyValue:YES 成功。

我为 characteristic-1 尝试了以下组合与

1- BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_INDICATE

2- BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY

3- BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_INDICATE

但不幸的是,它们都不起作用。

有人可以帮我在 Mac OS X Central for Android Peripheral 特性上将 notifiable 设置为 YES 吗?

【问题讨论】:

    标签: android ios macos


    【解决方案1】:

    在 android 上,您需要设置描述符来启用通知。

        BluetoothGattService gattService = new BluetoothGattService(YOUR_SERVICE_UUID,
                BluetoothGattService.SERVICE_TYPE_PRIMARY);
    
        BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(YOUR_CHARACTERISTIC_UUID,
                BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_INDICATE, BluetoothGattCharacteristic.PERMISSION_WRITE);
        BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor(UUID.fromString("00002902-0000-1000-8000-00805F9B34FB"),
                BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE);
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        characteristic.addDescriptor(descriptor);
    
        gattService.addCharacteristic(characteristic);
    

    【讨论】:

    • 没有。这行不通。我试过上面的方法。这是 MAC 端 BLE 扫描仪的错误:Error changing notification state:Error Domain=CBErrorDomain Code=1 "One or more parameters were invalid." UserInfo={NSLocalizedDescription=One or more parameters were invalid.}
    • 确保您使用“00002902-0000-1000-8000-00805F9B34FB”作为描述符 UUID。它对我有用。
    • 好的。为什么我们不能使用上述 UUID 以外的 UUID?
    • 现在可以使用了吗?根据 BLE 规范,该 UUID 用于订阅。
    • 错误不再出现。但是,如果我向此特征写入一些消息,则它不会到达 MAC 端扫描仪。我是否需要写给描述符而不是特征本身
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多