diff --git a/api/mosquitto/data/mosquitto.db b/api/mosquitto/data/mosquitto.db index 16508a9a..e2c978b7 100644 Binary files a/api/mosquitto/data/mosquitto.db and b/api/mosquitto/data/mosquitto.db differ diff --git a/esp32-thread/open-thread-client/main/esp_ot_cli.c b/esp32-thread/open-thread-client/main/esp_ot_cli.c index b860b03b..c2275c6e 100644 --- a/esp32-thread/open-thread-client/main/esp_ot_cli.c +++ b/esp32-thread/open-thread-client/main/esp_ot_cli.c @@ -276,10 +276,9 @@ char* gps_to_json(char* gps_data) { longitude = nmea_to_decimal(fields[4], fields[5][0]); } } - - snprintf(json, sizeof(json), "{\"data\":{\"latitude\":%.6f,\"longitude\":%.6f}}", - latitude, longitude); - + + time_t current_time = time(NULL); + snprintf(json, sizeof(json), "{\"latitude\":%.6f,\"longitude\":%.6f}", latitude, longitude); return json; } diff --git a/rpi/controllers/mqtt_forwarder.py b/rpi/controllers/mqtt_forwarder.py index 79516266..ce9787ec 100644 --- a/rpi/controllers/mqtt_forwarder.py +++ b/rpi/controllers/mqtt_forwarder.py @@ -1,3 +1,7 @@ +import datetime +import json +import time + from services.mqtt_service import MQTTService class MQTTForwarder: @@ -14,8 +18,19 @@ class MQTTForwarder: def start(self, src_topic: str, dst_topic: str): try: def forward_handler(topic: str, msg: str): - self.central_broker.publish(dst_topic, msg) + forwarded_msg = self.__wrapData(msg) + self.central_broker.publish(dst_topic, forwarded_msg) self.local_broker.subscribe(src_topic, forward_handler) except Exception as e: - print(f"An error occurred while forwarding from {src_topic} to {dst_topic}: {e}") \ No newline at end of file + print(f"An error occurred while forwarding from {src_topic} to {dst_topic}: {e}") + + def __wrapData(self, msg : str): + result = {} + data = json.loads(msg) + result["timestamp"] = int(time.time()) + result["systemId"] = self.client_id + result["data"] = {} + for keys in data: + result["data"][keys] = data[keys] + diff --git a/rpi/services/mqtt_service.py b/rpi/services/mqtt_service.py index a27252cc..08c5d4d8 100644 --- a/rpi/services/mqtt_service.py +++ b/rpi/services/mqtt_service.py @@ -65,11 +65,7 @@ class MQTTService: def publish(self, topic: str, data: str, qos: int = 0): try: self.connect() - payload = { - "timestamp": int(time.time()), - "data": data - } - result = self.client.publish(topic, json.dumps(payload), qos=qos) + result = self.client.publish(topic, json.dumps(data), qos=qos) result.wait_for_publish() except Exception as e: print(f"An error occurred while publishing on {topic} on {self.address} : {e}")