def FindUser(self, rfid): self.lookingUpUser = True conn = self.Connect() c = conn.cursor() ID = int(rfid) c.execute( "SELECT Username,DoorLevel,Active FROM Users WHERE RFID = %s", ID) conn.commit() Row = c.fetchone() print(Row) if c.rowcount > 0: User = { 'Username': Row['Username'], 'DoorLevel': Row['DoorLevel'], 'Active': Row['Active'], 'RFID': ID, 'Message': None } if Row['Active'] == 0: User['Message'] = 'User is not active in the system' self.Fail(User['RFID'], User) else: Checks = self.DoorAccess(User, conn, c) else: self.Fail(ID, 'None') mail.ReadError( "No user found\nRFID: %d\r\nBuilding: %s\r\nDoor: %s" % (int(ID), self.building, self.door)) self.lookingUpUser = False
def Fail(self, ID, User): if User == 'None': User = {'Username': None, 'RFID': ID, 'Message': 'No User found'} else: mail.ReadError("User: %s\nRFID: %s\n%s" % (User['Username'], User['RFID'], User['Message'])) self.SendToServer(User)
def Start(self): failed = 0 while self.run: if self.switchPin and GPIO.input( self.switchPin) and debouncedInput( self.switchPin) and GPIO.input( self.relayPin) == self.__ON: GPIO.output(self.relayPin, self.__OFF) threading.Timer(5, self.turnOff).start() while GPIO.input(self.switchPin): pass if self.ser: try: self.ser.flushInput() except: self.ser.close() self.ser = False if self.ser and self.ser.isOpen() and self.lookingUpUser == False: failed = 0 try: while (self.ser.inWaiting()): rfid = self.read.readline() self.ser.flushInput() self.FindUser(rfid) except: self.ser.close() self.ser = False continue elif self.ser == False and self.openingPort == False: failed += 1 if failed == 1: mail.ReadError('Building ' + str(self.building) + ' ' + self.door + ' door reader has gone offline') self.openingPort = True self.OpenPort() self.__del__
def __del__(self): GPIO.output(self.relayPin, self.__OFF) mail.ReadError('Building ' + str(self.building) + ' ' + self.door + ' door script has gone offline door is now inactivated') class_name = self.__class__.__name__ print("\r\n------ ", class_name, "destroyed ------")
import serial import sys import mail from Functions import Scan from time import sleep import readline Building = sys.argv[1] Door = sys.argv[2] s = Scan(Building, Door) ser = serial.Serial(s.GetPort(), 9600) ReadLine = readline.ReadLine(ser) # ser = serial.Serial(s.TestPort(),9600) try: while True: try: s.FindUser(ReadLine.readline()) ser.reset_input_buffer() sleep(.1) except KeyboardInterrupt: break except Exception as e: mail.ReadError(e) ser.close() del s
#!/bin/sh import RPi.GPIO as GPIO import Layout import time import serial import DB import mail import sys def SetInactive(d,m): new = DB.Server() n = new.cursor() n.execute("UPDATE Pi__Doors SET Active = 0 WHERE Door = %s AND Pi = %s", (d,m)) new.commit() Building = sys.argv[1] Door = sys.argv[2] Map = Layout.Map() Pin = Map[Building][Door]['Relay'] GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(Pin,GPIO.OUT) GPIO.output(Pin, 1) SetInactive(Door,Map[Building][Door]['Pi']) mail.ReadError('Building ' + Building + ' ' + Door + ' door has been deactivated');