I have a web app which prints to a Bluetooth thermal printer. I managed to connect to the printer and print what I need just fine. I was wondering if there's a way to save the device info into the session or local storage, so the user isn't required to pair to the device every time.
My current code is as follows:
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");
The idea is to have something like:
const device = await navigator.bluetooth.connect(deviceId);
// using the device's ID or address, name or whatever information is available from the first pairing.