Updates for key validation:
- Check the start and stop bytes of the RFID message in addition to the expected length to prevent crashes. - There is no need to re-lock the door if it was never unlocked. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
71db8b6220
commit
7296900ddf
6
doors.py
6
doors.py
|
@ -154,8 +154,8 @@ RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1)
|
||||||
def read_key():
|
def read_key():
|
||||||
RFID_SERIAL.reset_input_buffer() # Clear input buffer before reading
|
RFID_SERIAL.reset_input_buffer() # Clear input buffer before reading
|
||||||
string = RFID_SERIAL.read(12)
|
string = RFID_SERIAL.read(12)
|
||||||
if len(string) > 0:
|
if len(string) == 12 and string[0] == 0xA and string[-1] == 0xD:
|
||||||
key = string[1:11].decode() #exclude start x0A and stop x0D bytes
|
key = string[1:11].decode() #exclude start 0xA and stop 0xD bytes
|
||||||
if key.isalnum():
|
if key.isalnum():
|
||||||
return key;
|
return key;
|
||||||
return None
|
return None
|
||||||
|
@ -166,7 +166,7 @@ def read_rfid():
|
||||||
if key and verify_key(key):
|
if key and verify_key(key):
|
||||||
unlock_door()
|
unlock_door()
|
||||||
time.sleep(5) # block for 5 seconds before resetting door
|
time.sleep(5) # block for 5 seconds before resetting door
|
||||||
lock_door()
|
lock_door()
|
||||||
flush_keys()
|
flush_keys()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Reference in New Issue