Skip to content

Commit 690ee4f

Browse files
authored
Feature broker client name (#2191)
* fix python threads * improve
1 parent bdee5d1 commit 690ee4f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/helpermodules/broker.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
import datetime
12
import logging
2-
import os
33
import paho.mqtt.client as mqtt
44
import time
55
from typing import Callable
66

77
log = logging.getLogger(__name__)
88

99

10+
def get_name_suffix() -> str:
11+
with open('/proc/cpuinfo', 'r') as f:
12+
for line in f:
13+
if line[0:6] == 'Serial':
14+
serial = line[10:26]
15+
serial = "0000000000000000"
16+
return f"{serial}-{datetime.datetime.today().timestamp()}"
17+
18+
1019
class InternalBrokerClient:
1120
def __init__(self, name: str, on_connect: Callable, on_message: Callable) -> None:
1221
try:
13-
self.name = f"openWB-{name}-{self._get_serial()}"
22+
self.name = f"openWB-{name}-{get_name_suffix()}"
1423
self.client = mqtt.Client(self.name)
1524
self.client.on_connect = on_connect
1625
self.client.on_message = on_message
@@ -30,20 +39,11 @@ def disconnect(self) -> None:
3039
self.client.disconnect()
3140
log.info(f"Verbindung von Client {self.name} geschlossen.")
3241

33-
def _get_serial(self) -> str:
34-
""" Extract serial from cpuinfo file
35-
"""
36-
with open('/proc/cpuinfo', 'r') as f:
37-
for line in f:
38-
if line[0:6] == 'Serial':
39-
return line[10:26]
40-
return "0000000000000000"
41-
4242

4343
class InternalBrokerPublisher:
4444
def __init__(self) -> None:
4545
try:
46-
self.client = mqtt.Client(f"openWB-python-bulkpublisher-{os.getpid()}")
46+
self.client = mqtt.Client(f"openWB-python-bulkpublisher-{get_name_suffix()}")
4747
self.client.connect("localhost", 1886)
4848
except Exception:
4949
log.exception("Fehler beim Verbindungsaufbau zum Bulkpublisher")

runs/remoteSupport/remoteSupport.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import paho.mqtt.client as mqtt
1010
import platform
1111

12+
from helpermodules.timecheck import create_timestamp
13+
1214
API_VERSION = "1"
1315
BASE_PATH = Path(__file__).resolve().parents[2]
1416
RAMDISK_PATH = BASE_PATH / "ramdisk"
@@ -208,7 +210,7 @@ def is_tunnel_closed(tunnel: Popen) -> bool:
208210

209211

210212
lt_executable = get_lt_executable()
211-
client = mqtt.Client("openWB-remote-" + get_serial())
213+
client = mqtt.Client(f"openWB-remote-{get_serial()}-{create_timestamp()}")
212214
client.on_connect = on_connect
213215
client.on_message = on_message
214216
client.will_set(STATE_TOPIC, json.dumps("offline"), qos=2, retain=True)

0 commit comments

Comments
 (0)