Add method to be able to send heartbeat

This commit is contained in:
Wolfgang Nagele
2024-08-25 11:11:10 +02:00
parent abf9e96d3d
commit b692ef4cfb

View File

@@ -812,19 +812,21 @@ class MeshInterface: # pylint: disable=R0902
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