Files
mesh-network-project/desktop_app/api/node.py
2026-03-08 07:40:27 +11:00

23 lines
788 B
Python

from bleak import BleakScanner, BleakClient
NODE_BLUETOOTH_SERVICE_UUID = "E1898FF7-5063-4441-a6eb-526073B00001"
NODE_BLUETOOTH_RX_UUID = "E1898FF7-5063-4441-a6eb-526073B00002"
NODE_BLUETOOTH_TX_UUID = "E1898FF7-5063-4441-a6eb-526073B00003"
class MeshNode:
def __init__(self, client: BleakClient):
self.client = client
self.client.pair()
async def discover():
"""Find a mesh node via Bluetooth
"""
devices = await BleakScanner.discover(service_uuids=[NODE_BLUETOOTH_SERVICE_UUID], timeout=5)
# no device was found
if len(devices) == 0:
return None
device = await BleakScanner.find_device_by_address(devices[0].address, timeout=5)
return MeshNode(BleakClient(device))