diff --git a/mts-iot-apps/OpenMts.AutomaticCheckIn/AutomaticCheckIn.py b/mts-iot-apps/OpenMts.AutomaticCheckIn/AutomaticCheckIn.py new file mode 100644 index 0000000..dbb61ad --- /dev/null +++ b/mts-iot-apps/OpenMts.AutomaticCheckIn/AutomaticCheckIn.py @@ -0,0 +1,55 @@ +import time +import serial +import RPi.GPIO as GPIO +import sys +import configparser +sys.path.append('/home/pi/MFRC522-python') +from mfrc522 import SimpleMFRC522 + +def connect_to_scale(port): + ser = serial.Serial("/dev/ttyUSB0", timeout=1) + return ser + +def convert_value(scale_response): + low = int(scale_response.find(' ')+1) + high = int(scale_response.find('k')) + quantity = float(scale_response[low:high]) + return quantity + +# Get config +config = configparser.ConfigParser() +config.read('./config.ini') +print(config.sections()) +server = config["Server"]["Endpoint"] +apiKey = config["Server"]["ApiKey"] +scalePort = config["Scale"]["UsbPort"] + +# Output config +print("Configuration:") +print(" + Server: " + server) +print(" + API-Key: " + apiKey) +print(" + Scale USB port: " + scalePort) + +# Start reading +reader = SimpleMFRC522() +print("Pleace hold material-card next to the reader") +try: + while True: + id, matnr_card = reader.read() + ser = connect_to_scale(scalePort) + + # Get weight + raw_decode = bytes('S','utf-8') + ser.write(raw_decode) + scale_response = ser.readline() + print(scale_response) + quantity = convert_value(str(scale_response)) + weight_formated = '{0:0.2f}'.format(quantity) + print(" - Read weight: " + str(quantity) + ) + time.sleep(1) + print("Pleace hold material-card next to the reader") +except KeyboardInterrupt: + GPIO.cleanup() +except Exception as exception: + print(exception) + GPIO.cleanup() diff --git a/mts-iot-apps/OpenMts.AutomaticCheckIn/README.md b/mts-iot-apps/OpenMts.AutomaticCheckIn/README.md new file mode 100644 index 0000000..ac3953d --- /dev/null +++ b/mts-iot-apps/OpenMts.AutomaticCheckIn/README.md @@ -0,0 +1,15 @@ +# AutomaticCheckIn + +Tested on a Raspberry Pi 4 Model B. + +## Installation + +### Python Packages + +Install on Raspberry Pi: + +- [MFRC522-python](https://github.com/pimylifeup/MFRC522-python) + +Install on Raspberry Pi with pip3: + +- `pyserial` diff --git a/mts-iot-apps/OpenMts.AutomaticCheckIn/config.ini b/mts-iot-apps/OpenMts.AutomaticCheckIn/config.ini new file mode 100644 index 0000000..9ccb7b6 --- /dev/null +++ b/mts-iot-apps/OpenMts.AutomaticCheckIn/config.ini @@ -0,0 +1,6 @@ +[Server] +Endpoint = "http://localhost:5000" +ApiKey = "todo" + +[Scale] +UsbPort = "/dev/ttyUSB0" \ No newline at end of file