From 6829d05453658a9f9672c847299c652b15126db1 Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 30 Oct 2020 10:49:55 +0100 Subject: Introduce iot-barcode.target --- iot_barcode_transmitter | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 iot_barcode_transmitter (limited to 'iot_barcode_transmitter') diff --git a/iot_barcode_transmitter b/iot_barcode_transmitter new file mode 100755 index 0000000..5b08111 --- /dev/null +++ b/iot_barcode_transmitter @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + + +"""Executable to transmit the Barcode Data to MQTT without root Priviledges""" + + +from iot_barcode.static import KEYMAP +import iot_barcode.config as config +from iot_barcode.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() + + barcode = "" + + while True: + with open(fifo_path, "r") as fifo: + keycode = fifo.read() + character = KEYMAP[keycode] + if character is "\n": + mqtt_service.client.publish( + topic, + payload=barcode, + qos=0, + retain=False + ) + barcode = "" + else: + barcode += character + + except KeyboardInterrupt: + pass + + +if __name__ == "__main__": + main() -- cgit v1.2.3-70-g09d2