From f24a10ccf6c9e8d98f853c40dcee0ffa285354c0 Mon Sep 17 00:00:00 2001 From: spirkelmann Date: Mon, 3 Aug 2020 22:24:03 +0200 Subject: [PATCH] working prototype for unlocking --- authorized_cards.db | Bin 8192 -> 8192 bytes lock.py | 25 +++++++++++++++++++++++++ main.py | 21 ++++++++++++--------- 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 lock.py diff --git a/authorized_cards.db b/authorized_cards.db index e2b60737ee14e4343dad10f14cdc221a1457485c..d4720a3109e09d971d5daeee04262dc0c845365d 100644 GIT binary patch literal 8192 zcmeH~JC7Sx7>38ou5W956D~2A1P%}hg4p4F=YEC;gLXy{n?N?3NTDDy>;zfb^-8uQ zC@7F9_yk$3lQy}tJM``we6jN;EmT@t!vL%YqI()g}wYSjddhg`4?~#9o-=AMxt*lXt6%E=% zFRcaw8%T{zzM??&JkY!XR)sIF1e#S#Yq4u{K=TT>G$L*w5rFXpD9S|6C{;kR@C7GO zQZ0bPVjsadjh=S`F&%JB$O5%FqnW}O4==cYl4>L55+5V9)zNu3kPNu+DF`WZ39(dB zMupEgfs$&b)DjLaZ-#zg1bKs=y0WXy>Bj8a8W6+YzzN~$p) zn@c)XgcQ+}ZXg;k?hD*LL}uAz&r-!&8$RI#N~*Qwd7xC$2BOEEKpgiW>1zps=jPB% z!3h?gbpa*S!ct|j3C$GFWOQaJkltmQFbEh6nDPNM*L-SppCY*qca{O=tA$NhYhJ(dkIZ}5@j-E)fGTs z2`D`31CFZ<)TCeI>j1r*Q-qLFX$(}#oc4IFkdy-f8BiWb=`+J2jXJ%cpb$vh>HvGJ zqw*@EsgVqr_7$7%iqCx#z$E`8?&sUfr)5y9Uxry5=UNRk8?m%gD-l@3F`L delta 194 zcmZp0XmFSy&1gGO#+lJ}W5PmyZvK1*CVn*rel`BB8w+>vZfrz84@$QltwT37%LMY0TRq^Tj$G9yC+ FO8{M;Eu;Vd 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