fixing the door levels

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

19
main.py
View File

@ -33,6 +33,8 @@ On Windows, the native WebAuthn API will be used.
""" """
import time import time
import configparser import configparser
gpie = False
if gpie:
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
import pickle import pickle
import psycopg2 import psycopg2
@ -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,16 +59,19 @@ dbhost = config.get('Setup', 'dbhost')
doorID = config.get('Setup', 'doorID') doorID = config.get('Setup', 'doorID')
gotAaguid = None gotAaguid = None
if gpie:
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
secLevel = 0 secLevel = 0
user_id = None
greenLed = 14 greenLed = 14
redLed = 4 redLed = 4
door = 21 door = 21
if gpie:
# badCredentials = False # badCredentials = False
GPIO.setup(greenLed, GPIO.OUT) GPIO.setup(greenLed, GPIO.OUT)
GPIO.output(greenLed, GPIO.LOW) GPIO.output(greenLed, GPIO.LOW)
@ -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)