Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sendAlert method on mesh interface #724

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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
37 changes: 37 additions & 0 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,40 @@
channelIndex=channelIndex,
)


def sendAlert(
self,
text: str,
destinationId: Union[int, str] = BROADCAST_ADDR,
onResponse: Optional[Callable[[dict], Any]] = None,
channelIndex: int = 0,
):
"""Send an alert text to some other node. This is similar to a text message,
but carries a higher priority and is capable of generating special notifications
on certain clients.

Arguments:
text {string} -- The text of the alert to send

Keyword Arguments:
destinationId {nodeId or nodeNum} -- where to send this
message (default: {BROADCAST_ADDR})

Returns the sent packet. The id field will be populated in this packet
and can be used to track future message acks/naks.
"""

return self.sendData(

Check warning on line 415 in meshtastic/mesh_interface.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/mesh_interface.py#L415

Added line #L415 was not covered by tests
text.encode("utf-8"),
destinationId,
portNum=portnums_pb2.PortNum.ALERT_APP,
wantAck=False,
wantResponse=False,
onResponse=onResponse,
channelIndex=channelIndex,
priority=mesh_pb2.MeshPacket.Priority.ALERT
)

def sendData(
self,
data,
Expand All @@ -402,6 +436,7 @@
hopLimit: Optional[int]=None,
pkiEncrypted: Optional[bool]=False,
publicKey: Optional[bytes]=None,
priority: mesh_pb2.MeshPacket.Priority.ValueType=mesh_pb2.MeshPacket.Priority.RELIABLE,
): # pylint: disable=R0913
"""Send a data packet to some other node

Expand Down Expand Up @@ -453,6 +488,8 @@
meshPacket.decoded.portnum = portNum
meshPacket.decoded.want_response = wantResponse
meshPacket.id = self._generatePacketId()
if priority is not None:
meshPacket.priority = priority

if onResponse is not None:
logging.debug(f"Setting a response handler for requestId {meshPacket.id}")
Expand Down
Loading