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
This commit is contained in:
Matthew Treinish 2016-09-07 23:06:08 -04:00
parent f391139791
commit d0d4f77e0d
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
1 changed files with 11 additions and 4 deletions

View File

@ -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')