Skip to content

Commit 5f629cd

Browse files
committed
timeout option for scan (default 2s)
1 parent ec44c93 commit 5f629cd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "meshcore-cli"
7-
version = "0.6.17"
7+
version = "0.6.18"
88
authors = [
99
{ name="Florent de Lamotte", email="[email protected]" },
1010
]

src/meshcore_cli/meshcore_cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ def usage () :
12701270
-D : debug
12711271
-S : performs a ble scan and ask for device
12721272
-l : list available ble devices and exit
1273+
-T <timeout> : timeout for the ble scan (-S and -l) default 2s
12731274
-a <address> : specifies device address (can be a name)
12741275
-d <name> : filter meshcore devices with name or address
12751276
-t <hostname> : connects via tcp/ip
@@ -1289,13 +1290,14 @@ async def main(argv):
12891290
hostname = None
12901291
serial_port = None
12911292
baudrate = 115200
1293+
timeout = 2
12921294
# If there is an address in config file, use it by default
12931295
# unless an arg is explicitely given
12941296
if os.path.exists(MCCLI_ADDRESS) :
12951297
with open(MCCLI_ADDRESS, encoding="utf-8") as f :
12961298
address = f.readline().strip()
12971299

1298-
opts, args = getopt.getopt(argv, "a:d:s:ht:p:b:jDhSl")
1300+
opts, args = getopt.getopt(argv, "a:d:s:ht:p:b:jDhSlT:")
12991301
for opt, arg in opts :
13001302
match opt:
13011303
case "-d" : # name specified on cmdline
@@ -1318,16 +1320,18 @@ async def main(argv):
13181320
case "-h" :
13191321
usage()
13201322
return
1323+
case "-T" :
1324+
timeout = float(arg)
13211325
case "-l" :
1322-
devices = await BleakScanner.discover()
1326+
devices = await BleakScanner.discover(timeout=timeout)
13231327
if len(devices) == 0:
13241328
logger.error("No ble device found")
13251329
for d in devices :
13261330
if d.name.startswith("MeshCore-"):
13271331
print(f"{d.address} {d.name}")
13281332
return
13291333
case "-S" :
1330-
devices = await BleakScanner.discover()
1334+
devices = await BleakScanner.discover(timeout=timeout)
13311335
choices = []
13321336
for d in devices:
13331337
if d.name.startswith("MeshCore-"):

0 commit comments

Comments
 (0)