Skip to content

Commit

Permalink
Merge pull request #710 from digitaldisarray/master
Browse files Browse the repository at this point in the history
Add text message port cli option
  • Loading branch information
ianmcorvidae authored Feb 19, 2025
2 parents 5f174b2 + 3954fbd commit 985366c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 9 additions & 1 deletion meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,15 @@ def onConnected(interface):
if checkChannel(interface, channelIndex):
print(
f"Sending text message {args.sendtext} to {args.dest} on channelIndex:{channelIndex}"
f" {'using PRIVATE_APP port' if args.private else ''}"
)
interface.sendText(
args.sendtext,
args.dest,
wantAck=True,
channelIndex=channelIndex,
onResponse=interface.getNode(args.dest, False, **getNode_kwargs).onAckNak,
portNum=portnums_pb2.PortNum.PRIVATE_APP if args.private else portnums_pb2.PortNum.TEXT_MESSAGE_APP
)
else:
meshtastic.util.our_exit(
Expand Down Expand Up @@ -1669,10 +1671,16 @@ 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', use of PRIVATE_APP port '--private', and/or channel index '--ch-index'.",
metavar="TEXT",
)

group.add_argument(
"--private",
help="Optional argument for sending text messages to the PRIVATE_APP port. Use in combination with --sendtext.",
action="store_true"
)

group.add_argument(
"--traceroute",
help="Traceroute from connected node to a destination. "
Expand Down
7 changes: 4 additions & 3 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def sendText(
wantResponse: bool = False,
onResponse: Optional[Callable[[dict], Any]] = None,
channelIndex: int = 0,
portNum: portnums_pb2.PortNum.ValueType = 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.
Expand All @@ -421,12 +422,12 @@ def sendText(
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.
Expand All @@ -435,7 +436,7 @@ def sendText(
return self.sendData(
text.encode("utf-8"),
destinationId,
portNum=portnums_pb2.PortNum.TEXT_MESSAGE_APP,
portNum=portNum,
wantAck=wantAck,
wantResponse=wantResponse,
onResponse=onResponse,
Expand Down
8 changes: 4 additions & 4 deletions meshtastic/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,10 @@ def test_main_sendtext(capsys):
iface = MagicMock(autospec=SerialInterface)

def mock_sendText(
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0, portNum=0
):
print("inside mocked sendText")
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex}")
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex} {portNum}")

iface.sendText.side_effect = mock_sendText

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

def mock_sendText(
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0
text, dest, wantAck=False, wantResponse=False, onResponse=None, channelIndex=0, portNum=0
):
print("inside mocked sendText")
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex}")
print(f"{text} {dest} {wantAck} {wantResponse} {channelIndex} {portNum}")

iface.sendText.side_effect = mock_sendText

Expand Down

0 comments on commit 985366c

Please sign in to comment.