From 74c911cb75696331d51998f9c0a697e776e724ad Mon Sep 17 00:00:00 2001 From: digitaldisarray Date: Fri, 6 Dec 2024 17:54:08 -0800 Subject: [PATCH] Add text message port cli option --- meshtastic/__main__.py | 13 +++++++++++-- meshtastic/mesh_interface.py | 7 ++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index f5390d5..a26c497 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -442,7 +442,7 @@ def onConnected(interface): channelIndex = mt_config.channel_index or 0 if checkChannel(interface, channelIndex): print( - f"Sending text message {args.sendtext} to {args.dest} on channelIndex:{channelIndex}" + f"Sending text message {args.sendtext} to {args.dest}:{args.textport} on channelIndex:{channelIndex}" ) interface.sendText( args.sendtext, @@ -450,6 +450,7 @@ def onConnected(interface): wantAck=True, channelIndex=channelIndex, onResponse=interface.getNode(args.dest, False, **getNode_kwargs).onAckNak, + portNum=args.textport ) else: meshtastic.util.our_exit( @@ -1592,10 +1593,18 @@ def addRemoteActionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar group.add_argument( "--sendtext", - help="Send a text message. Can specify a destination '--dest' and/or channel index '--ch-index'.", + help="Send a text message. Can specify a destination '--dest', port '--textport', and/or channel index '--ch-index'.", metavar="TEXT", ) + group.add_argument( + "--textport", + help="Optional argument for sending text messages to the non default port. Use in combination with --sendtext.", + type=int, + default=portnums_pb2.PortNum.TEXT_MESSAGE_APP, + metavar="PORT" + ) + group.add_argument( "--traceroute", help="Traceroute from connected node to a destination. " diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 648755c..ddc938d 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -354,6 +354,7 @@ class MeshInterface: # pylint: disable=R0902 wantResponse: bool = False, onResponse: Optional[Callable[[dict], Any]] = None, channelIndex: int = 0, + portNum: int = portnums_pb2.PortNum.TEXT_MESSAGE_APP ): """Send a utf8 string to some other node, if the node has a display it will also be shown on the device. @@ -364,12 +365,12 @@ class MeshInterface: # pylint: disable=R0902 Keyword Arguments: destinationId {nodeId or nodeNum} -- where to send this message (default: {BROADCAST_ADDR}) - portNum -- the application portnum (similar to IP port numbers) - of the destination, see portnums.proto for a list wantAck -- True if you want the message sent in a reliable manner (with retries and ack/nak provided for delivery) wantResponse -- True if you want the service on the other side to send an application layer response + portNum -- the application portnum (similar to IP port numbers) + of the destination, see portnums.proto for a list Returns the sent packet. The id field will be populated in this packet and can be used to track future message acks/naks. @@ -378,7 +379,7 @@ class MeshInterface: # pylint: disable=R0902 return self.sendData( text.encode("utf-8"), destinationId, - portNum=portnums_pb2.PortNum.TEXT_MESSAGE_APP, + portNum=portNum, wantAck=wantAck, wantResponse=wantResponse, onResponse=onResponse,