diff --git a/.vscode/launch.json b/.vscode/launch.json index d5d1311..83c15a3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,6 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { "name": "meshtastic BLE", "type": "python", @@ -21,6 +20,14 @@ "justMyCode": true, "args": ["--debug", "--info"] }, + { + "name": "meshtastic setpref", + "type": "python", + "request": "launch", + "module": "meshtastic", + "justMyCode": true, + "args": ["--debug", "--setpref", "a", "1", "--setpref", "b", "2"] + }, { "name": "meshtastic shell", "type": "python", @@ -35,7 +42,7 @@ "request": "launch", "module": "meshtastic", "justMyCode": true, - "args": [ "--debug", "--test"] + "args": ["--debug", "--test"] }, { "name": "meshtastic sendtext", diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index f46844e..3d1e9ec 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -36,9 +36,15 @@ def onConnected(interface): wantAck=True, wantResponse=True) if args.setpref: - name = args.setpref[0] - val = int(args.setpref[1]) - setattr(interface.radioConfig.preferences, name, val) + for pref in args.setpref: + name = pref[0] + print(f"Setting preference {name} to {pref[1]}") + # FIXME, currently this tool only supports setting integers + try: + val = int(pref[1]) + setattr(interface.radioConfig.preferences, name, val) + except Exception as ex: + print(f"Can't set {name} due to {ex}") print("Writing modified preferences to device...") interface.writeConfig() @@ -85,7 +91,8 @@ def main(): parser.add_argument("--info", help="Read and display the radio config information", action="store_true") - parser.add_argument("--setpref", help="Set a preferences field", nargs=2) + parser.add_argument( + "--setpref", help="Set a preferences field", nargs=2, action='append') parser.add_argument( "--dest", help="The destination node id for the --send commands, if not set '^all' is assumed", default="^all")