From bf2ae303bdd3b69be69eba4962f154baaed98cfd Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Fri, 7 Feb 2025 21:38:41 +0000 Subject: add functionality to connect to device and find characteristics and properties --- src/connect.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/connect.py (limited to 'src/connect.py') diff --git a/src/connect.py b/src/connect.py new file mode 100644 index 0000000..dadf147 --- /dev/null +++ b/src/connect.py @@ -0,0 +1,22 @@ +from bleak import BleakClient, BleakScanner +from logger import get_logger + +logger = get_logger("Connection") + +async def connect(address): + try: + async with BleakClient(address) as client: + if client.is_connected: + logger.info("Connection successful!") + + services = await client.get_services() + for service in services: + logger.info(f"Service: {service.uuid}") + for char in service.characteristics: + logger.info(f" └── Characteristic: {char.uuid}, Properties: {char.properties}") + return client + else: + logger.error("Failed to connect!") + except Exception as e: + logger.error(f"Connection error: {e}") + raise \ No newline at end of file -- cgit v1.2.3