Skip to content

Commit 985366c

Browse files
authored
Merge pull request #710 from digitaldisarray/master
Add text message port cli option
2 parents 5f174b2 + 3954fbd commit 985366c

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

meshtastic/__main__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,15 @@ def onConnected(interface):
483483
if checkChannel(interface, channelIndex):
484484
print(
485485
f"Sending text message {args.sendtext} to {args.dest} on channelIndex:{channelIndex}"
486+
f" {'using PRIVATE_APP port' if args.private else ''}"
486487
)
487488
interface.sendText(
488489
args.sendtext,
489490
args.dest,
490491
wantAck=True,
491492
channelIndex=channelIndex,
492493
onResponse=interface.getNode(args.dest, False, **getNode_kwargs).onAckNak,
494+
portNum=portnums_pb2.PortNum.PRIVATE_APP if args.private else portnums_pb2.PortNum.TEXT_MESSAGE_APP
493495
)
494496
else:
495497
meshtastic.util.our_exit(
@@ -1669,10 +1671,16 @@ def addRemoteActionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar
16691671

16701672
group.add_argument(
16711673
"--sendtext",
1672-
help="Send a text message. Can specify a destination '--dest' and/or channel index '--ch-index'.",
1674+
help="Send a text message. Can specify a destination '--dest', use of PRIVATE_APP port '--private', and/or channel index '--ch-index'.",
16731675
metavar="TEXT",
16741676
)
16751677

1678+
group.add_argument(
1679+
"--private",
1680+
help="Optional argument for sending text messages to the PRIVATE_APP port. Use in combination with --sendtext.",
1681+
action="store_true"
1682+
)
1683+
16761684
group.add_argument(
16771685
"--traceroute",
16781686
help="Traceroute from connected node to a destination. "

meshtastic/mesh_interface.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def sendText(
411411
wantResponse: bool = False,
412412
onResponse: Optional[Callable[[dict], Any]] = None,
413413
channelIndex: int = 0,
414+
portNum: portnums_pb2.PortNum.ValueType = portnums_pb2.PortNum.TEXT_MESSAGE_APP
414415
):
415416
"""Send a utf8 string to some other node, if the node has a display it
416417
will also be shown on the device.
@@ -421,12 +422,12 @@ def sendText(
421422
Keyword Arguments:
422423
destinationId {nodeId or nodeNum} -- where to send this
423424
message (default: {BROADCAST_ADDR})
424-
portNum -- the application portnum (similar to IP port numbers)
425-
of the destination, see portnums.proto for a list
426425
wantAck -- True if you want the message sent in a reliable manner
427426
(with retries and ack/nak provided for delivery)
428427
wantResponse -- True if you want the service on the other side to
429428
send an application layer response
429+
portNum -- the application portnum (similar to IP port numbers)
430+
of the destination, see portnums.proto for a list
430431
431432
Returns the sent packet. The id field will be populated in this packet
432433
and can be used to track future message acks/naks.
@@ -435,7 +436,7 @@ def sendText(
435436
return self.sendData(
436437
text.encode("utf-8"),
437438
destinationId,
438-
portNum=portnums_pb2.PortNum.TEXT_MESSAGE_APP,
439+
portNum=portNum,
439440
wantAck=wantAck,
440441
wantResponse=wantResponse,
441442
onResponse=onResponse,

meshtastic/tests/test_main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,10 @@ def test_main_sendtext(capsys):
593593
iface = MagicMock(autospec=SerialInterface)
594594

595595
def mock_sendText(
596-
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0
596+
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0, portNum=0
597597
):
598598
print("inside mocked sendText")
599-
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex}")
599+
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex} {portNum}")
600600

601601
iface.sendText.side_effect = mock_sendText
602602

@@ -620,10 +620,10 @@ def test_main_sendtext_with_channel(capsys):
620620
iface = MagicMock(autospec=SerialInterface)
621621

622622
def mock_sendText(
623-
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0
623+
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0, portNum=0
624624
):
625625
print("inside mocked sendText")
626-
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex}")
626+
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex} {portNum}")
627627

628628
iface.sendText.side_effect = mock_sendText
629629

0 commit comments

Comments
 (0)