From 14813e5c76dceee1b39634ab9bc9311f902d339b Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 11 Mar 2024 17:00:49 -0500 Subject: [PATCH] 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 0077ce0..3e10255 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -984,6 +984,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 afa8dd1..d4f82c8 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -32,7 +32,8 @@ class SerialInterface(StreamInterface): 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}"