login to mqtt broker
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-10-03 13:59:24 +02:00
parent 9dc7499962
commit d43538785d
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
2 changed files with 6 additions and 1 deletions

View File

@ -24,6 +24,8 @@ services:
restart: always
networks:
- guard
ports:
- "127.0.0.1:1883:1883"
guard-service:
image: registry.kmlabz.com/birbnetes/guard-service

View File

@ -19,7 +19,7 @@ class MQTT:
"""
def __init__(self, host=config.MQTT_HOSTNAME, port=config.MQTT_PORT, client_id=config.CLIENT_ID, qos=2,
retain=True):
retain=True, username=config.MQTT_USERNAME, password=config.MQTT_PASSWORD):
"""
Init variables
:param host:
@ -35,6 +35,8 @@ class MQTT:
self._topic = None
self.qos = qos
self.retain = retain
self.username = username
self.password = password
def get_topic(self) -> str:
"""
@ -61,6 +63,7 @@ class MQTT:
logging.info("Connecting to MQTT")
self.client = mqtt.Client(client_id=self.client_id, clean_session=True, userdata=None, protocol=mqtt.MQTTv311,
transport="tcp")
self.client.username_pw_set(username=self.username,password=self.password)
self.port = int(self.port)
self.client.connect(host=self.host, port=self.port, keepalive=60)