Skip to content

Commit 19d7e91

Browse files
authored
Merge pull request #629 from ppicazo/trace_route_hop_fix
Fix for hopLimit param on sendTraceRoute not being respected
2 parents 1511d4e + 64bb668 commit 19d7e91

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

meshtastic/mesh_interface.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def sendData(
325325
onResponse: Optional[Callable[[dict], Any]]=None,
326326
onResponseAckPermitted: bool=False,
327327
channelIndex: int=0,
328+
hopLimit: Optional[int]=None,
328329
):
329330
"""Send a data packet to some other node
330331
@@ -347,7 +348,8 @@ def sendData(
347348
for regular ACKs (True) or just data responses & NAKs (False)
348349
Note that if the onResponse callback is called 'onAckNak' this
349350
will implicitly be true.
350-
channelIndex - channel number to use
351+
channelIndex -- channel number to use
352+
hopLimit -- hop limit to use
351353
352354
Returns the sent packet. The id field will be populated in this packet
353355
and can be used to track future message acks/naks.
@@ -379,7 +381,7 @@ def sendData(
379381
if onResponse is not None:
380382
logging.debug(f"Setting a response handler for requestId {meshPacket.id}")
381383
self._addResponseHandler(meshPacket.id, onResponse, ackPermitted=onResponseAckPermitted)
382-
p = self._sendPacket(meshPacket, destinationId, wantAck=wantAck)
384+
p = self._sendPacket(meshPacket, destinationId, wantAck=wantAck, hopLimit=hopLimit)
383385
return p
384386

385387
def sendPosition(
@@ -478,6 +480,7 @@ def sendTraceRoute(self, dest: Union[int, str], hopLimit: int, channelIndex: int
478480
wantResponse=True,
479481
onResponse=self.onResponseTraceRoute,
480482
channelIndex=channelIndex,
483+
hopLimit=hopLimit,
481484
)
482485
# extend timeout based on number of nodes, limit by configured hopLimit
483486
waitFactor = min(len(self.nodes) - 1 if self.nodes else 0, hopLimit)
@@ -563,7 +566,13 @@ def onResponseTelemetry(self, p: dict):
563566
def _addResponseHandler(self, requestId: int, callback: Callable[[dict], Any], ackPermitted: bool=False):
564567
self.responseHandlers[requestId] = ResponseHandler(callback=callback, ackPermitted=ackPermitted)
565568

566-
def _sendPacket(self, meshPacket: mesh_pb2.MeshPacket, destinationId: Union[int,str]=BROADCAST_ADDR, wantAck: bool=False):
569+
def _sendPacket(
570+
self,
571+
meshPacket: mesh_pb2.MeshPacket,
572+
destinationId: Union[int,str]=BROADCAST_ADDR,
573+
wantAck: bool=False,
574+
hopLimit: Optional[int]=None
575+
):
567576
"""Send a MeshPacket to the specified node (or if unspecified, broadcast).
568577
You probably don't want this - use sendData instead.
569578
@@ -604,9 +613,12 @@ def _sendPacket(self, meshPacket: mesh_pb2.MeshPacket, destinationId: Union[int,
604613

605614
meshPacket.to = nodeNum
606615
meshPacket.want_ack = wantAck
607-
loraConfig = getattr(self.localNode.localConfig, "lora")
608-
hopLimit = getattr(loraConfig, "hop_limit")
609-
meshPacket.hop_limit = hopLimit
616+
617+
if hopLimit is not None:
618+
meshPacket.hop_limit = hopLimit
619+
else:
620+
loraConfig = getattr(self.localNode.localConfig, "lora")
621+
meshPacket.hop_limit = getattr(loraConfig, "hop_limit")
610622

611623
# if the user hasn't set an ID for this packet (likely and recommended),
612624
# we should pick a new unique ID so the message can be tracked.

0 commit comments

Comments
 (0)