https://technologisttips.com/raspberry-pi-bluetooth/
sudo apt-get install bluetooth bluez
sudo apt-get install python-bluez
| <html> | |
| <head> | |
| <style> | |
| #log { | |
| display:block; | |
| width: 100%; | |
| height: 200px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <button onclick='onGetBluetoothDevicesButtonClick()'>get devices</button> | |
| <button onclick='onRequestBluetoothDeviceButtonClick()'>request devices</button> | |
| <textarea id="log"></textarea> | |
| <script> | |
| const textarea = document.getElementById('log'); | |
| function log(...args){ | |
| console.log(...args); | |
| textarea.value += `\n${JSON.stringify(args)}`; | |
| } | |
| function onGetBluetoothDevicesButtonClick() { | |
| log("Getting existing permitted Bluetooth devices..."); | |
| navigator.bluetooth | |
| .getDevices() | |
| .then((devices) => { | |
| log("> Got " + devices.length + " Bluetooth devices."); | |
| for (const device of devices) { | |
| log(" > " + device.name + " (" + device.id + ")"); | |
| } | |
| }) | |
| .catch((error) => { | |
| log("Argh! " + error); | |
| }); | |
| } | |
| function onRequestBluetoothDeviceButtonClick() { | |
| log("Requesting any Bluetooth device..."); | |
| navigator.bluetooth | |
| .requestDevice({ | |
| // filters: [...] <- Prefer filters to save energy & show relevant devices. | |
| acceptAllDevices: true, | |
| }) | |
| .then((device) => { | |
| log("> Requested " + device.name + " (" + device.id + ")"); | |
| }) | |
| .catch((error) => { | |
| log("Argh! " + error); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |
https://technologisttips.com/raspberry-pi-bluetooth/
sudo apt-get install bluetooth bluez
sudo apt-get install python-bluez