diff options
Diffstat (limited to 'iot_barcode_scanner/mqtt.py')
-rw-r--r-- | iot_barcode_scanner/mqtt.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/iot_barcode_scanner/mqtt.py b/iot_barcode_scanner/mqtt.py new file mode 100644 index 0000000..c5a075c --- /dev/null +++ b/iot_barcode_scanner/mqtt.py @@ -0,0 +1,27 @@ + + +"""Provide MQTT Functionality for the Package""" + + +import paho.mqtt.client as mqtt + + +class MqttService(): + """Bundle for MQTT Functionality""" + + def __init__(self, config): + self.config = config + self.client = mqtt.Client() + self.client.on_connect = self.on_connect + + def run(self): + self.client.connect( + self.config["mqtt"]["broker"], + self.config["mqtt"]["port"], + 60 + ) + self.client.loop_start() + + def on_connect(self, client, userdata, flags, rc): + print("Connected with result code " + str(rc)) + client.subscribe(self.config["mqtt"]["topic"]) |