diff --git a/authorized_cards.db b/authorized_cards.db index e2b6073..d4720a3 100644 Binary files a/authorized_cards.db and b/authorized_cards.db differ diff --git a/lock.py b/lock.py new file mode 100644 index 0000000..79ea524 --- /dev/null +++ b/lock.py @@ -0,0 +1,25 @@ +import RPi.GPIO as GPIO +import time + +GPIO.setmode(GPIO.BOARD) + +UNLOCK_PIN = 12 +LOCK_PIN = 11 +DELAY = 0.25 + +GPIO.setup(UNLOCK_PIN, GPIO.OUT) +GPIO.setup(LOCK_PIN, GPIO.OUT) + +GPIO.output(UNLOCK_PIN, GPIO.LOW) +GPIO.output(LOCK_PIN, GPIO.LOW) + +def unlock(): + GPIO.output(UNLOCK_PIN, GPIO.HIGH) + time.sleep(DELAY) + GPIO.output(UNLOCK_PIN, GPIO.LOW) + +def lock(): + GPIO.output(LOCK_PIN, GPIO.HIGH) + time.sleep(DELAY) + GPIO.output(LOCK_PIN, GPIO.LOW) + diff --git a/main.py b/main.py index 411d3b3..a0ec09b 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,8 @@ import time import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 +import lock + class DoorLock(): def __init__(self): # initialize card reader @@ -43,7 +45,9 @@ class DoorLock(): def unlock_door(self): # TODO send command to open door lock + # not implemented yet print("Unlocking door!\n\n") + lock.unlock() def release_the_kraken(self): # TODO notify that authentication failed @@ -53,7 +57,7 @@ class DoorLock(): def run_authorization(self): try: while True: - print("Hold card before reader..") + print("Hold card in front of reader..") uid, data = self.reader.read() print("card read: \n uid = {}\ndata = {}\n".format(hex(uid), data)) @@ -69,17 +73,16 @@ class DoorLock(): self.release_the_kraken() time.sleep(1.5) finally: - #GPIO.cleanup() - pass + GPIO.cleanup() if __name__ == "__main__": # create database with some users - # conn = setup_db() - # with conn: - # create_user(conn, 'Simon', 4225799947, 0, str(datetime.utcnow()), str(datetime.utcnow())) - # create_user(conn, 'Valentin', 154921302, 0, str(datetime.utcnow()), str(datetime.utcnow())) - # users = select_all_users(conn) + conn = setup_db() + with conn: + create_user(conn, 'Simon', 141405954844, 0, str(datetime.utcnow()), str(datetime.utcnow())) + create_user(conn, 'Valentin', 154921302, 0, str(datetime.utcnow()), str(datetime.utcnow())) + users = select_all_users(conn) doors_of_durin = DoorLock() @@ -87,4 +90,4 @@ if __name__ == "__main__": data = 'Mellon!' #write_success = doors_of_durin.reader.write(data) doors_of_durin.run_authorization() - pass \ No newline at end of file + pass