微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

重新连接到已知且已配对的Web蓝牙设备

如何解决重新连接到已知且已配对的Web蓝牙设备

我有一个Web应用程序,可以打印到蓝牙热敏打印机。我设法连接到打印机并打印出我需要的东西。我想知道是否有一种方法可以将设备信息保存到会话或本地存储中,因此不需要用户每次都与设备配对。

我当前的代码如下:

    const device = await navigator.bluetooth.requestDevice({
      acceptAllDevices: true,optionalServices: [
        '000018f0-0000-1000-8000-00805f9b34fb'
      ]
    });

    const server = await device.gatt.connect();
    const service = await server.getPrimaryService("000018f0-0000-1000-8000-00805f9b34fb");
    const characteristic = await service.getCharacteristic("00002af1-0000-1000-8000-00805f9b34fb");

想法是像这样:

const device = await navigator.bluetooth.connect(deviceid);
// using the device's ID or address,name or whatever information is available from the first pairing.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。