Skip to content
Closed
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
14 changes: 13 additions & 1 deletion tofupilot/openhtf/tofupilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __init__(
self.mqttClient = None
self.publishOptions = None
self._logger = self.client._logger
self._reconnecting = False
self._streaming_setup_thread = None

def _upload(self, testRecord: TestRecord):
Expand Down Expand Up @@ -259,6 +260,7 @@ def _connect_streaming(self) -> str:
self.mqttClient.username_pw_set("pythonClient", token)

self.mqttClient.on_message = self._on_message
self.mqttClient.on_connect = self._on_connect
self.mqttClient.on_disconnect = self._on_disconnect
self.mqttClient.on_unsubscribe = self._on_unsubscribe

Expand Down Expand Up @@ -424,6 +426,16 @@ def _on_message(self, client, userdata, message):
if parsed["source"] == "web":
self._handle_answer(**parsed["message"])

def _on_connect(
self, client, userdata, connect_flags, reason_code, properties,
):
if self._reconnecting:
# Warning to be sure the log level is the same as the other message
self._logger.warning(
f"Operator UI: Reconnected"
)
self._reconnecting = False

def _on_disconnect(
self, client, userdata, disconnect_flags: mqtt.DisconnectFlags, reason_code: ReasonCode, properties
):
Expand All @@ -432,7 +444,7 @@ def _on_disconnect(
self._logger.warning(
f"Operator UI: Unexpected disconnect (code {reason_code})"
)

self._reconnecting = True
self._connect_streaming()
self.mqttClient.loop_start()
test_state_dict, _ = _to_dict_with_event(self.test.state)
Expand Down
Loading