我的目标是将数据存储在设备中。
就像测量温度或其他任何东西的设备一样,将其存储在内存中。我需要通过记录访问控制点(RACP)查询所有这些数据设备。
结果:在启动通知示例时抛出错误:
https://googlechrome.github.io/samples/web-bluetooth/notifications-async-await.html https://bugs.chromium.org/p/chromium/issues/detail?id=664863
OP代码:1 - 报告存储的记录
即使删除了startNotifications行也会抛出错误,所以我的代码示例如下:
const mainService = 'my correct service uuid';
const characteristicUUID1 = 'my correct char uuid';
const characteristicUUID2 = 'my correct char uuid';
const descriptorUUID = '00002902-0000-1000-8000-00805f9b34fb';
let deviceCache = null;
let serverCache = null;
let serviceCache = null;
let characteristicCacheA = null;
let characteristicCacheB = null;
let descriptorCache = null;
try {
deviceCache = await navigator.bluetooth.requestDevice({ filters: [{ name: 'my device' }] });
console.log('Connecting to GATT Server...');
serverCache = await deviceCache.gatt.connect();
console.log('Getting Services...');
serviceCache = await serverCache.getPrimaryService(mainService);
console.log('Getting Characteristics A...');
characteristicCacheA = await serviceCache.getCharacteristic(characteristicUUID1);
console.log('Start Notifications A...');
await characteristicCacheA.startNotifications();
console.log('Getting Characteristics B...');
characteristicCacheB = await serviceCache.getCharacteristic(characteristicUUID2);
console.log('Start Notifications B...');
await characteristicCacheB.startNotifications();
console.log('Add event listener...');
characteristicCacheA.addEventListener('characteristicvaluechanged', this.handleNotifications);
console.log('Getting Descriptor...');
descriptorCache = await characteristicCacheA.getDescriptor(descriptorUUID);
console.log('Write value to descr...');
await descriptorCache.writeValue(new Uint8Array([1]));
} catch (error) {
console.log(error.message, 'error');
}
通知错误(具有实验性的chrome功能,不会引发错误):
错误:GATT操作因未知原因失败。
描述符错误是:
writeValue()调用标记为exclude-writes的blocklisted对象。
此外,我的设备要求pin,但网络连接没有提示任何东西。所以也许它说写入描述符被阻止了。
如何处理引脚输入 - 没有线索(一旦我启用chrome实验功能后我得到提示输入引脚不确定它是否相关)。
我的逻辑是否正确? - 不要这么认为。
有什么建议?
到目前为止我调查了什么?
编辑:阅读本文后 - https://medium.com/@devdevcharlie/experimenting-with-web-bluetooth-1f1176047ddd
我认为正确的逻辑应该是,写入您需要的命令特征命令(比如获取所有数据)。之后,从设备文档中找到负责此数据的正确特征,并启动通知并添加eventListener并接收数据。
对writeValue()
的调用失败了,因为访问CCCD是on the blocklist。对startNotifications()
的调用将根据需要写入描述符以启用通知。
我们需要调查startNotifications()
失败的这个“未知原因”。您使用什么操作系统?请按照reporting Web Bluetooth bugs的说明进行操作,并在Chromium项目的问题跟踪器中提交问题。
至于现在,Chrome无法或在Windows 10上与受保护特性进行通信时遇到问题,在macOS上它完全正常工作。如果有人在观看它,我已经在铬虫追踪器上发布了问题。 https://bugs.chromium.org/p/chromium/issues/detail?id=960258#c6