ansible/roles/bluetooth-monitor/files/bleak3.py

24 lines
619 B
Python

import asyncio
from bleak import BleakScanner
async def main():
stop_event = asyncio.Event()
# TODO: add something that calls stop_event.set()
def callback(device, advertising_data):
print("device", device.address, "advertising_data", advertising_data)
# TODO: do something with incoming data
pass
async with BleakScanner(callback, scanning_mode="active") as scanner:
# Important! Wait for an event to trigger stop, otherwise scanner
# will stop immediately.
await stop_event.wait()
# scanner stops when block exits
...
asyncio.run(main())