Merge pull request #219 from pdxlocations/allow-port-numbers

Enhance TCP interface initialization to support host:port format
This commit is contained in:
Kelly
2025-10-19 18:54:54 -07:00
committed by GitHub
+14 -1
View File
@@ -331,7 +331,20 @@ for i in range(1, 10):
if interface_type == 'serial':
globals()[f'interface{i}'] = meshtastic.serial_interface.SerialInterface(globals().get(f'port{i}'))
elif interface_type == 'tcp':
globals()[f'interface{i}'] = meshtastic.tcp_interface.TCPInterface(globals().get(f'hostname{i}'))
host = globals().get(f'hostname{i}', '127.0.0.1')
port = 4403
# Allow host:port format
if isinstance(host, str) and ':' in host:
maybe_host, maybe_port = host.rsplit(':', 1)
if maybe_port.isdigit():
host = maybe_host
try:
port = int(maybe_port)
except ValueError:
port = 4403
globals()[f'interface{i}'] = meshtastic.tcp_interface.TCPInterface(hostname=host, portNumber=port)
elif interface_type == 'ble':
globals()[f'interface{i}'] = meshtastic.ble_interface.BLEInterface(globals().get(f'mac{i}'))
else: