summaryrefslogtreecommitdiff
path: root/barcode_transmit_daemon.py
blob: 4edb72d8640c044e802426a633a1533ce1f948ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()