Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions packages/helpermodules/broker.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import datetime
import logging
import os
import paho.mqtt.client as mqtt
import time
from typing import Callable

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}-{self._get_serial()}"
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
Expand All @@ -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-{os.getpid()}")
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")
Expand Down
4 changes: 3 additions & 1 deletion runs/remoteSupport/remoteSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down