RFLinkGateway icon indicating copy to clipboard operation
RFLinkGateway copied to clipboard

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

Open draakje111 opened this issue 6 years ago • 1 comments

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 avatar Dec 02 '18 18:12 draakje111

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.

draakje111 avatar Dec 02 '18 20:12 draakje111