Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web Bluetooth demo</title>
</head>
<body>
<button id="go">Go Bluetooth</button>
<script>
document.querySelector('#go').onclick = (e) => {
e.preventDefault();
// Use the same service UUID as in mbed here!
navigator.bluetooth.requestDevice({ filters: [{ services: [ 0x8765 ] }] })
.then(device => {
console.log('Found device ' + device.name);
return device.connectGATT();
)
.then(() =>
alert('Connected over GATT!');
});
.catch(err => {
alert('' + err + ' ' + JSON.stringify(err));
});
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment