diff options
author | xengineering <mail2xengineering@protonmail.com> | 2020-10-29 12:11:32 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2020-10-29 12:15:46 +0100 |
commit | 84b9ddcc2905f5d8667cfef1359b724c23d27365 (patch) | |
tree | 4e5a4c9ba39d8ec8c1a63a2bda4d7e9fc402ae40 | |
parent | 56503ecf9bccd9a318142e2946f84e5f57be5eeb (diff) | |
download | iot-barcode-scanner-84b9ddcc2905f5d8667cfef1359b724c23d27365.tar iot-barcode-scanner-84b9ddcc2905f5d8667cfef1359b724c23d27365.tar.zst iot-barcode-scanner-84b9ddcc2905f5d8667cfef1359b724c23d27365.zip |
Setup basic Systemd Units
-rw-r--r-- | Makefile | 27 | ||||
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | config.json | 6 | ||||
-rw-r--r-- | iot-barcode-device-handler.service | 12 | ||||
-rw-r--r-- | iot-barcode.service | 14 | ||||
-rw-r--r-- | iot_barcode/__init__.py | 0 | ||||
-rw-r--r-- | iot_barcode/config.py (renamed from iot_barcode_scanner/config.py) | 3 | ||||
-rw-r--r-- | iot_barcode/mqtt.py (renamed from iot_barcode_scanner/mqtt.py) | 1 | ||||
-rw-r--r-- | iot_barcode/static.py (renamed from iot_barcode_scanner/static.py) | 2 | ||||
-rwxr-xr-x | iot_barcode_daemon (renamed from barcode_transmit_daemon.py) | 6 | ||||
-rwxr-xr-x | iot_barcode_device_handler (renamed from barcode_scanner_daemon.py) | 2 | ||||
-rw-r--r-- | iot_barcode_scanner/__init__.py | 5 |
12 files changed, 60 insertions, 31 deletions
@@ -1,6 +1,6 @@ -PKGNAME=iot_barcode_scanner +PKGNAME=iot_barcode PREFIX=/usr INSTALL=install INSTALL_PROGRAM=$(INSTALL) -m 755 @@ -8,8 +8,9 @@ INSTALL_DATA=$(INSTALL) -m 644 bindir=$(DESTDIR)$(PREFIX)/bin sharedir=$(DESTDIR)$(PREFIX)/share -confdir=$(DESTDIR)/etc/xengineering.eu/$(PKGNAME) +confdir=$(DESTDIR)/etc/$(PKGNAME) libdir=$(DESTDIR)$(PREFIX)/lib/python3/dist-packages/$(PKGNAME) +systemddir=$(DESTDIR)/lib/systemd/system .PHONY: install uninstall @@ -19,20 +20,24 @@ install: # install executables mkdir -p $(bindir) - $(INSTALL_PROGRAM) barcode_scanner_daemon.py $(bindir)/eu.xengineering.$(PKGNAME).scanner - $(INSTALL_PROGRAM) barcode_transmit_daemon.py $(bindir)/eu.xengineering.$(PKGNAME).transmitter + $(INSTALL_PROGRAM) iot_barcode_device_handler $(bindir)/ + $(INSTALL_PROGRAM) iot_barcode_daemon $(bindir)/ # install library / package mkdir -p $(libdir)/ - $(INSTALL_DATA) iot_barcode_scanner/__init__.py $(libdir)/__init__.py - $(INSTALL_DATA) iot_barcode_scanner/config.py $(libdir)/config.py - $(INSTALL_DATA) iot_barcode_scanner/mqtt.py $(libdir)/mqtt.py - $(INSTALL_DATA) iot_barcode_scanner/static.py $(libdir)/static.py + $(INSTALL_DATA) iot_barcode/__init__.py $(libdir)/__init__.py + $(INSTALL_DATA) iot_barcode/config.py $(libdir)/config.py + $(INSTALL_DATA) iot_barcode/mqtt.py $(libdir)/mqtt.py + $(INSTALL_DATA) iot_barcode/static.py $(libdir)/static.py # install config file mkdir -p $(confdir)/ $(INSTALL_DATA) config.json $(confdir)/config.json + # install systemd unit files + $(INSTALL_DATA) iot-barcode.service $(systemddir)/ + $(INSTALL_DATA) iot-barcode-device-handler.service $(systemddir)/ + # install license mkdir -p $(sharedir)/licenses/ $(INSTALL_DATA) LICENSE $(sharedir)/licenses/$(PKGNAME) @@ -40,10 +45,12 @@ install: uninstall: - rm -f $(bindir)/eu.xengineering.$(PKGNAME).scanner - rm -f $(bindir)/eu.xengineering.$(PKGNAME).transmitter + rm -f $(bindir)/iot_barcode_device_handler + rm -f $(bindir)/iot_barcode_daemon rm -f $(libdir)/__init__.py rm -f $(libdir)/config.py rm -f $(libdir)/mqtt.py rm -f $(libdir)/static.py + rm -f $(systemddir)/iot-barcode.service + rm -f $(systemddir)/iot-barcode-device-handler.service rm -f $(sharedir)/licenses/$(PKGNAME) @@ -13,11 +13,12 @@ A service that makes barcode scanners available on the network for IoT use. git clone https://github.com/xengineering/iot-barcode-scanner.git cd iot-barcode-scanner sudo make install + sudo useradd -Urs /usr/bin/nologin iotbarcode ``` -2. Configure ```/etc/xengineering.eu/iot_barcode_scanner/config.json``` -3. Run ```sudo eu.xengineering.iot_barcode_scanner.scanner &``` -4. Run ```eu.xengineering.iot_barcode_scanner.transmitter &``` -5. Listen to MQTT output (e.g. with ```mosquitto_sub -h localhost -t "xengineering.eu/iot-barcode-scanner"```) +2. Configure ```/etc/iot_barcode/config.json``` +3. Run ```sudo systemctl enable --now iot-barcode-device-handler``` +4. Run ```sudo systemctl enable --now iot-barcode``` +5. Listen to MQTT output (e.g. with ```mosquitto_sub -h localhost -t "xengineering.eu/iot-barcode"```) ## Milestones @@ -27,10 +28,10 @@ A service that makes barcode scanners available on the network for IoT use. - [x] Disable scanner as regular input source and bind it only to the service - [x] Split into two executables to reduce root-priviledged code - [x] Write Makefile for easy installation +- [x] Implement systemd services +- [ ] Package it for Arch Linux - [ ] Make python package installation portable across linux distributions -- [ ] Implement systemd services - [ ] Implement auto discovery of barcode scanners -- [ ] Package it for Arch Linux ## Dependencies diff --git a/config.json b/config.json index 223dbcf..9ee7179 100644 --- a/config.json +++ b/config.json @@ -2,10 +2,10 @@ "mqtt":{ "broker":"127.0.0.1", "port":1883, - "topic":"xengineering.eu/iot-barcode-scanner" + "topic":"xengineering.eu/iot-barcode" }, "scanner":{ - "evdev_path":"/dev/input/event4", - "fifo_path":"/tmp/xengineering.eu/iot-barcode-scanner/scanner_fifo" + "evdev_path":"/dev/input/event0", + "fifo_path":"/tmp/iot-barcode/scanner_fifo" } } diff --git a/iot-barcode-device-handler.service b/iot-barcode-device-handler.service new file mode 100644 index 0000000..8933cfd --- /dev/null +++ b/iot-barcode-device-handler.service @@ -0,0 +1,12 @@ + +[Unit] +Description=A Daemon to read Barcodes from a specified Barcode Reader + +[Service] +Type=simple +ExecStart=/usr/bin/iot_barcode_device_handler +User=root +Group=root + +[Install] +WantedBy=default.target diff --git a/iot-barcode.service b/iot-barcode.service new file mode 100644 index 0000000..fbd9940 --- /dev/null +++ b/iot-barcode.service @@ -0,0 +1,14 @@ + +[Unit] +Description=A Daemon to transmit Barcodes to an MQTT Broker +Requires=iot-barcode-device-handler.service +After=iot-barcode-device-handler.service + +[Service] +Type=simple +ExecStart=/usr/bin/iot_barcode_daemon +User=iotbarcode +Group=iotbarcode + +[Install] +WantedBy=default.target 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_scanner/config.py b/iot_barcode/config.py index 6b83393..7435f8b 100644 --- a/iot_barcode_scanner/config.py +++ b/iot_barcode/config.py @@ -5,7 +5,8 @@ import sys import json -from iot_barcode_scanner.static import CONFIG_PATH + +from iot_barcode.static import CONFIG_PATH def get_config(): diff --git a/iot_barcode_scanner/mqtt.py b/iot_barcode/mqtt.py index c5a075c..2b0ece1 100644 --- a/iot_barcode_scanner/mqtt.py +++ b/iot_barcode/mqtt.py @@ -23,5 +23,4 @@ class MqttService(): 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"]) diff --git a/iot_barcode_scanner/static.py b/iot_barcode/static.py index af76683..638f017 100644 --- a/iot_barcode_scanner/static.py +++ b/iot_barcode/static.py @@ -3,7 +3,7 @@ """Module to store static Data for the whole Package""" -CONFIG_PATH = "/etc/xengineering.eu/iot_barcode_scanner/config.json" +CONFIG_PATH = "/etc/iot_barcode/config.json" KEYMAP = { "KEY_0": "0", diff --git a/barcode_transmit_daemon.py b/iot_barcode_daemon index a2d7eb6..5b08111 100755 --- a/barcode_transmit_daemon.py +++ b/iot_barcode_daemon @@ -4,9 +4,9 @@ """Executable to transmit the Barcode Data to MQTT without root Priviledges""" -from iot_barcode_scanner.static import KEYMAP -import iot_barcode_scanner.config as config -from iot_barcode_scanner.mqtt import MqttService +from iot_barcode.static import KEYMAP +import iot_barcode.config as config +from iot_barcode.mqtt import MqttService def main(): diff --git a/barcode_scanner_daemon.py b/iot_barcode_device_handler index 09139f7..5c05aab 100755 --- a/barcode_scanner_daemon.py +++ b/iot_barcode_device_handler @@ -7,7 +7,7 @@ import evdev import os -import iot_barcode_scanner.config as config +import iot_barcode.config as config def main(): diff --git a/iot_barcode_scanner/__init__.py b/iot_barcode_scanner/__init__.py deleted file mode 100644 index 6f92d9b..0000000 --- a/iot_barcode_scanner/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ - - -from iot_barcode_scanner.config import * -from iot_barcode_scanner.mqtt import * -from iot_barcode_scanner.static import * |