From dbd93192a8fd0788d63f6ff975d46476401b6875 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Tue, 12 Nov 2024 16:31:30 +0100 Subject: [PATCH 1/2] fix python threads --- packages/helpermodules/broker.py | 6 +++--- runs/remoteSupport/remoteSupport.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/helpermodules/broker.py b/packages/helpermodules/broker.py index 7f24b15e74..405d65011c 100644 --- a/packages/helpermodules/broker.py +++ b/packages/helpermodules/broker.py @@ -1,5 +1,5 @@ +import datetime import logging -import os import paho.mqtt.client as mqtt import time from typing import Callable @@ -10,7 +10,7 @@ class InternalBrokerClient: def __init__(self, name: str, on_connect: Callable, on_message: Callable) -> None: try: - self.name = f"openWB-{name}-{self._get_serial()}" + self.name = f"openWB-{name}-{datetime.datetime.today().timestamp()}" self.client = mqtt.Client(self.name) self.client.on_connect = on_connect self.client.on_message = on_message @@ -43,7 +43,7 @@ def _get_serial(self) -> str: class InternalBrokerPublisher: def __init__(self) -> None: try: - self.client = mqtt.Client(f"openWB-python-bulkpublisher-{os.getpid()}") + self.client = mqtt.Client(f"openWB-python-bulkpublisher-{datetime.datetime.today().timestamp()}") self.client.connect("localhost", 1886) except Exception: log.exception("Fehler beim Verbindungsaufbau zum Bulkpublisher") diff --git a/runs/remoteSupport/remoteSupport.py b/runs/remoteSupport/remoteSupport.py index 8e6c037757..0739cb5c30 100755 --- a/runs/remoteSupport/remoteSupport.py +++ b/runs/remoteSupport/remoteSupport.py @@ -9,6 +9,8 @@ import paho.mqtt.client as mqtt import platform +from helpermodules.timecheck import create_timestamp + API_VERSION = "1" BASE_PATH = Path(__file__).resolve().parents[2] RAMDISK_PATH = BASE_PATH / "ramdisk" @@ -208,7 +210,7 @@ def is_tunnel_closed(tunnel: Popen) -> bool: lt_executable = get_lt_executable() -client = mqtt.Client("openWB-remote-" + get_serial()) +client = mqtt.Client(f"openWB-remote-{get_serial()}-{create_timestamp()}") client.on_connect = on_connect client.on_message = on_message client.will_set(STATE_TOPIC, json.dumps("offline"), qos=2, retain=True) From 6e7396f855e843f55c7c45f38d3a1e62aeb3f880 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 3 Feb 2025 15:43:26 +0100 Subject: [PATCH 2/2] improve --- packages/helpermodules/broker.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/helpermodules/broker.py b/packages/helpermodules/broker.py index 405d65011c..ab7feb3149 100644 --- a/packages/helpermodules/broker.py +++ b/packages/helpermodules/broker.py @@ -7,10 +7,19 @@ log = logging.getLogger(__name__) +def get_name_suffix() -> str: + with open('/proc/cpuinfo', 'r') as f: + for line in f: + if line[0:6] == 'Serial': + serial = line[10:26] + serial = "0000000000000000" + return f"{serial}-{datetime.datetime.today().timestamp()}" + + class InternalBrokerClient: def __init__(self, name: str, on_connect: Callable, on_message: Callable) -> None: try: - self.name = f"openWB-{name}-{datetime.datetime.today().timestamp()}" + self.name = f"openWB-{name}-{get_name_suffix()}" self.client = mqtt.Client(self.name) self.client.on_connect = on_connect self.client.on_message = on_message @@ -30,20 +39,11 @@ def disconnect(self) -> None: self.client.disconnect() log.info(f"Verbindung von Client {self.name} geschlossen.") - def _get_serial(self) -> str: - """ Extract serial from cpuinfo file - """ - with open('/proc/cpuinfo', 'r') as f: - for line in f: - if line[0:6] == 'Serial': - return line[10:26] - return "0000000000000000" - class InternalBrokerPublisher: def __init__(self) -> None: try: - self.client = mqtt.Client(f"openWB-python-bulkpublisher-{datetime.datetime.today().timestamp()}") + self.client = mqtt.Client(f"openWB-python-bulkpublisher-{get_name_suffix()}") self.client.connect("localhost", 1886) except Exception: log.exception("Fehler beim Verbindungsaufbau zum Bulkpublisher")