From 2cec7a3e0b2733ffe1cd11878828bf8a9416eaee Mon Sep 17 00:00:00 2001 From: caschick221 Date: Mon, 6 May 2024 16:26:33 -0400 Subject: [PATCH] fixing the door levels --- main.py | 85 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/main.py b/main.py index 4ee7d44..4f900fb 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,9 @@ On Windows, the native WebAuthn API will be used. """ import time import configparser -import RPi.GPIO as GPIO +gpie = False +if gpie: + import RPi.GPIO as GPIO import pickle import psycopg2 import fido2.webauthn @@ -49,6 +51,7 @@ config = configparser.ConfigParser() config.read('config.ini') + dbusername = config.get('Setup', 'dbusername') dbpassword = config.get('Setup', 'dbpassword') dbname = config.get('Setup', 'dbname') @@ -56,33 +59,36 @@ dbhost = config.get('Setup', 'dbhost') doorID = config.get('Setup', 'doorID') gotAaguid = None -GPIO.setmode(GPIO.BCM) +if gpie: + GPIO.setmode(GPIO.BCM) secLevel = 0 - +user_id = None greenLed = 14 redLed = 4 door = 21 -# badCredentials = False -GPIO.setup(greenLed, GPIO.OUT) -GPIO.output(greenLed, GPIO.LOW) -GPIO.setup(redLed, GPIO.OUT) -GPIO.output(redLed, GPIO.HIGH) -time.sleep(1) -GPIO.output(redLed, GPIO.LOW) -time.sleep(0.2) +if gpie: + # badCredentials = False + GPIO.setup(greenLed, GPIO.OUT) + GPIO.output(greenLed, GPIO.LOW) + GPIO.setup(redLed, GPIO.OUT) -GPIO.output(greenLed, GPIO.HIGH) -time.sleep(1) -GPIO.output(greenLed, GPIO.LOW) -time.sleep(0.2) + GPIO.output(redLed, GPIO.HIGH) + time.sleep(1) + GPIO.output(redLed, GPIO.LOW) + time.sleep(0.2) -GPIO.setup(door, GPIO.OUT) -GPIO.output(door, GPIO.LOW) + GPIO.output(greenLed, GPIO.HIGH) + time.sleep(1) + GPIO.output(greenLed, GPIO.LOW) + time.sleep(0.2) + + GPIO.setup(door, GPIO.OUT) + GPIO.output(door, GPIO.LOW) def badCred(): print("Bad credential!") # badCredentials = True @@ -101,12 +107,13 @@ class CliInteraction(UserInteraction): while True: - - GPIO.output(door, GPIO.LOW) - # GPIO.output(14, GPIO.LOW) + if gpie: + GPIO.output(door, GPIO.LOW) + # GPIO.output(14, GPIO.LOW) print("Waiting for device...") badCredentials = False - GPIO.output(redLed, GPIO.HIGH) + if gpie: + GPIO.output(redLed, GPIO.HIGH) while True: try: # GPIO.output(14, GPIO.LOW) @@ -195,8 +202,10 @@ while True: # Example usage: Fetch data for a specific AAGUID and store in variables aaguid_data = None aaguid_data = fetch_data("") + user_id = aaguid_data["user_id"] if aaguid_data: + # Store each piece of data into a separate variable testa = aaguid_data["AAGUID"] cred_id = aaguid_data["credential_id"] @@ -251,7 +260,7 @@ while True: WHERE "user_id" = %s; ''' # Execute the SQL query - cur.execute(select_query, (result[1])) + cur.execute(select_query, (str(user_id))) # Fetch the results result = None @@ -279,7 +288,7 @@ while True: cur = conn.cursor() select_query = ''' SELECT sec_level - FROM door + FROM doors WHERE "door_id" = %s; ''' # Execute the SQL query @@ -307,24 +316,26 @@ while True: if doorSecLevel < userSecLevel: raise Exception - GPIO.output(redLed, GPIO.LOW) - for i in range(2): - GPIO.output(greenLed, GPIO.HIGH) - time.sleep(0.05) - GPIO.output(greenLed, GPIO.LOW) - time.sleep(0.05) + if gpie: + GPIO.output(redLed, GPIO.LOW) + for i in range(2): + GPIO.output(greenLed, GPIO.HIGH) + time.sleep(0.05) + GPIO.output(greenLed, GPIO.LOW) + time.sleep(0.05) - GPIO.output(greenLed, GPIO.HIGH) - GPIO.output(door, GPIO.HIGH) - time.sleep(5) - GPIO.output(greenLed, GPIO.LOW) + GPIO.output(greenLed, GPIO.HIGH) + GPIO.output(door, GPIO.HIGH) + time.sleep(5) + GPIO.output(greenLed, GPIO.LOW) except Exception as e: print("Authentication Failed!") for i in range(5): - GPIO.output(redLed, GPIO.LOW) - time.sleep(0.05) - GPIO.output(redLed, GPIO.HIGH) - time.sleep(0.05) + if gpie: + GPIO.output(redLed, GPIO.LOW) + time.sleep(0.05) + GPIO.output(redLed, GPIO.HIGH) + time.sleep(0.05)