Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to be able to send heartbeat #658

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,19 +812,22 @@
lambda: pub.sendMessage("meshtastic.connection.lost", interface=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)

Check warning on line 819 in meshtastic/mesh_interface.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/mesh_interface.py#L817-L819

Added lines #L817 - L819 were not covered by tests

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()

Check warning on line 830 in meshtastic/mesh_interface.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/mesh_interface.py#L826-L830

Added lines #L826 - L830 were not covered by tests

callback() # run our periodic callback now, it will make another timer if necessary

Expand Down
Loading