Skip to content

Commit 4f1ea5b

Browse files
authored
Merge pull request #616 from meshtastic/ble-logging
Adds support for ble logging characteristic
2 parents 18883b9 + 5c2851d commit 4f1ea5b

5 files changed

Lines changed: 229 additions & 171 deletions

File tree

.vscode/launch.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
"request": "launch",
1111
"module": "meshtastic",
1212
"justMyCode": false,
13-
"args": ["--debug", "--ble", "24:62:AB:DD:DF:3A"]
13+
"args": ["--ble", "Meshtastic_9f6e"]
14+
},
15+
{
16+
"name": "meshtastic BLE scan",
17+
"type": "python",
18+
"request": "launch",
19+
"module": "meshtastic",
20+
"justMyCode": false,
21+
"args": ["--debug", "--ble-scan"]
1422
},
1523
{
1624
"name": "meshtastic admin",
@@ -76,6 +84,14 @@
7684
"justMyCode": true,
7785
"args": ["--debug", "--info"]
7886
},
87+
{
88+
"name": "meshtastic debug BLE",
89+
"type": "python",
90+
"request": "launch",
91+
"module": "meshtastic",
92+
"justMyCode": true,
93+
"args": ["--debug", "--ble", "--info"]
94+
},
7995
{
8096
"name": "meshtastic debug set region",
8197
"type": "python",

meshtastic/__main__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,16 +1042,11 @@ def common():
10421042
subscribe()
10431043
if args.ble_scan:
10441044
logging.debug("BLE scan starting")
1045-
client = BLEInterface(None, debugOut=logfile, noProto=args.noproto)
1046-
try:
1047-
for x in client.scan():
1048-
print(f"Found: name='{x[1].local_name}' address='{x[0].address}'")
1049-
finally:
1050-
client.close()
1045+
for x in BLEInterface.scan():
1046+
print(f"Found: name='{x.name}' address='{x.address}'")
10511047
meshtastic.util.our_exit("BLE scan finished", 0)
1052-
return
10531048
elif args.ble:
1054-
client = BLEInterface(args.ble, debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes)
1049+
client = BLEInterface(args.ble if args.ble != "any" else None, debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes)
10551050
elif args.host:
10561051
try:
10571052
client = meshtastic.tcp_interface.TCPInterface(
@@ -1119,8 +1114,10 @@ def addConnectionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParse
11191114

11201115
group.add_argument(
11211116
"--ble",
1122-
help="The BLE device address or name to connect to",
1117+
help="Connect to a BLE device, optionally specifying a device name (defaults to 'any')",
1118+
nargs="?",
11231119
default=None,
1120+
const="any"
11241121
)
11251122

11261123
return parser

0 commit comments

Comments
 (0)