-l to list ble devices

This commit is contained in:
Florent 2025-04-24 14:50:42 +02:00
parent 093a2a7c2c
commit ec44c93659
3 changed files with 16 additions and 4 deletions

View file

@ -37,6 +37,9 @@ Arguments mostly deals with ble connection
<pre>
-h : prints this help
-j : json output
-D : print debug messages
-S : BLE device selector
-l : lists BLE devices
-a &lt;address&gt; : specifies device address (can be a name)
-d &lt;name&gt; : filter meshcore devices with name or address
-t &lt;hostname&gt; : 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 &lt;param&gt; : gets a param, \"get help\" for more
set &lt;param&gt; &lt;value&gt; : sets a param, \"set help\" for more
get &lt;param&gt; : gets a param, "get help" for more
set &lt;param&gt; &lt;value&gt; : sets a param, "set help" for more
time &lt;epoch&gt; : sets time to given epoch
clock : get current time
clock sync : sync device clock st

View file

@ -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" },
]

View file

@ -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 <address> : specifies device address (can be a name)
-d <name> : filter meshcore devices with name or address
-t <hostname> : 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 = []