28 lines
696 B
Python
28 lines
696 B
Python
import asyncio
|
|
|
|
import bleak.exc
|
|
from bleak import BleakScanner
|
|
from bleak.backends.device import BLEDevice
|
|
from bleak.backends.scanner import AdvertisementData
|
|
|
|
|
|
def discover_callback(device: BLEDevice, advertising_data: AdvertisementData):
|
|
print(
|
|
f"[{advertising_data.rssi:-4d}] {device.address} - {device.name} with {len(advertising_data.service_uuids)} services"
|
|
)
|
|
|
|
|
|
async def discover_devices():
|
|
stop_event = asyncio.Event()
|
|
|
|
async with BleakScanner(discover_callback):
|
|
await stop_event.wait()
|
|
|
|
|
|
def run():
|
|
print("scanner called")
|
|
try:
|
|
asyncio.run(discover_devices())
|
|
except bleak.exc.BleakDBusError as exc:
|
|
print(f"ERROR: {exc}")
|