From bf904c69068bfc2c4b544673e48a74e3d8b08a2f Mon Sep 17 00:00:00 2001 From: DJ Holt Date: Mon, 16 Sep 2024 23:24:03 -0600 Subject: [PATCH 1/2] Allow port number to be specified with tcp hostname --- meshtastic/__main__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 02d9abcb..8aff798a 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -1155,8 +1155,14 @@ def common(): ) elif args.host: try: + if ":" in args.host: + tcp_hostname, tcp_port = args.host.split(':') + else: + tcp_hostname = args.host + tcp_port = 4403 client = meshtastic.tcp_interface.TCPInterface( - args.host, + tcp_hostname, + portNumber=tcp_port, debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes, From 5cc9627e218501599295da3198059e9cf782687a Mon Sep 17 00:00:00 2001 From: DJ Holt Date: Mon, 16 Sep 2024 23:41:44 -0600 Subject: [PATCH 2/2] Refactor default port number to variable --- meshtastic/__main__.py | 2 +- meshtastic/tcp_interface.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 8aff798a..a2b0e5c0 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -1159,7 +1159,7 @@ def common(): tcp_hostname, tcp_port = args.host.split(':') else: tcp_hostname = args.host - tcp_port = 4403 + tcp_port = meshtastic.tcp_interface.DEFAULT_TCP_PORT client = meshtastic.tcp_interface.TCPInterface( tcp_hostname, portNumber=tcp_port, diff --git a/meshtastic/tcp_interface.py b/meshtastic/tcp_interface.py index d049dc44..7b588c67 100644 --- a/meshtastic/tcp_interface.py +++ b/meshtastic/tcp_interface.py @@ -6,6 +6,7 @@ from meshtastic.stream_interface import StreamInterface +DEFAULT_TCP_PORT = 4403 class TCPInterface(StreamInterface): """Interface class for meshtastic devices over a TCP link""" @@ -16,7 +17,7 @@ def __init__( debugOut=None, noProto=False, connectNow=True, - portNumber=4403, + portNumber=DEFAULT_TCP_PORT, noNodes:bool=False, ): """Constructor, opens a connection to a specified IP address/hostname