javascript - 重新连接到已知和配对的网络蓝牙设备
问题描述
我有一个打印到蓝牙热敏打印机的网络应用程序。我设法连接到打印机并打印出我需要的东西。我想知道是否有办法将设备信息保存到会话或本地存储中,因此用户不需要每次都与设备配对。
我目前的代码如下:
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.
解决方案
推荐阅读
- git - 可以在“git-svn 克隆”而不是 SVN URL 上使用 SVN 存储库路径吗?
- c - 如何在 MacOS 11.1 上使用 Homebrew 安装 libuuid?
- scala - json4s 总是转义 unicode 字符 €
- android - How to tab indicator expand and contract dynamically - android studio
- r - How to make a single rowname bold using htmlTable
- reactjs - 反冲原子打字稿默认未定义
- javascript - 从 Promise 中获取数据
- javascript - ReactJS / Material-UI / Javascript:无法在 TableRow 上获得圆角边框
- python - 使用 Beautiful Soup 提取特定列表
- reactjs - 如何通过在react js中单击来删除特定元素