Moved Docker stuff to "Docker" folder
Created k8s folder for k8s stuff Added early-stage service.yaml for K8s deployment
This commit is contained in:
44
Docker/src/python/tHome/broker/connect.py
Normal file
44
Docker/src/python/tHome/broker/connect.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#===========================================================================
|
||||
#
|
||||
# Broker connection
|
||||
#
|
||||
#===========================================================================
|
||||
from . import config
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
#===========================================================================
|
||||
class Client( mqtt.Client ):
|
||||
"""Logging client
|
||||
"""
|
||||
def __init__( self, log=None ):
|
||||
mqtt.Client.__init__( self )
|
||||
self._logger = log
|
||||
# Restore callbacks overwritten by stupid mqtt library
|
||||
self.on_log = Client.on_log
|
||||
|
||||
def on_log( self, userData, level, buf ):
|
||||
if self._logger:
|
||||
self._logger.log( level, buf )
|
||||
|
||||
#===========================================================================
|
||||
def connect( configDir, log, client=None ):
|
||||
cfg = config.parse( configDir )
|
||||
|
||||
if client is None:
|
||||
client = Client( log )
|
||||
|
||||
if cfg.user:
|
||||
client.username_pw_set( cfg.user, cfg.password )
|
||||
|
||||
if cfg.ca_certs:
|
||||
client.tls_set( cfg.ca_certs, cfg.certFile, cfg.keyFile )
|
||||
|
||||
log.info( "Connecting to broker at %s:%d" % ( cfg.host, cfg.port ) )
|
||||
client.connect( cfg.host, cfg.port, cfg.keepAlive )
|
||||
|
||||
return client
|
||||
|
||||
#===========================================================================
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user