From d0d4f77e0db8503dff1306f0012d5a84c59de8fc Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 7 Sep 2016 23:06:08 -0400 Subject: [PATCH] Add config option to set QOS of published messages This commit adds a new config option to lpmqtt to set the QOS level for messages published to MQTT. The QOS used in MQTT is the min value between what the client and publisher use. By default lpmqtt will use a QOS level of 0, but if operating in an environment where more guarantees are needed on delivery you can set this to be higher. Change-Id: If2ce821565551fdf686e253d06356080702c05a1 --- lpmqtt/daemon.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lpmqtt/daemon.py b/lpmqtt/daemon.py index f009da0..ade544b 100644 --- a/lpmqtt/daemon.py +++ b/lpmqtt/daemon.py @@ -23,7 +23,7 @@ from lpmqtt import lp class PushMQTT(object): def __init__(self, hostname, port=1883, client_id=None, - keepalive=60, will=None, auth=None, tls=None): + keepalive=60, will=None, auth=None, tls=None, qos=0): self.hostname = hostname self.port = port self.client_id = client_id @@ -31,18 +31,19 @@ class PushMQTT(object): self.will = will self.auth = auth self.tls = tls + self.qos = qos def publish_single(self, topic, msg): publish.single(topic, msg, hostname=self.hostname, port=self.port, client_id=self.client_id, keepalive=self.keepalive, will=self.will, - auth=self.auth, tls=self.tls) + auth=self.auth, tls=self.tls, qos=self.qos) def publish_multiple(self, topic, msg): publish.multiple(topic, msg, hostname=self.hostname, port=self.port, client_id=self.client_id, keepalive=self.keepalive, will=self.will, - auth=self.auth, tls=self.tls) + auth=self.auth, tls=self.tls, qos=self.qos) def process_event(event, base_topic): @@ -86,12 +87,18 @@ def main(): if mqtt_password: auth['password'] = mqtt_password base_topic = config.get('mqtt', 'base_topic') + # Max QOS + if config.has_option('mqtt', 'qos'): + mqtt_qos = config.getint('mqtt', 'qos') + else: + mqtt_qos = 0 mqttqueue = PushMQTT( config.get('mqtt', 'hostname'), port=mqtt_port, keepalive=keepalive, - auth=auth) + auth=auth, + qos=mqtt_qos) # IMAP email settings imap_server = config.get('imap', 'hostname')