From de417081819c38edbfbed0ab2edf4caddc8132d8 Mon Sep 17 00:00:00 2001 From: "Mariana R. Santos" Date: Tue, 9 Apr 2024 13:53:46 +0200 Subject: [PATCH] Implement robot telemetry exception --- src/robot_interface/telemetry/mqtt_client.py | 26 ++++++++++++++------ src/robot_interface/telemetry/payloads.py | 7 ++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/robot_interface/telemetry/mqtt_client.py b/src/robot_interface/telemetry/mqtt_client.py index efe024bc..d49ddf83 100644 --- a/src/robot_interface/telemetry/mqtt_client.py +++ b/src/robot_interface/telemetry/mqtt_client.py @@ -1,11 +1,15 @@ import time from abc import ABCMeta, abstractmethod from queue import Queue -from typing import Callable, Tuple +from typing import Callable, Tuple, Type +from datetime import datetime +import json from robot_interface.models.exceptions.robot_exceptions import ( RobotTelemetryException, ) +from robot_interface.telemetry.payloads import CloudHealthPayload +from robot_interface.utilities.json_service import EnhancedJSONEncoder class MqttClientInterface(metaclass=ABCMeta): @@ -61,17 +65,23 @@ def __init__( self.retain: bool = retain def run(self, isar_id: str, robot_name: str) -> None: + self.cloud_healt_topic: str = f"isar/{isar_id}/cloud_health" + topic: str + payload: str + while True: try: - payload: str = self.telemetry_method( - isar_id=isar_id, robot_name=robot_name - ) + payload = self.telemetry_method(isar_id=isar_id, robot_name=robot_name) + topic = self.topic except RobotTelemetryException: - continue + payload = json.dumps( + CloudHealthPayload(isar_id, robot_name, datetime.utcnow()), + cls=EnhancedJSONEncoder, + ) + topic = self.cloud_healt_topic + + self.publish(topic=topic, payload=payload, qos=self.qos, retain=self.retain) - self.publish( - topic=self.topic, payload=payload, qos=self.qos, retain=self.retain - ) time.sleep(self.interval) def publish( diff --git a/src/robot_interface/telemetry/payloads.py b/src/robot_interface/telemetry/payloads.py index cea1e1d7..a557d882 100644 --- a/src/robot_interface/telemetry/payloads.py +++ b/src/robot_interface/telemetry/payloads.py @@ -15,6 +15,13 @@ class TelemetryPayload: timestamp: datetime +@dataclass +class CloudHealthPayload: + isar_id: str + robot_name: str + timestamp: datetime + + @dataclass class TelemetryPosePayload(TelemetryPayload): pose: Pose