diff --git a/README.rst b/README.rst index 25c711a..c3972ab 100644 --- a/README.rst +++ b/README.rst @@ -51,6 +51,10 @@ can set: if your broker uses a non-default port. * **keepalive** - Used to set the keepalive time for connections to the MQTT broker. By default this is set to 60 seconds. + * **username** - Used to set the auth username to connect to the MQTT broker + with. + * **password** - Used to set the auth password to connect to the MQTT broker + with. A username must be set for this option to be used. Other Settings -------------- diff --git a/germqtt/germqtt.py b/germqtt/germqtt.py index 97a2016..7da7435 100644 --- a/germqtt/germqtt.py +++ b/germqtt/germqtt.py @@ -116,10 +116,26 @@ def _main(args, config): else: keepalive = 60 + # Configure auth + auth = None + if config.has_option('mqtt', 'username'): + mqtt_username = config.get('mqtt', 'username') + else: + mqtt_username = None + if config.has_option('mqtt', 'password'): + mqtt_password = config.get('mqtt', 'password') + else: + mqtt_password = None + if mqtt_username: + auth = {'username': mqtt_username} + if mqtt_password: + auth['password'] = mqtt_password + mqttqueue = PushMQTT( config.get('mqtt', 'hostname'), port=mqtt_port, - keepalive=keepalive) + keepalive=keepalive, + auth=auth) base_topic = config.get('mqtt', 'topic') while True: