diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 6a2f31c4..40128e8b 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) @@ -1016,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, ) @@ -1368,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() 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}"