-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover_bluetooth.py
More file actions
35 lines (26 loc) · 1.04 KB
/
discover_bluetooth.py
File metadata and controls
35 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""Simple script to discover Bluetooth devices and print their names."""
import asyncio
from bleak import BleakScanner
async def discover_devices(timeout: float = 10.0) -> None:
"""Discover nearby Bluetooth devices and print their names."""
print(f"Scanning for Bluetooth devices (timeout: {timeout}s)...")
print("-" * 50)
devices = await BleakScanner.discover(timeout=timeout)
if not devices:
print("No Bluetooth devices found.")
print("Make sure Bluetooth is enabled and devices are in range.")
return
print(f"\nFound {len(devices)} device(s):\n")
for i, device in enumerate(devices, 1):
name = device.name or "Unknown"
address = device.address
print(f"{i}. {name} ({address})")
if __name__ == "__main__":
try:
asyncio.run(discover_devices())
except KeyboardInterrupt:
print("\nScan interrupted by user.")
except Exception as e:
print(f"Error: {e}")
print("\nMake sure Bluetooth is enabled on your system.")