diff options
Diffstat (limited to 'iot_barcode')
-rw-r--r-- | iot_barcode/__init__.py | 0 | ||||
-rw-r--r-- | iot_barcode/config.py | 24 | ||||
-rw-r--r-- | iot_barcode/mqtt.py | 26 | ||||
-rw-r--r-- | iot_barcode/static.py | 20 |
4 files changed, 70 insertions, 0 deletions
diff --git a/iot_barcode/__init__.py b/iot_barcode/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/iot_barcode/__init__.py diff --git a/iot_barcode/config.py b/iot_barcode/config.py new file mode 100644 index 0000000..7435f8b --- /dev/null +++ b/iot_barcode/config.py @@ -0,0 +1,24 @@ + + +"""Module to read the Configuration File for the Service""" + + +import sys +import json + +from iot_barcode.static import CONFIG_PATH + + +def get_config(): + """Read Config File and return it as Python Object""" + + try: + with open(CONFIG_PATH, "r") as config_file: + text = config_file.read() + except FileNotFoundError: + print("Config file does not exist.") + sys.exit(1) + + data = json.loads(text) + + return data diff --git a/iot_barcode/mqtt.py b/iot_barcode/mqtt.py new file mode 100644 index 0000000..2b0ece1 --- /dev/null +++ b/iot_barcode/mqtt.py @@ -0,0 +1,26 @@ + + +"""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): + client.subscribe(self.config["mqtt"]["topic"]) diff --git a/iot_barcode/static.py b/iot_barcode/static.py new file mode 100644 index 0000000..638f017 --- /dev/null +++ b/iot_barcode/static.py @@ -0,0 +1,20 @@ + + +"""Module to store static Data for the whole Package""" + + +CONFIG_PATH = "/etc/iot_barcode/config.json" + +KEYMAP = { + "KEY_0": "0", + "KEY_1": "1", + "KEY_2": "2", + "KEY_3": "3", + "KEY_4": "4", + "KEY_5": "5", + "KEY_6": "6", + "KEY_7": "7", + "KEY_8": "8", + "KEY_9": "9", + "KEY_ENTER": "\n", +} |