Javascript web蓝牙从设备GATT获取存储的数据

Javascript web蓝牙从设备GATT获取存储的数据,javascript,bluetooth-lowenergy,gatt,bluetooth-gatt,web-bluetooth,Javascript,Bluetooth Lowenergy,Gatt,Bluetooth Gatt,Web Bluetooth,我的目标是获取存储在设备中的数据 类似于测量温度或其他东西并将其存储到存储器中的装置。我需要通过记录访问控制点(RACP)查询所有这些数据设备 实现它的第一个想法是 获得特性 启动通知 将代码写入描述符 通过eventListener获取所有数据 结果:启动通知时引发错误 使用的示例: 下一个想法是不启动通知,因为特性是 指示,写入类型。 因此,我们考虑从设备文档中添加侦听器并写入描述符代码,其中说明: 操作码: 1–报告存储的记录 即使删除了startNotifications,行也会

我的目标是获取存储在设备中的数据

类似于测量温度或其他东西并将其存储到存储器中的装置。我需要通过记录访问控制点(RACP)查询所有这些数据设备

  • 实现它的第一个想法是

    • 获得特性

    • 启动通知

    • 将代码写入描述符

    • 通过eventListener获取所有数据

  • 结果:启动通知时引发错误 使用的示例:

  • 下一个想法是不启动通知,因为特性是 指示,写入类型。 因此,我们考虑从设备文档中添加侦听器并写入描述符代码,其中说明:
  • 操作码: 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操作因未知原因失败

    描述符的错误为:

    对标记为exclude writes的BlockList对象调用writeValue()

    此外,我的设备正在请求pin,但web正在连接,没有任何提示。所以可能它说写入描述符被阻止了

    如何处理pin输入-没有线索(一旦我在启用chrome实验功能后得到输入pin的提示,我不确定它是否相关)

    我的逻辑正确吗我不这么认为

    有什么建议吗

    到目前为止我调查了什么

  • 编辑:看完这篇文章-


    我认为正确的逻辑应该是,编写您需要的命令特性命令(如获取所有数据)。之后,从设备文档中找到负责此数据的正确特征,启动通知并添加eventListener并接收数据。

    调用
    writeValue()
    失败,因为无法访问CCCD。调用
    startNotifications()
    将根据需要写入描述符以启用通知


    我们需要调查
    startNotifications()
    失败的“未知原因”。您使用的是什么操作系统?请按照Chromium项目的问题跟踪程序中的说明操作并提交问题。

    调用
    writeValue()
    失败,因为无法访问CCCD。调用
    startNotifications()
    将根据需要写入描述符以启用通知


    我们需要调查
    startNotifications()
    失败的“未知原因”。您使用的是什么操作系统?请按照chrome项目的问题跟踪程序中的说明进行操作并提交问题。

    目前,chrome在windows 10上无法与受保护的特性进行通信,或者在macOS上无法与受保护的特性进行通信,这一切都工作得很好。我已经在chromium bug跟踪器上发布了这个问题,如果有人在观看它的话。

    就目前而言,chrome无法在windows 10上与受保护的特性进行通信,或者在macOS上无法与受保护的特性进行通信,这一切都很正常。我已经在chromium bug跟踪器上发布了这个问题,如果有人在观看它的话。

    在我切换到这里之后chrome://flags/#enable-实验性web平台功能已启用实验性功能已启用,i startNotifications现在触发良好,但我认为这两种方式都应该有效。我正在使用最新的Chrome和macOS。好的,所以我不必把值写入描述符,对吗?我该怎么说才能给我存储的数据呢?此外,根据文件,我可以根据操作代码获取记录或记录计数等。所以我想我应该把这段代码写在某个地方。到特征或哪里?在控制台中获取此信息:默认值10:39:48.549322+0300 Bluetooth******[handleATTErrorResponse]。错误10:39:48.549444+0300 bluetoothd******[handleATTErrorResponse]-身份验证不足。默认10:39:48.549615+0300 bluetoothd******[handleATTErrorResponse]-链接未加密,请执行与MITM disbled的配对。我在此处切换后chrome://flags/#enable-已启用实验性web平台功能已启用实验性功能,我开始通知现在触发很好,但我认为它应该以任何方式工作。我正在使用最新的Chrome和macOS。好的,所以我不必把值写入描述符,对吗?我该怎么说才能给我存储的数据呢?此外,根据文件,我可以根据操作代码获取记录或记录计数等。所以我想我应该把这段代码写在某个地方。到特征或哪里?在控制台中获取此信息:默认值10:39:48.549322+0300 Bluetooth******[handleATTErrorResponse]。错误10:39:48.549444+0300 bluetoothd******[handleATTErrorResponse]-身份验证不足。默认10:39:48.549615+0300 bluetoothd******[handleATTErrorResponse]-链接未加密,请与MITM disbled执行配对。