无法在 Web BLE API 中传递配对密钥

问题描述

我有一个外围设备,需要与引脚配对才能访问其特性或执行读/写操作。 这是我到目前为止所做的代码片段。

const server = await device.gatt.connect();
console.log(`Bluetooth: Got server:`,server);

const service = await server.getPrimaryService(currentService.uuid);
let characteristic2 = await this.state.service.getCharacteristic(
  currentService.characteristicsUUID[1]
);
await characteristic2.writeValue(new Int8Array([1]).buffer);

它表明特性Attrib2.writeValue()不被允许,即使读写访问是由该服务的特性提供的,因为设备没有使用pin配对。我只是想知道 web-ble 中是否有任何 API 使用它浏览器可以在与设备配对时请求 PIN?并且只有在与该引脚配对后,它才会提供对外围设备的访问。

解决方法

Chromium 团队目前正在努力在必要时添加对与设备配对的支持,以访问受保护的特征。这目前在 Android 和 macOS 上会自动发生,但不会在 Windows、Linux 和 Chrome 操作系统上发生。

关注this issue以获取更新。