Files
mesh-network-project/desktop_app/api/node.py

23 lines
788 B
Python
Raw Normal View History

2026-03-08 07:40:27 +11:00
from bleak import BleakScanner, BleakClient
2026-03-07 10:38:18 +11:00
NODE_BLUETOOTH_SERVICE_UUID = "E1898FF7-5063-4441-a6eb-526073B00001"
2026-03-08 07:40:27 +11:00
NODE_BLUETOOTH_RX_UUID = "E1898FF7-5063-4441-a6eb-526073B00002"
NODE_BLUETOOTH_TX_UUID = "E1898FF7-5063-4441-a6eb-526073B00003"
2026-03-07 10:38:18 +11:00
class MeshNode:
2026-03-07 14:22:06 +11:00
def __init__(self, client: BleakClient):
self.client = client
2026-03-08 07:40:27 +11:00
self.client.pair()
2026-03-07 10:38:18 +11:00
async def discover():
"""Find a mesh node via Bluetooth
"""
2026-03-07 14:22:06 +11:00
devices = await BleakScanner.discover(service_uuids=[NODE_BLUETOOTH_SERVICE_UUID], timeout=5)
2026-03-07 10:38:18 +11:00
# no device was found
if len(devices) == 0:
2026-03-07 14:22:06 +11:00
return None
device = await BleakScanner.find_device_by_address(devices[0].address, timeout=5)
return MeshNode(BleakClient(device))