fixing the door levels

This commit is contained in:
caschick221 2024-05-06 16:26:33 -04:00
parent c491ae0db3
commit 2cec7a3e0b

51
main.py
View File

@ -33,7 +33,9 @@ On Windows, the native WebAuthn API will be used.
""" """
import time import time
import configparser import configparser
import RPi.GPIO as GPIO gpie = False
if gpie:
import RPi.GPIO as GPIO
import pickle import pickle
import psycopg2 import psycopg2
import fido2.webauthn import fido2.webauthn
@ -49,6 +51,7 @@ config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
dbusername = config.get('Setup', 'dbusername') dbusername = config.get('Setup', 'dbusername')
dbpassword = config.get('Setup', 'dbpassword') dbpassword = config.get('Setup', 'dbpassword')
dbname = config.get('Setup', 'dbname') dbname = config.get('Setup', 'dbname')
@ -56,33 +59,36 @@ dbhost = config.get('Setup', 'dbhost')
doorID = config.get('Setup', 'doorID') doorID = config.get('Setup', 'doorID')
gotAaguid = None gotAaguid = None
GPIO.setmode(GPIO.BCM) if gpie:
GPIO.setmode(GPIO.BCM)
secLevel = 0 secLevel = 0
user_id = None
greenLed = 14 greenLed = 14
redLed = 4 redLed = 4
door = 21 door = 21
# badCredentials = False
GPIO.setup(greenLed, GPIO.OUT)
GPIO.output(greenLed, GPIO.LOW)
GPIO.setup(redLed, GPIO.OUT)
GPIO.output(redLed, GPIO.HIGH) if gpie:
time.sleep(1) # badCredentials = False
GPIO.output(redLed, GPIO.LOW) GPIO.setup(greenLed, GPIO.OUT)
time.sleep(0.2) GPIO.output(greenLed, GPIO.LOW)
GPIO.setup(redLed, GPIO.OUT)
GPIO.output(greenLed, GPIO.HIGH) GPIO.output(redLed, GPIO.HIGH)
time.sleep(1) time.sleep(1)
GPIO.output(greenLed, GPIO.LOW) GPIO.output(redLed, GPIO.LOW)
time.sleep(0.2) time.sleep(0.2)
GPIO.setup(door, GPIO.OUT) GPIO.output(greenLed, GPIO.HIGH)
GPIO.output(door, GPIO.LOW) time.sleep(1)
GPIO.output(greenLed, GPIO.LOW)
time.sleep(0.2)
GPIO.setup(door, GPIO.OUT)
GPIO.output(door, GPIO.LOW)
def badCred(): def badCred():
print("Bad credential!") print("Bad credential!")
# badCredentials = True # badCredentials = True
@ -101,11 +107,12 @@ class CliInteraction(UserInteraction):
while True: while True:
if gpie:
GPIO.output(door, GPIO.LOW) GPIO.output(door, GPIO.LOW)
# GPIO.output(14, GPIO.LOW) # GPIO.output(14, GPIO.LOW)
print("Waiting for device...") print("Waiting for device...")
badCredentials = False badCredentials = False
if gpie:
GPIO.output(redLed, GPIO.HIGH) GPIO.output(redLed, GPIO.HIGH)
while True: while True:
try: try:
@ -195,8 +202,10 @@ while True:
# Example usage: Fetch data for a specific AAGUID and store in variables # Example usage: Fetch data for a specific AAGUID and store in variables
aaguid_data = None aaguid_data = None
aaguid_data = fetch_data("") aaguid_data = fetch_data("")
user_id = aaguid_data["user_id"]
if aaguid_data: if aaguid_data:
# Store each piece of data into a separate variable # Store each piece of data into a separate variable
testa = aaguid_data["AAGUID"] testa = aaguid_data["AAGUID"]
cred_id = aaguid_data["credential_id"] cred_id = aaguid_data["credential_id"]
@ -251,7 +260,7 @@ while True:
WHERE "user_id" = %s; WHERE "user_id" = %s;
''' '''
# Execute the SQL query # Execute the SQL query
cur.execute(select_query, (result[1])) cur.execute(select_query, (str(user_id)))
# Fetch the results # Fetch the results
result = None result = None
@ -279,7 +288,7 @@ while True:
cur = conn.cursor() cur = conn.cursor()
select_query = ''' select_query = '''
SELECT sec_level SELECT sec_level
FROM door FROM doors
WHERE "door_id" = %s; WHERE "door_id" = %s;
''' '''
# Execute the SQL query # Execute the SQL query
@ -307,6 +316,7 @@ while True:
if doorSecLevel < userSecLevel: if doorSecLevel < userSecLevel:
raise Exception raise Exception
if gpie:
GPIO.output(redLed, GPIO.LOW) GPIO.output(redLed, GPIO.LOW)
for i in range(2): for i in range(2):
GPIO.output(greenLed, GPIO.HIGH) GPIO.output(greenLed, GPIO.HIGH)
@ -323,6 +333,7 @@ while True:
except Exception as e: except Exception as e:
print("Authentication Failed!") print("Authentication Failed!")
for i in range(5): for i in range(5):
if gpie:
GPIO.output(redLed, GPIO.LOW) GPIO.output(redLed, GPIO.LOW)
time.sleep(0.05) time.sleep(0.05)
GPIO.output(redLed, GPIO.HIGH) GPIO.output(redLed, GPIO.HIGH)