This commit is contained in:
parent
9dc7499962
commit
d43538785d
@ -24,6 +24,8 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- guard
|
- guard
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:1883:1883"
|
||||||
|
|
||||||
guard-service:
|
guard-service:
|
||||||
image: registry.kmlabz.com/birbnetes/guard-service
|
image: registry.kmlabz.com/birbnetes/guard-service
|
||||||
|
@ -19,7 +19,7 @@ class MQTT:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host=config.MQTT_HOSTNAME, port=config.MQTT_PORT, client_id=config.CLIENT_ID, qos=2,
|
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
|
Init variables
|
||||||
:param host:
|
:param host:
|
||||||
@ -35,6 +35,8 @@ class MQTT:
|
|||||||
self._topic = None
|
self._topic = None
|
||||||
self.qos = qos
|
self.qos = qos
|
||||||
self.retain = retain
|
self.retain = retain
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
|
|
||||||
def get_topic(self) -> str:
|
def get_topic(self) -> str:
|
||||||
"""
|
"""
|
||||||
@ -61,6 +63,7 @@ class MQTT:
|
|||||||
logging.info("Connecting to MQTT")
|
logging.info("Connecting to MQTT")
|
||||||
self.client = mqtt.Client(client_id=self.client_id, clean_session=True, userdata=None, protocol=mqtt.MQTTv311,
|
self.client = mqtt.Client(client_id=self.client_id, clean_session=True, userdata=None, protocol=mqtt.MQTTv311,
|
||||||
transport="tcp")
|
transport="tcp")
|
||||||
|
self.client.username_pw_set(username=self.username,password=self.password)
|
||||||
self.port = int(self.port)
|
self.port = int(self.port)
|
||||||
self.client.connect(host=self.host, port=self.port, keepalive=60)
|
self.client.connect(host=self.host, port=self.port, keepalive=60)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user