summaryrefslogtreecommitdiff
path: root/barcode_transmit_daemon.py
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-10-15 12:48:30 +0200
committerxengineering <mail2xengineering@protonmail.com>2020-10-15 12:48:30 +0200
commit3f739baab456c2cc977f11090381d1f61eb023c4 (patch)
treea35293cd7a0164601213bdfbd10774a1e998ebc1 /barcode_transmit_daemon.py
parent449b490f233371fe28e9089a05982cd5634285d2 (diff)
downloadiot-barcode-scanner-3f739baab456c2cc977f11090381d1f61eb023c4.tar
iot-barcode-scanner-3f739baab456c2cc977f11090381d1f61eb023c4.tar.zst
iot-barcode-scanner-3f739baab456c2cc977f11090381d1f61eb023c4.zip
Split Executable to reduce root-priviledged Code Execution
Diffstat (limited to 'barcode_transmit_daemon.py')
-rw-r--r--barcode_transmit_daemon.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/barcode_transmit_daemon.py b/barcode_transmit_daemon.py
new file mode 100644
index 0000000..4edb72d
--- /dev/null
+++ b/barcode_transmit_daemon.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python3
+
+
+"""Executable to transmit the Barcode Data to MQTT without root Priviledges"""
+
+
+import iot_barcode_scanner.config as config
+from iot_barcode_scanner.mqtt import MqttService
+
+
+def main():
+ try:
+
+ # read config
+ cfg = config.get_config()
+ fifo_path = cfg["scanner"]["fifo_path"]
+ topic = cfg["mqtt"]["topic"]
+
+ # setup mqtt
+ mqtt_service = MqttService(cfg)
+ mqtt_service.run()
+
+ while True:
+ with open(fifo_path, "r") as fifo:
+ text = fifo.read()
+ mqtt_service.client.publish(
+ topic,
+ payload=text,
+ qos=0,
+ retain=False
+ )
+
+ except KeyboardInterrupt:
+ pass
+
+
+if __name__ == "__main__":
+ main()