I'm trying to find my device listed under the bluetooth options when I am trying to use the Javascript Bluetooth API, but my device John's iPhone is not showing up for me to pair with. Really new at this, so was hoping to get some help on this issue.
I've linked the code below. All I see is null and unknown devices that fail to connect.
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault();
onButtonClick();
});
function onButtonClick() {
const options = {
"acceptAllDevices": true
}
navigator.bluetooth.requestDevice(options)
.then(device => {
log('> Name: ' + device.name);
log('> Id: ' + device.id);
log('> Connected: ' + device.gatt.connected);
})
.catch(error => {
log('Argh! ' + error);
});
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<button type="submit">Submit</button>
</form>
<script src="./index.js"></script>
</body>
</html>
Its console.log() instead of log()
Example:
...
navigator.bluetooth.requestDevice(options)
.then(device => {
console.log('> Name: ' + device.name);
console.log('> Id: ' + device.id);
console.log('> Connected: ' + device.gatt.connected);
})
.catch(error => {
console.log('Argh! ' + error);
...