Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,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 @@ -1592,10 +1594,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 @@ -354,6 +354,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 @@ -364,12 +365,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 @@ -378,7 +379,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
Loading