Iture / RFLinkGateway

MQTT Support for RFLink Gateway (http://www.nemcon.nl/blog2) project
35 stars 33 forks source link

Question: how to specify username and password for MQTT broker? #13

Open draakje111 opened 5 years ago

draakje111 commented 5 years ago

I cannot find how to specify the username and passoword for the mqtt broker, I have putt security on the broker and want to user your code to connect.

draakje111 commented 5 years ago

I found the missing peace of code in MQTTClient.py: class MQTTClient(multiprocessing.Process): def init(self, messageQ, commandQ, config): self.logger = logging.getLogger('RFLinkGW.MQTTClient') self.logger.info("Starting...")

    multiprocessing.Process.__init__(self)
    self.__messageQ = messageQ
    self.__commandQ = commandQ

    self.mqttDataPrefix = config['mqtt_prefix']
    self.mqttDataFormat = config['mqtt_format']
    self._mqttConn = mqtt.Client(client_id='RFLinkGateway')

--> self._mqttConn.username_pw_set(config['mqtt_username'], password=config['mqtt_password']) self._mqttConn.connect(config['mqtt_host'], port=config['mqtt_port'], keepalive=120)

added this line, so you can specify the username and password in the config file.