import time import socket import subprocess import logging import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 reader = SimpleMFRC522() log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) #try: # while True: # (status, TagType) = reader.MFRC522_Request(MFRC522.PICC_REQIDL) # if status == MFRC522.MI_OK: # (status, uid) = reader.MFRC522_Anticoll() # if status == MFRC522.MI_OK: # uid_str = "-".join([str(x) for x in uid[:4]]) # print(f"Tag erkannt! UID: {uid_str}") # time.sleep(0.1) #state 0 = nicht da? #state 1 = ist da? try: while True: id, text = reader.read() idz = str(id) import subprocess subprocess.run([ "mosquitto_pub", "-h", "192.168.213.12", # -h -> Host; IP des Brokers "-t", "RFID", # -t -> Topic; "Gruppe" "-m", idz # -m -> Message; sendende Nachricht ]) print("RFID",id) time.sleep(10) finally: GPIO.cleanup() print("\nProgramm beendet.")