working prototype for unlocking

master
Simon Pirkelmann 2020-08-03 22:24:03 +02:00
parent bc66a3a729
commit f24a10ccf6
3 changed files with 37 additions and 9 deletions

Binary file not shown.

25
lock.py Normal file
View File

@ -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)

21
main.py
View File

@ -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
pass