I need to get a Bluetooth address of a device that is connecting to my site. Here is a couple of questions:
- Can it be achieved with Bluetooth API only? If not, which way could I use to do what I described above?
- About that API. Let’s imagine a situation. I have a phone. Bluetooth is turned on. I’m visiting my website and I need to get BT address of my phone. Could this code work out:
const button = document.querySelector('#the-button');
button.addEventListener('click', function() {
navigator.bluetooth.requestDevice({
filters: [{
services: ['battery_service']
}]
}).then(device => {
console.log('Got device:', device.name);
console.log('id:', device.id);
});
});
I can’t understand if I have to connect my phone to another device or all I have to do is using the above code. So, generally, there are 2 questions I want to ask: 1. Are there any other ways to get BT address of a device besides Bluetooth API? 2. How many devices do I need to use BT API?