Skip to content

Commit 775108b

Browse files
committed
Hop limit param on sendTraceRoute fix
1 parent 0e6a0eb commit 775108b

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

meshtastic/mesh_interface.py

Lines changed: 12 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,7 @@ 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(self, meshPacket: mesh_pb2.MeshPacket, destinationId: Union[int,str]=BROADCAST_ADDR, wantAck: bool=False, hopLimit: Optional[int]=None):
567570
"""Send a MeshPacket to the specified node (or if unspecified, broadcast).
568571
You probably don't want this - use sendData instead.
569572
@@ -604,9 +607,12 @@ def _sendPacket(self, meshPacket: mesh_pb2.MeshPacket, destinationId: Union[int,
604607

605608
meshPacket.to = nodeNum
606609
meshPacket.want_ack = wantAck
607-
loraConfig = getattr(self.localNode.localConfig, "lora")
608-
hopLimit = getattr(loraConfig, "hop_limit")
609-
meshPacket.hop_limit = hopLimit
610+
611+
if hopLimit is not None:
612+
meshPacket.hop_limit = hopLimit
613+
else:
614+
loraConfig = getattr(self.localNode.localConfig, "lora")
615+
meshPacket.hop_limit = getattr(loraConfig, "hop_limit")
610616

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

0 commit comments

Comments
 (0)