【问题标题】:How to read Generic Access service/characteristics using react-native-ble-manager如何使用 react-native-ble-manager 读取通用访问服务/特征
【发布时间】:2020-09-18 09:04:30
【问题描述】:

我在 Android 10 上有一个使用 react native 构建的客户端应用

Android SDK:
  API Levels: 23, 28
  Build Tools: 28.0.3
react: ^16.9.0 => 16.9.0
react-native: ^0.62.2 => 0.62.2

什么有效: 服务发现 连接 自定义(128 位)特性的读取/写入/通知

什么不起作用: 读取通用访问服务0x1800的特征

服务发现: BleManager.retrieveServices /snip/ “特征”:[{“特征”:“2a00”,“属性”:[对象],“服务”:“1800”}, 这是完整的设备名称特征。

我可以使用任何 BLE 客户端应用程序读取它,例如LightBlue,所以服务器端工作。

我已尝试读取 16 位短 UUID:

    BleManager.read(peripheral.id, 
      '1800', 
      '2a00').then((readData) => {
      console.log(readData);          
    }).catch((error) => {
      console.log(error); 
    });

还有完整的 128b 版本:

BleManager.read(peripheral.id, 
  '00001800-0000-1000-8000-00805f9b34fb', 
  '00002a00-0000-1000-8000-00805f9b34fb').then((readData) => {
  console.log(readData);          
}).catch((error) => {
  console.log(error); 
});

在这两种情况下都捕获错误“00002a00-0000-1000-8000-00805f9b34fb not found”。

请注意,相同的代码适用于我自己的自定义 UUID。 peripheral.id 是我的服务器外围设备的 MAC 地址。

有什么想法可能是错的吗?谢谢!

【问题讨论】:

  • 您的扫描有效吗?我的意思是设备发现?

标签: android react-native bluetooth-lowenergy bluetooth-gatt


【解决方案1】:

我发现了问题。这是一种竞争条件,在读取特征之前检索服务未完成。解决方案:

BleManager.retrieveServices(peripheral.id).then((peripheralInfo) => {
    BleManager.read(peripheral.id, 
      '1800', 
      '2a00').then((readData) => {
      console.log(readData);          
    }).catch((error) => {
      console.log(error); 
    });
})

【讨论】:

    猜你喜欢
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多