Esempio n. 1
0
File: readRFID.py Progetto: kod3r/pi
def readCard():
    global rfidData, errorCount
    try:
        classLED("blue")
        while True:
            ser.flushInput()
            classLED("blue")
            rfidData = ser.readline().strip()
            print "Line: "
            if len(rfidData) > 0:
                rfidData = rfidData[1:13]
                print "Card Scanned: ", rfidData
                print findTag(rfidData)

    except SerialException:
        print "Serial Exception error"
        errorCount+=1
        readCard()

    except termios.error:
        print "Termios error"
        errorCount+=1
        readCard()

    except OSError as e:
        if e.errno == 11:
            errorCount+=1
            readCard()
        else:
            raise

    finally:
        ser.close()
        con.close()
        RPIO.cleanup()
        pass
Esempio n. 2
0
File: readRFID.py Progetto: kod3r/pi
def findTag(inputTag):

        permiso = classPermiso(inputTag)

        entry = classEntradaLog(permiso)
        entry.postSQLite(con), entry.postJSON()

        if currentDay is 7:
            dateIsSunday = True
        else:
            dateIsSunday = False


        if permiso.permission == PERMISSION_YES:
            if (permiso.endHour > currentTime > permiso.startHour) or (permiso.startHour is None and permiso.endHour is None):
                if currentDate < permiso.endDate:
                    if ((dateIsSunday is True) and permiso.sundayPermission == 1) or (dateIsSunday is False):
                        entry = classEntradaLog(permiso)
                        entry.postSQLite(con), entry.postJSON()
                        classLED("green")
                        time.sleep(1)
                        return "Access Granted"
                    else:
                        classLED("red")
                        time.sleep(1)
                        return "Cannot enter on a Sunday"
                else:
                    classLED("red")
                    time.sleep(1)
                    return "Date is too old"
            else:
                classLED("red")
                time.sleep(1)
                return "You are not permitted to enter at this Time"
    
        elif permiso.permission == PERMISSION_NO:
            entry = classEntradaLog(permiso)
            entry.postSQLite(con), entry.postJSON()
            classLED("red")
            time.sleep(1)
            return "Access Denied"

        elif permiso.permission == PERMISSION_BLACKLIST:
            entry = classEntradaLog(permiso)
            entry.postSQLite(con), entry.postJSON()
            classLED("red")
            time.sleep(1)
            mp3Location = current_dir + "/alarm.mp3"
            os.system('mpg321 ' + mp3Location + " &")
            return "!!! Alert !!!"

        elif permiso.permission == PERMISSION_PIN:
            if (permiso.endHour > currentTime > permiso.startHour) or (permiso.startHour is None and permiso.endHour is None):
                if currentDate < permiso.endDate:
                    if ((dateIsSunday is True) and permiso.sundayPermission == 1) or (dateIsSunday is False):
                        entry = classEntradaLog(permiso)
                        entry.postSQLite(con), entry.postJSON()
                        #pinInput(permiso.personPIN)
                    else:
                        return "Cannot enter on a Sunday"
                else:
                    return "Date is too old"
            else:
                return "You are not permitted to enter at this Time"
        else:
            return "Unkown Permission"