fixing the door levels
This commit is contained in:
parent
c491ae0db3
commit
2cec7a3e0b
51
main.py
51
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,11 +107,12 @@ class CliInteraction(UserInteraction):
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
if gpie:
|
||||
GPIO.output(door, GPIO.LOW)
|
||||
# GPIO.output(14, GPIO.LOW)
|
||||
print("Waiting for device...")
|
||||
badCredentials = False
|
||||
if gpie:
|
||||
GPIO.output(redLed, GPIO.HIGH)
|
||||
while True:
|
||||
try:
|
||||
@ -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,6 +316,7 @@ while True:
|
||||
if doorSecLevel < userSecLevel:
|
||||
raise Exception
|
||||
|
||||
if gpie:
|
||||
GPIO.output(redLed, GPIO.LOW)
|
||||
for i in range(2):
|
||||
GPIO.output(greenLed, GPIO.HIGH)
|
||||
@ -323,6 +333,7 @@ while True:
|
||||
except Exception as e:
|
||||
print("Authentication Failed!")
|
||||
for i in range(5):
|
||||
if gpie:
|
||||
GPIO.output(redLed, GPIO.LOW)
|
||||
time.sleep(0.05)
|
||||
GPIO.output(redLed, GPIO.HIGH)
|
||||
|
Loading…
Reference in New Issue
Block a user