diff --git a/config.yaml.example b/config.yaml.example index 369301f..c405884 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -4,6 +4,7 @@ mqtt: username: user password: password topic_prefix: hostname + client_id: bt-mqtt-gateway manager: topic_subscription: diff --git a/mqtt.py b/mqtt.py index 9f9b48a..22a7b26 100644 --- a/mqtt.py +++ b/mqtt.py @@ -1,11 +1,13 @@ import paho.mqtt.publish as publish import paho.mqtt.client as mqtt - class MqttClient: + + #print({client_id}) + def __init__(self, config): self._config = config - self._mqttc = mqtt.Client(client_id='bt-mqtt-gateway', clean_session=False) + self._mqttc = mqtt.Client(client_id=self.client_id, clean_session=False) if self.username is not None and self.password is not None: self._auth = {'username': self.username, 'password': self.password} @@ -25,6 +27,10 @@ class MqttClient: port=self.port, auth=self._auth) + @property + def client_id(self): + return self._config['client_id'] if 'client_id' in self._config else 'bt-mqtt-gateway' + @property def hostname(self): return self._config['host']