|
9 | 9 | import logging |
10 | 10 | import requests |
11 | 11 | from bleak import BleakScanner, BleakClient |
| 12 | +from bleak.exc import BleakError |
12 | 13 | import serial.tools.list_ports |
13 | 14 | from pathlib import Path |
14 | 15 | import traceback |
|
23 | 24 | from meshcore import MeshCore, EventType, logger |
24 | 25 |
|
25 | 26 | # Version |
26 | | -VERSION = "v1.1.40" |
| 27 | +VERSION = "v1.1.41" |
27 | 28 |
|
28 | 29 | # default ble address is stored in a config file |
29 | 30 | MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/" |
@@ -2600,23 +2601,30 @@ async def main(argv): |
2600 | 2601 | return |
2601 | 2602 | case "-l" : |
2602 | 2603 | print("BLE devices:") |
2603 | | - devices = await BleakScanner.discover(timeout=timeout) |
2604 | | - if len(devices) == 0: |
2605 | | - print(" No ble device found") |
2606 | | - for d in devices : |
2607 | | - if not d.name is None and d.name.startswith("MeshCore-"): |
2608 | | - print(f" {d.address} {d.name}") |
| 2604 | + try : |
| 2605 | + devices = await BleakScanner.discover(timeout=timeout) |
| 2606 | + if len(devices) == 0: |
| 2607 | + print(" No ble device found") |
| 2608 | + for d in devices : |
| 2609 | + if not d.name is None and d.name.startswith("MeshCore-"): |
| 2610 | + print(f" {d.address} {d.name}") |
| 2611 | + except BleakError: |
| 2612 | + print(" No BLE HW") |
2609 | 2613 | print("\nSerial ports:") |
2610 | 2614 | ports = serial.tools.list_ports.comports() |
2611 | 2615 | for port, desc, hwid in sorted(ports): |
2612 | 2616 | print(f" {port:<18} {desc} [{hwid}]") |
2613 | 2617 | return |
2614 | 2618 | case "-S" : |
2615 | | - devices = await BleakScanner.discover(timeout=timeout) |
2616 | 2619 | choices = [] |
2617 | | - for d in devices: |
2618 | | - if not d.name is None and d.name.startswith("MeshCore-"): |
2619 | | - choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}")) |
| 2620 | + |
| 2621 | + try : |
| 2622 | + devices = await BleakScanner.discover(timeout=timeout) |
| 2623 | + for d in devices: |
| 2624 | + if not d.name is None and d.name.startswith("MeshCore-"): |
| 2625 | + choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}")) |
| 2626 | + except BleakError: |
| 2627 | + logger.info("No BLE Device") |
2620 | 2628 |
|
2621 | 2629 | ports = serial.tools.list_ports.comports() |
2622 | 2630 | for port, desc, hwid in sorted(ports): |
|
0 commit comments