From ec44c936599aef81417bac27885cbf8587ed6d0c Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 24 Apr 2025 14:50:42 +0200 Subject: [PATCH] -l to list ble devices --- README.md | 7 +++++-- pyproject.toml | 2 +- src/meshcore_cli/meshcore_cli.py | 11 ++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 19009f3..4761ca8 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ Arguments mostly deals with ble connection
     -h : prints this help                                                                      
     -j : json output
+    -D : print debug messages
+    -S : BLE device selector
+    -l : lists BLE devices
     -a <address>    : specifies device address (can be a name)
     -d <name>       : filter meshcore devices with name or address
     -t <hostname>   : connects via tcp/ip
@@ -70,8 +73,8 @@ Commands are given after arguments, they can be chained and some have shortcuts.
   Management
     advert                 : sends advert                           a
     floodadv               : flood advert
-    get <param>            : gets a param, \"get help\" for more
-    set <param> <value>    : sets a param, \"set help\" for more 
+    get <param>            : gets a param, "get help" for more
+    set <param> <value>    : sets a param, "set help" for more 
     time <epoch>           : sets time to given epoch
     clock                  : get current time
     clock sync             : sync device clock                      st
diff --git a/pyproject.toml b/pyproject.toml
index 1da0008..7568e7a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
 
 [project]
 name = "meshcore-cli"
-version = "0.6.16"
+version = "0.6.17"
 authors = [
   { name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
 ]
diff --git a/src/meshcore_cli/meshcore_cli.py b/src/meshcore_cli/meshcore_cli.py
index 02136bd..6e19db8 100644
--- a/src/meshcore_cli/meshcore_cli.py
+++ b/src/meshcore_cli/meshcore_cli.py
@@ -1269,6 +1269,7 @@ def usage () :
     -j : json output
     -D : debug
     -S : performs a ble scan and ask for device
+    -l : list available ble devices and exit
     -a 
: specifies device address (can be a name) -d : filter meshcore devices with name or address -t : connects via tcp/ip @@ -1294,7 +1295,7 @@ async def main(argv): with open(MCCLI_ADDRESS, encoding="utf-8") as f : address = f.readline().strip() - opts, args = getopt.getopt(argv, "a:d:s:ht:p:b:jDhS") + opts, args = getopt.getopt(argv, "a:d:s:ht:p:b:jDhSl") for opt, arg in opts : match opt: case "-d" : # name specified on cmdline @@ -1317,6 +1318,14 @@ async def main(argv): case "-h" : usage() return + case "-l" : + devices = await BleakScanner.discover() + if len(devices) == 0: + logger.error("No ble device found") + for d in devices : + if d.name.startswith("MeshCore-"): + print(f"{d.address} {d.name}") + return case "-S" : devices = await BleakScanner.discover() choices = []