From a1f0056088572ce373e67b7a139048c6ec47aa8b Mon Sep 17 00:00:00 2001 From: "Matthias@Dell" Date: Wed, 14 Jun 2023 13:53:25 +0200 Subject: [PATCH] host script with bleak --- host/main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 host/main.py diff --git a/host/main.py b/host/main.py new file mode 100644 index 0000000..0524ba0 --- /dev/null +++ b/host/main.py @@ -0,0 +1,42 @@ +import bleak as b +import asyncio + +TARGET_NAME = "ArduinoTENG" +TARGET_ADRESS = "C8:C9:A3:E6:08:3A" + +def disconnect_callback(client: b.BleakClient): + print(f"Disconnected {client}") + +async def main(): + # devices = await b.BleakScanner.discover(return_adv=False) + # # print(devices) + # target_device = None + # for adr, (device, adv_data) in devices.items(): + # if device.name == TARGET_NAME: + # print(adv_data) + # target_device = device + # break + # if target_device is None: + # print("ERROR: Could not find target device") + # return + # print(f"Found target device: {target_device.name}: {target_device.metadata}, {target_device.details}") + # print(target_device.name, target_device.details) + # async with b.BleakClient(target_device) as client: + # # print(f"Connected to {client}") + # print(f"Services: {await client.services}") + scanner = b.BleakScanner() + scanner.start() + target_device = TARGET_ADRESS + client = b.BleakClient(target_device) + try: + await client.connect() + # print(client.services) + except b.BleakError as e: + print(e) + finally: + await client.disconnect() + scanner.stop() + + +if __name__ == "__main__": + asyncio.run(main())