From b692ef4cfb6b1bef9b70c665c5c30e051240bde0 Mon Sep 17 00:00:00 2001 From: Wolfgang Nagele Date: Sun, 25 Aug 2024 11:11:10 +0200 Subject: [PATCH 1/2] Add method to be able to send heartbeat --- meshtastic/mesh_interface.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index c83a399c..39480891 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -812,19 +812,21 @@ def _disconnected(self): lambda: pub.sendMessage("meshtastic.connection.lost", interface=self) ) + def sendHeartbeat(self): + p = mesh_pb2.ToRadio() + p.heartbeat.CopyFrom(mesh_pb2.Heartbeat()) + self._sendToRadio(p) + def _startHeartbeat(self): """We need to send a heartbeat message to the device every X seconds""" def callback(): self.heartbeatTimer = None - i = 300 - logging.debug(f"Sending heartbeat, interval {i} seconds") - if i != 0: - self.heartbeatTimer = threading.Timer(i, callback) - self.heartbeatTimer.start() - p = mesh_pb2.ToRadio() - p.heartbeat.CopyFrom(mesh_pb2.Heartbeat()) - self._sendToRadio(p) + interval = 300 + logging.debug(f"Sending heartbeat, interval {interval} seconds") + self.heartbeatTimer = threading.Timer(interval, callback) + self.heartbeatTimer.start() + self.sendHeartbeat() callback() # run our periodic callback now, it will make another timer if necessary From d77335caa7fde9f2cd0585ab76a38f90213be250 Mon Sep 17 00:00:00 2001 From: Wolfgang Nagele Date: Sun, 25 Aug 2024 22:13:08 +0200 Subject: [PATCH 2/2] Add sendHeartbeat doc-string --- meshtastic/mesh_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 39480891..36c7ee88 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -813,6 +813,7 @@ def _disconnected(self): ) def sendHeartbeat(self): + """Sends a heartbeat to the radio. Can be used to verify the connection is healthy.""" p = mesh_pb2.ToRadio() p.heartbeat.CopyFrom(mesh_pb2.Heartbeat()) self._sendToRadio(p)