Skip to content

Commit 74c911c

Browse files
Add text message port cli option
1 parent 03ac322 commit 74c911c

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

meshtastic/__main__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,15 @@ def onConnected(interface):
442442
channelIndex = mt_config.channel_index or 0
443443
if checkChannel(interface, channelIndex):
444444
print(
445-
f"Sending text message {args.sendtext} to {args.dest} on channelIndex:{channelIndex}"
445+
f"Sending text message {args.sendtext} to {args.dest}:{args.textport} on channelIndex:{channelIndex}"
446446
)
447447
interface.sendText(
448448
args.sendtext,
449449
args.dest,
450450
wantAck=True,
451451
channelIndex=channelIndex,
452452
onResponse=interface.getNode(args.dest, False, **getNode_kwargs).onAckNak,
453+
portNum=args.textport
453454
)
454455
else:
455456
meshtastic.util.our_exit(
@@ -1592,10 +1593,18 @@ def addRemoteActionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar
15921593

15931594
group.add_argument(
15941595
"--sendtext",
1595-
help="Send a text message. Can specify a destination '--dest' and/or channel index '--ch-index'.",
1596+
help="Send a text message. Can specify a destination '--dest', port '--textport', and/or channel index '--ch-index'.",
15961597
metavar="TEXT",
15971598
)
15981599

1600+
group.add_argument(
1601+
"--textport",
1602+
help="Optional argument for sending text messages to the non default port. Use in combination with --sendtext.",
1603+
type=int,
1604+
default=portnums_pb2.PortNum.TEXT_MESSAGE_APP,
1605+
metavar="PORT"
1606+
)
1607+
15991608
group.add_argument(
16001609
"--traceroute",
16011610
help="Traceroute from connected node to a destination. "

meshtastic/mesh_interface.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def sendText(
354354
wantResponse: bool = False,
355355
onResponse: Optional[Callable[[dict], Any]] = None,
356356
channelIndex: int = 0,
357+
portNum: int = portnums_pb2.PortNum.TEXT_MESSAGE_APP
357358
):
358359
"""Send a utf8 string to some other node, if the node has a display it
359360
will also be shown on the device.
@@ -364,12 +365,12 @@ def sendText(
364365
Keyword Arguments:
365366
destinationId {nodeId or nodeNum} -- where to send this
366367
message (default: {BROADCAST_ADDR})
367-
portNum -- the application portnum (similar to IP port numbers)
368-
of the destination, see portnums.proto for a list
369368
wantAck -- True if you want the message sent in a reliable manner
370369
(with retries and ack/nak provided for delivery)
371370
wantResponse -- True if you want the service on the other side to
372371
send an application layer response
372+
portNum -- the application portnum (similar to IP port numbers)
373+
of the destination, see portnums.proto for a list
373374
374375
Returns the sent packet. The id field will be populated in this packet
375376
and can be used to track future message acks/naks.
@@ -378,7 +379,7 @@ def sendText(
378379
return self.sendData(
379380
text.encode("utf-8"),
380381
destinationId,
381-
portNum=portnums_pb2.PortNum.TEXT_MESSAGE_APP,
382+
portNum=portNum,
382383
wantAck=wantAck,
383384
wantResponse=wantResponse,
384385
onResponse=onResponse,

0 commit comments

Comments
 (0)