Skip to content

Python script hanging #3

Description

@stanwin00

Hi,

I'm experiencing an issue where the python script hangs and the rfid reader crashes. The script is based off the SimpleMFRC522 library. Have you experience this before?

My current code is this:

`reader = SimpleMFRC522()

try:
# Welcome message
print("Welcome to the MFRC522 data read example")
print("Press Ctrl-C to stop.")
id = None

while True:
    dbConnection = pymysql.connect(
        host=config.host, user=config.user, passwd=config.passd, db=config.dbname, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
    cur = dbConnection.cursor()
    # Get the UID of the card
    id = reader.read_id()
    print(id)
    cur.execute("SELECT * FROM access_list_2 WHERE rfid_code = %s;", (id,))
    if cur.rowcount != 1:
        print ("Access Denied")
        # Log access attempt
        cur.execute("INSERT INTO access_log SET rfid_presented = %s, rfid_presented_datetime = NOW(), rfid_granted = 0", (id,))
        dbConnection.commit()
        id = None
        dbConnection.close()
    else:
        GPIO.output(12, GPIO.HIGH)
        # Log access attempt
        cur.execute("INSERT INTO access_log SET rfid_presented = %s, rfid_presented_datetime = NOW(), rfid_granted = 1", (id,))
        dbConnection.commit()
        time.sleep(5)
        GPIO.output(12, GPIO.LOW)
        id = None
        dbConnection.close()
   time.sleep(1)

except:
logging.exception("message")
finally:
GPIO.cleanup()
raise
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions