From 22942061b6ba422ac4ca7eb1448634167be66a31 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 6 Aug 2025 11:55:27 +0200 Subject: [PATCH] create ble cx from device instead of address when possible --- src/meshcore_cli/meshcore_cli.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/meshcore_cli/meshcore_cli.py b/src/meshcore_cli/meshcore_cli.py index 06c5224..41459f6 100644 --- a/src/meshcore_cli/meshcore_cli.py +++ b/src/meshcore_cli/meshcore_cli.py @@ -2119,6 +2119,7 @@ async def main(argv): json_output = JSON debug = False address = ADDRESS + device = None port = 5000 hostname = None serial_port = None @@ -2176,7 +2177,7 @@ async def main(argv): choices = [] for d in devices: if not d.name is None and d.name.startswith("MeshCore-"): - choices.append(({"type":"ble","address":d.address}, f"{d.address:<22} {d.name}")) + choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}")) ports = serial.tools.list_ports.comports() for port, desc, hwid in sorted(ports): @@ -2196,7 +2197,7 @@ async def main(argv): return if result["type"] == "ble": - address = result["address"] + device = result["device"] elif result["type"] == "serial": serial_port = result["port"] else: @@ -2215,7 +2216,7 @@ async def main(argv): elif not serial_port is None : # connect via serial port mc = await MeshCore.create_serial(port=serial_port, baudrate=baudrate, debug=debug, only_error=json_output) else : #connect via ble - if address is None or address == "" or len(address.split(":")) != 6 : + if device is None and (address is None or address == "" or len(address.split(":")) != 6) : logger.info(f"Scanning BLE for device matching {address}") devices = await BleakScanner.discover(timeout=timeout) found = False @@ -2223,14 +2224,21 @@ async def main(argv): if not d.name is None and d.name.startswith("MeshCore-") and\ (address is None or address in d.name) : address=d.address + device=d logger.info(f"Found device {d.name} {d.address}") found = True break + elif d.address == address : # on a mac, address is an uuid + device = d + logger.info(f"Found device {d.name} {d.address}") + found = True + break + if not found : logger.info(f"Couldn't find device {address}") return - mc = await MeshCore.create_ble(address=address, debug=debug, only_error=json_output) + mc = await MeshCore.create_ble(address=address, device=device, debug=debug, only_error=json_output) # Store device address in configuration if os.path.isdir(MCCLI_CONFIG_DIR) :