diff --git a/doors.py b/doors.py index 0cb42fc..52fffa4 100755 --- a/doors.py +++ b/doors.py @@ -154,8 +154,8 @@ RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1) def read_key(): RFID_SERIAL.reset_input_buffer() # Clear input buffer before reading string = RFID_SERIAL.read(12) - if len(string) > 0: - key = string[1:11].decode() #exclude start x0A and stop x0D bytes + if len(string) == 12 and string[0] == 0xA and string[-1] == 0xD: + key = string[1:11].decode() #exclude start 0xA and stop 0xD bytes if key.isalnum(): return key; return None @@ -166,7 +166,7 @@ def read_rfid(): if key and verify_key(key): unlock_door() time.sleep(5) # block for 5 seconds before resetting door - lock_door() + lock_door() flush_keys() except Exception as e: print(e)