add configurable client_id
This commit is contained in:
@@ -4,6 +4,7 @@ mqtt:
|
|||||||
username: user
|
username: user
|
||||||
password: password
|
password: password
|
||||||
topic_prefix: hostname
|
topic_prefix: hostname
|
||||||
|
client_id: bt-mqtt-gateway
|
||||||
|
|
||||||
manager:
|
manager:
|
||||||
topic_subscription:
|
topic_subscription:
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import paho.mqtt.publish as publish
|
import paho.mqtt.publish as publish
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
|
||||||
class MqttClient:
|
class MqttClient:
|
||||||
|
|
||||||
|
#print({client_id})
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self._config = 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:
|
if self.username is not None and self.password is not None:
|
||||||
self._auth = {'username': self.username, 'password': self.password}
|
self._auth = {'username': self.username, 'password': self.password}
|
||||||
@@ -25,6 +27,10 @@ class MqttClient:
|
|||||||
port=self.port,
|
port=self.port,
|
||||||
auth=self._auth)
|
auth=self._auth)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def client_id(self):
|
||||||
|
return self._config['client_id'] if 'client_id' in self._config else 'bt-mqtt-gateway'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hostname(self):
|
def hostname(self):
|
||||||
return self._config['host']
|
return self._config['host']
|
||||||
|
|||||||
Reference in New Issue
Block a user