Skip to content

Commit

Permalink
Merge pull request #724 from meshtastic/send-alert
Browse files Browse the repository at this point in the history
Add sendAlert method on mesh interface
  • Loading branch information
thebentern authored Dec 23, 2024
2 parents 4e267c7 + d161291 commit d05ef17
Showing 1 changed file with 37 additions and 0 deletions.
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 @@ def sendText(
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(
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 @@ def sendData(
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 @@ def sendData(
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

0 comments on commit d05ef17

Please sign in to comment.