Scan for Bluetooth Low Energy devices, explore GATT services and characteristics, and perform read/write/notify operations.
navigator.bluetooth.requestDevice() to prompt the user to select a BLE device. Requires a user gesture.Connect to a device and click "Discover Services" to explore.
User cancelled the device picker or no matching device found.
try {
device = await navigator.bluetooth.requestDevice(opts);
} catch (e) {
if (e.name === 'NotFoundError') {
// User cancelled or no device
}
}
Not in a secure context (HTTPS) or missing user gesture.
// Must be called from user interaction
button.onclick = () => {
navigator.bluetooth.requestDevice(opts);
};
GATT connection failed. Device may be out of range.
device.gatt.connect().catch(e => {
if (e.name === 'NetworkError') {
// Retry or notify user
}
});
Requested service/characteristic not available on device.
// Always list required services in filters // and optional services in optionalServices