From efe868b8995954b419c963fa33a36efe3c3d9b92 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 11 Mar 2024 17:00:49 -0500 Subject: [PATCH 1/2] Attempt TCP connection to localhost if serial detect fails --- meshtastic/__main__.py | 10 ++++++++++ meshtastic/serial_interface.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 6a2f31c4..5dcde56d 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -981,6 +981,16 @@ def common(): message += " After running that command, log out and re-login for it to take effect.\n" message += f"Error was:{ex}" meshtastic.util.our_exit(message) + if client.devPath is None: + try: + client = meshtastic.tcp_interface.TCPInterface( + "localhost", debugOut=logfile, noProto=args.noproto + ) + except Exception as ex: + meshtastic.util.our_exit( + f"Error connecting to localhost:{ex}", 1 + ) + # We assume client is fully connected now onConnected(client) diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index afa8dd17..d4f82c8a 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -32,7 +32,8 @@ def __init__(self, devPath=None, debugOut=None, noProto=False, connectNow=True): ports = meshtastic.util.findPorts(True) logging.debug(f"ports:{ports}") if len(ports) == 0: - meshtastic.util.our_exit("Warning: No Meshtastic devices detected.") + print("No Serial Meshtastic device detected, attempting TCP connection on localhost.") + return elif len(ports) > 1: message = "Warning: Multiple serial ports were detected so one serial port must be specified with the '--port'.\n" message += f" Ports detected:{ports}" From ec083b8b2bb926a39ab2c32f169ef43c3a2b36b7 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 11 Mar 2024 18:25:54 -0500 Subject: [PATCH 2/2] Document automatic device search --- meshtastic/__main__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 5dcde56d..40128e8b 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -1026,7 +1026,7 @@ def initParser(): parser.add_argument( "--port", - help="The port the Meshtastic device is connected to, i.e. /dev/ttyUSB0. If unspecified, we'll try to find it.", + help="The port the Meshtastic device is connected to, i.e. /dev/ttyUSB0.", default=None, ) @@ -1378,7 +1378,9 @@ def initParser(): def main(): """Perform command line meshtastic operations""" our_globals = Globals.getInstance() - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser( + epilog="If neither --port nor --host are specified, we search for a compatible serial device, " + "and if none is found, then attempt a TCP connection to localhost.") our_globals.set_parser(parser) initParser() common()