1+ import datetime
12import logging
2- import os
33import paho .mqtt .client as mqtt
44import time
55from typing import Callable
66
77log = 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+
1019class 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
4343class 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" )
0 commit comments