def upload_fingerprint_template(name): myquery={} myquery['username'] = name mydoc = coll.find_one(myquery) #print(mydoc['uid']) print(mydoc['image_template']) image_temp = [] image_temp = mydoc['image_template'] print(image_temp) #image_temp = f.storeTemplate() try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) exit(1) result = image_temp result = f.searchTemplate() positionNumber = result[0] print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) position = f.getTemplateCount() position = position+1 print("Inserting fingerprint matching user from mongo to local fingerprint sensor") f.uploadCharacteristics(0x01, image_temp) f.storeTemplate() print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
def fingerprintGrab(ref, bucketLoc, universalLoc): try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) exit(1) ## Gets some sensor information # print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) link = universalLoc + 'biom' ## Tries to search the finger and calculate hash try: f.deleteTemplate(0) char = ref.get(link, '') f.uploadCharacteristics(0x02, char) f.createTemplate() positionNumber = f.storeTemplate() auth, scan = checkAuth() return (auth, scan) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def LoadFingerprintIntoModule(self, inputData): try: f = PyFingerprint('/dev/ttyUSB1', 57600, 0xFFFFFFFF, 0x00000000) if (inputData != "null"): inputData = ast.literal_eval(inputData) f.uploadCharacteristics(0x01, inputData) f.storeTemplate() if (f.verifyPassword() == False): raise ValueError( 'The given fingerprint sensor password is wrong!') except Exception as e: pass
def search_fingerprint(): # Se obtiene el número identificador a ser buscado data = request.json characteristics_to_compare = data.get('characteristicsData', '') # Inicialización del sensor try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError( 'La contraseña proporcionada para el sensor es erronea!') except Exception as e: print('El sensor de huellas dactilares no se pudo inicializar!') print('Mensaje de excepción: ' + str(e)) exit(1) # Se busca la huella proporcionada try: send_instructions('Ponga su dedo en el sensor') # Se espera a que el dedo sea posicionado while (f.readImage() == False): pass # Convierte la imagen leída a características y la almacena en el buffer 1 f.convertImage(0x01) # Se sube una por una las listas con las características al buffer 2 para luego # compararlas con la imagen adquirida f.uploadCharacteristics(0x02, characteristics_to_compare) compare_characteristics_payload = f.compareCharacteristics() if compare_characteristics_payload > 50: send_instructions('Identificado correctamente') return jsonify(value='Identificado correctamente', error='') else: send_instructions('Las huellas no coinciden') return jsonify(value='', error='Las huellas no coinciden') except Exception as e: print('Error al manejar la petición') print('Mensaje de excepción: ' + str(e)) exit(1)
f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print("The fingerprint sensor could not be initialized!\n" + "Exception message: " + str(e)) exit(1) ## Load the template to compare against. if (f.deleteTemplate(0) == True): print('Template deleted!') #print("Uploading characteristics") f.uploadCharacteristics(0x01, finger_template1) f.uploadCharacteristics(0x02, finger_template2) #print("Peak on the uploaded characteristics: " + str(f.downloadCharacteristics(0x02))) ## Gets some sensor information print("Currently used templates: " + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) ## Tries to search the finger and calculate hash try: # print("Waiting for finger...\n") # # ## Wait that finger is read # while ( f.readImage() == False ): # pass
except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message:' + str(e)) exit(1) try: print('Waiting for finger...') while(f.readImage() == False ): pass ##converts read image to characteristics and stores it in charbuffer 1 f.convertImage(0x01) cur= conn.cursor() sql = "select * from finger_template" # finger template 이름의 table cur. execute(sql) for row in cur.fetchall(): print(f.uploadCharacteristics(0x02, eval(row[0]))) score-f.compareCharacteristics() print(score) ##두 지문간 특성을 비교하여 유사도를 정수형으로 score 변수에 저장 execpt Execption as e: print('Operation failed!') print('Execption message:' + str(e)) exit(1) finally: conn.close()
print('Exception message: ' + str(e)) exit(1) # trying to authenticate try: # Deleting the database f.clearDatabase() # Uploading the template to the sensor temp_file = open("template.txt", "r") template = [] for x in temp_file: template.append(int(x)) temp_file.close() f.uploadCharacteristics(characteristicsData=template) positionNumber = f.storeTemplate() print('Finger uploaded successfully!') print('New template position #' + str(positionNumber)) # Tries to search the finger print('Waiting for finger...') # Wait that finger is read while ( f.readImage() == False ): pass # Converts read image to characteristics and stores it in charbuffer 1 f.convertImage(0x01) # Searches template
class fingerprint_sensor: def __init__(self): # Sensor Initialisation try: self.f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (self.f.verifyPassword() == False): raise ValueError( 'The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) def enrollment(self): try: print('Waiting for finger...') # Wait that finger is read while (self.f.readImage() == False): pass # Converts read image to characteristics and stores it in charbuffer 1 self.f.convertImage(0x01) # Checks if finger is already enrolled result = self.f.searchTemplate() positionNumber = result[0] if (positionNumber >= 0): print('Template already exists at position #' + str(positionNumber)) time.sleep(2) # Wait that finger is read again while (self.f.readImage() == False): pass # Converts read image to characteristics and stores it in charbuffer 2 self.f.convertImage(0x02) # Compares the charbuffers if (self.f.compareCharacteristics() == 0): raise Exception('Fingers do not match') # Creates a template self.f.createTemplate() # Saves template at new position number positionNumber = self.f.storeTemplate() print('Finger enrolled successfully!') print('New template position #' + str(positionNumber)) # Exports the template to a temporaryfile template = self.f.downloadCharacteristics() temp_file = open("template.txt", "w+") for item in template: temp_file.write(str(item) + "\n") temp_file.close() return os.path.abspath('temp_file.txt') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) def authentication(self, file_path): try: match_flag = 0 # Uploading the template to the sensor temp_file = open(file_path, "r") template = [] for x in temp_file: template.append(int(x)) temp_file.close() self.f.uploadCharacteristics(characteristicsData=template) Index_template = self.f.storeTemplate() # Tries to search the finger print('Waiting for finger...') # Wait that finger is read while (self.f.readImage() == False): pass # Converts read image to characteristics and stores it in charbuffer 1 self.f.convertImage(0x01) # Searches template result = self.f.searchTemplate() positionNumber = result[0] if (positionNumber == -1): print('No match found!') match_flag = 0 elif (positionNumber == Index_template): print('Matched') match_flag = 1 return match_flag except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) def Clear_Sensor(self): # Deleting the database self.f.clearDatabase()
characterics1 = f.downloadCharacteristics(0x01) #print(characterics1) characterics2 = f.downloadCharacteristics(0x02) #print(characterics2) f.createTemplate() characterics3 = f.downloadCharacteristics(0x01) print('*' * 200) print(characterics3) mydict = {"_id": enroll_id, "name": name, "finger_array": characterics3} x = mycol.insert_one(mydict) myquery = {"_id": 1} mydoc = mycol.find(myquery) for x in mydoc: match_char = x["finger_array"] print match_char f.uploadCharacteristics(0x02, characteristicsData=match_char) character4 = f.downloadCharacteristics(0x02) print character4 if (character4 == match_char): print("finger match") except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) exit(1) try: print('Waiting for finger...') ## 지문이 읽힐때까지 기다림 while (f.readImage() == False): pass ## Converts read image to characteristics and stores it in charbuffer 1 f.convertImage(0x01) db = firestore.client() doc_ref = db.collection('Control').document('FingerprintResult') doc = doc_ref.get(field_paths={'result'}).to_dict().get('result') print(doc) print("@@@@@") print(f.uploadCharacteristics(0x02, eval(doc))) score = f.compareCharacteristics() print(score) print("!!!!!!") except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
## Converts read image to characteristics and stores it in charbuffer 1 f.convertImage(0x01) print("Input finger") scannedFinger = f.downloadCharacteristics(0x01) characteristics = str(f.downloadCharacteristics(0x01)).encode('utf-8') print("SCANNED FINGER") print(scannedFinger) print("====================================================") for x in response: # print(x) temp = x["fingerprint"].split(", ") temp[0] = temp[0].split("[")[1] temp[len(temp) - 1] = temp[len(temp) - 1].split("]")[0] results = list(map(int, temp)) print(results) f.uploadCharacteristics(0x02, results) score = f.compareCharacteristics() if (score > 0): break if (score != 0): print("Finger found!") print(results) print("With an accuracy score: " + str(score)) else: print("Finger not found") except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def enroll_user(): # Intenta inicializar el sensor try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError( 'La contraseña proporcionada para el sensor es erronea!') except Exception as e: print('El sensor de huellas dactilares no se pudo inicializar!') print('Mensaje de excepcion: ' + str(e)) exit(1) # Intenta ingresar nuevos datos al sensor try: send_instructions('Ponga el dedo en el sensor') # Espera a que la imagen sea leída while (f.readImage() == False): pass # Convierte la imagen leída a características y la almacena en el buffer 1 f.convertImage(0x01) # Se obtienen las características de la base de datos characteristics_data = retrieve_characteristics() for characteristic in characteristics_data: # Si la lista llega vacía, quiere decir que la información que llegó corresponde al votante que no tiene la # huella registrada, así que se omite esta prueba if len(characteristic) == 0: pass else: # Se sube una por una las listas con las características al buffer 2 para luego # compararlas con la imagen adquirida f.uploadCharacteristics(0x02, characteristic) compare_characteristics_payload = f.compareCharacteristics() # Umbral de decision para la aceptación de huellas dactilares if compare_characteristics_payload > 20: send_instructions( 'La huella ya se encuentra registrada en la base de datos' ) return jsonify( value='', error= 'La huella ya se encuentra registrada en la base de datos' ) send_instructions('Quite el dedo del sensor') time.sleep(2) send_instructions('Ponga el dedo en el sensor nuevamente') # Espera a que la imagen del dedo sea leída nuevamente while (f.readImage() == False): pass # Convierte la imagen leída a características y la almacena en el buffer 2 f.convertImage(0x02) # Compara los buffers 1 y 2 if (f.compareCharacteristics() == 0): # Si las huellas no son iguales se retorna un error send_instructions('Las huellas no corresponden') return jsonify(value='', error='Las huellas no corresponden') # Se crea la plantilla comparando la informacion almacenada en los buffers 1 y 2 f.createTemplate() # Descarga las características almacenadas en el buffer 1, correspondientes a la plantilla recíen creada characteristics = f.downloadCharacteristics(0x01) send_instructions('Huella registrada correctamente!') return jsonify( # Se La lista(vector) que contiene las características de la huella value=characteristics, error='') except Exception as e: print('Operacion fallida!') print('Mensaje de excepción: ' + str(e)) exit(1)
def authenticate(): far = [[0, 50, 100], [20, 0, 60], [150, 40, 0]] station_names = [ 'Uttara North', 'Uttara Centre', 'Uttara South', 'Pallabi', 'Mirpur 11', 'Mirpur-10', 'Kazipara', 'Shewrapara', 'Agargaon', 'Bijoy Sarani', 'Farmgate', 'Karwan Bazar', 'Shahbag', 'Dhaka University', 'Bangladesh Secretariat', 'Motijheel' ] data = request.get_json() try: f = PyFingerprint('COM6', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) data = {'s': 'Exception message: ' + str(e), 'bool_found': '0'} return json.dumps(data) try: data = request.get_json() chrr = json.loads(data) chr = chrr["tem"] c = list() for i in range(0, len(chr)): c.append(int(chr[i])) f.uploadCharacteristics(0x01, chr) result = f.searchTemplate() positionNumber = result[0] accuracyScore = result[1] if (positionNumber == -1): #del f #f.__del__() print("ok1") data = {'s': 'No match found!', 'bool_found': '0'} #f.loadTemplate(0, 0x01) #result = f.searchTemplate() print("ok2") print('No match found!') data = {'s': 'No match found!', 'bool_found': '0'} # exit(0) else: #f.__del__() #del f print("first else") if (chrr["entry_exit"] == 0): f.loadTemplate(0, 0x01) result = f.searchTemplate() f.__del__() u = User.query.filter_by(id=positionNumber).first() exit_station_number = int(chrr["station_number"]) exit_station_name = station_names[exit_station_number] exit_time = chrr["scaned_time"] date = chrr["date"] entry_station_name = station_names[u.start_station] db_start_station = int(u.start_station) try: fa = int( u.money) - far[db_start_station][exit_station_number] u.money = fa print(far) info = User_travel_history( date=str(date), entry_station=entry_station_name, exit_station=exit_station_name, entry_time=u.entry_time, fare=str(far[db_start_station][exit_station_number]), exit_time=exit_time, human=u) db.session.add(info) db.session.commit() #print("hi") print('Found template') data = { 's': 'Found template at position #' + str(positionNumber), 'bool_found': '1' } # print('The accuracy score is: ' + str(accuracyScore)) except Exception as e: print('Exception message: ' + str(e)) data = {'s': 'No match found!', 'bool_found': '0'} if (chrr["entry_exit"] == 1): f.loadTemplate(0, 0x01) result = f.searchTemplate() f.__del__() u = User.query.filter_by(id=positionNumber).first() if (u.money > 70): u.start_station = int(chrr["station_number"]) u.entry_time = chrr["scaned_time"] db.session.commit() data = {'s': 'Enough money', 'bool_found': '1'} else: data = {'s': 'Insufficent balance !', 'bool_found': '0'} #f.loadTemplate(0, 0x01) #result = f.searchTemplate() #f.__del__() except Exception as e: f.__del__() print('Operation failed!') print('Exception message: ' + str(e)) data = {'s': 'No match found!', 'bool_found': '0'} return json.dumps(data)
""" from pyfingerprint.pyfingerprint import PyFingerprint from sys import stdin ## Tries to initialize the sensor try: f = PyFingerprint('/dev/ttyAMA0', 115200, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) exit(1) try: print('Provide your fingerprint...') while(not f.readImage()): pass f.convertImage(1) # carrega no charbuffer1 o template lido print("loading fingerprint characteristics...") for line in stdin: # para cada linha da entrada padrao (termina a leitura no EOF) f.uploadCharacteristics(2,eval(line)) print('The matching score between the two templates is', f.compareCharacteristics()) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
# Define bundle counter i = 0 # For each bundle... for bundle in bundles: # Get Bundle message msg = bundle.get_messages() # Converts message to a list of fingerprint characteristics mychar = json.loads(msg[0]) # Upload characteristics to buffer 2 print("\nUploading fingerprint characteristics to buffer 2") f.uploadCharacteristics(0x02, mychar) # Save buffer 2 as template print("Saving buffer 2 as template in pos " + str(i)) f.storeTemplate(i, 0x02) # Increase bundle counter i = i + 1 print("\nCompleted..") retry = True ## Tries to search the finger and calculate hash while retry is True: try:
## print('Found template at position #' + str(positionNumber)) ## print('The accuracy score is: ' + str(accuracyScore)) ## OPTIONAL stuff ## ## Loads the found template to charbuffer 1 ## f.loadTemplate(positionNumber, 0x01) ## Downloads the characteristics of template loaded in charbuffer 1 ## characterics = str(f.downloadCharacteristics(0x01)).encode('utf-8') #characterics = '[3, 1, 90, 11, 163, 0, 128, 14, 128, 14, 128, 6, 0, 6, 0, 6, 0, 2, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 128, 6, 192, 14, 224, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 4, 13, 190, 82, 155, 230, 30, 49, 36, 170, 158, 95, 37, 103, 158, 37, 40, 215, 254, 50, 180, 86, 190, 63, 33, 84, 31, 52, 59, 235, 255, 73, 188, 21, 63, 46, 137, 227, 186, 37, 9, 161, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 88, 18, 161, 0, 128, 6, 128, 6, 0, 2, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 128, 0, 128, 0, 128, 2, 192, 2, 192, 2, 224, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 144, 204, 254, 12, 17, 33, 62, 31, 145, 163, 62, 22, 29, 157, 126, 24, 164, 27, 254, 107, 40, 229, 190, 73, 49, 170, 222, 58, 181, 216, 94, 75, 193, 22, 158, 56, 134, 101, 63, 26, 170, 154, 255, 88, 174, 84, 31, 101, 142, 142, 124, 36, 60, 153, 28, 36, 191, 193, 92, 95, 14, 165, 29, 69, 151, 35, 144, 65, 28, 36, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]' characterics = sys.argv[1] if (f.uploadCharacteristics(0x01, eval(characterics)) == True): print('Template uploaded') else: raise Exception('Error during upload') if (f.storeTemplate(0) == True): print('Template stored') else: raise Exception('Error during template storing') ## Hashes characteristics of template ## print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest()) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e))
def main(): #MIFAREReader = MFRC522.MFRC522() GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbers GPIO.setup(LCD_E, GPIO.OUT) # E GPIO.setup(LCD_RS, GPIO.OUT) # RS GPIO.setup(LCD_D4, GPIO.OUT) # DB4 GPIO.setup(LCD_D5, GPIO.OUT) # DB5 GPIO.setup(LCD_D6, GPIO.OUT) # DB6 GPIO.setup(LCD_D7, GPIO.OUT) # DB7 lcd_init() while (True): MIFAREReader = MFRC522.MFRC522() lcd_string("ATTENDANCE SYSTEM", LCD_LINE_1, 2) lcd_string("TA-2 ELEKTRO 2014", LCD_LINE_4, 2) #today= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") rdy = datetime.datetime.now().strftime("%b %d %Y") #str(today) clk = datetime.datetime.now().strftime("%H:%M:%S") lcd_string(rdy, LCD_LINE_2, 2) lcd_string(clk, LCD_LINE_3, 2) if GPIO.input(19): lcd_byte(0x01, LCD_CMD) lcd_string("UPDATING..", LCD_LINE_2, 2) try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError( 'The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) ## Tries to delete the template of the finger try: curs.execute("SELECT max(id_finger)FROM user") maks = curs.fetchone() y = maks[0] print y for x in range(0, y): curs.execute( "SELECT temp_finger FROM user WHERE id_finger = ('%i')" % x) temp = curs.fetchone() t_temp = temp[0] t1_temp = t_temp.split() t2_temp = list(map(int, t1_temp)) f.uploadCharacteristics(0x01, t2_temp) f.storeTemplate(x, 0x01) db.commit() except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) lcd_byte(0x01, LCD_CMD) print('Duplicated Data') lcd_string("Duplicated Data", LCD_LINE_2, 2) lcd_string("Please Contact", LCD_LINE_3, 2) lcd_string("Administrator", LCD_LINE_4, 2) print('Exception message: ' + str(e)) time.sleep(2) lcd_byte(0x01, LCD_CMD) try: (status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) if status == MIFAREReader.MI_OK: (status, uid) = MIFAREReader.MFRC522_Anticoll() if status == MIFAREReader.MI_OK: lcd_byte(0x01, LCD_CMD) rt_rfid = str(uid) rt_rfid1 = rt_rfid.translate(None, ',[] ') print rt_rfid1 curs.execute( "SELECT status FROM user WHERE rfid = ('%s')" % rt_rfid1) status_1 = curs.fetchone() t_stat = status_1[0] print t_stat GPIO.output(21, True) time.sleep(.085) GPIO.output(21, False) if (t_stat == "Dosen"): curs.execute( "SELECT Nama FROM Dosen WHERE rfid = ('%s')" % rt_rfid1) nama = curs.fetchone() ntemp = nama[0] print ntemp #print today curs.execute( "SELECT matakuliah1 FROM Dosen WHERE rfid = ('%s')" % rt_rfid1) matkul1 = curs.fetchone() t_matkul1 = matkul1[0] curs.execute( "SELECT matakuliah2 FROM Dosen WHERE rfid = ('%s')" % rt_rfid1) matkul2 = curs.fetchone() t_matkul2 = matkul2[0] curs.execute( "SELECT matakuliah3 FROM Dosen WHERE rfid = ('%s')" % rt_rfid1) matkul3 = curs.fetchone() t_matkul3 = matkul3[0] curs.execute( "SELECT matakuliah4 FROM Dosen WHERE rfid = ('%s')" % rt_rfid1) matkul4 = curs.fetchone() t_matkul4 = matkul4[0] tampilayar(ntemp, clk) print "Memilih matakuliah" tampilayardosen(ntemp, t_matkul1, t_matkul2, t_matkul3, t_matkul4) print "Data sudah masuk" lcd_byte(0x01, LCD_CMD) lcd_string("DATA RECORDED", LCD_LINE_2, 2) time.sleep(1) lcd_byte(0x01, LCD_CMD) else: today = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") str(today) curs.execute( "SELECT nama FROM user WHERE rfid = ('%s')" % rt_rfid1) nama = curs.fetchone() ntemp = nama[0] print ntemp print today ruang = "GD715" mat = "-" tampilayar(ntemp, clk) curs.execute( "INSERT INTO Log (nama, datetime, ruangan, matakuliah) VALUES ('%s', '%s', '%s', '%s')" % (ntemp, today, ruang, mat)) db.commit() lcd_byte(0x01, LCD_CMD) except Exception as e: GPIO.output(21, True) time.sleep(.075) GPIO.output(21, False) time.sleep(.045) GPIO.output(21, True) time.sleep(.075) GPIO.output(21, False) time.sleep(.045) GPIO.output(21, True) time.sleep(.075) GPIO.output(21, False) lcd_byte(0x01, LCD_CMD) print('RFID belum didaftar!!!') lcd_string("COBA LAGI", LCD_LINE_2, 2) print('Exception message: ' + str(e)) time.sleep(2) lcd_byte(0x01, LCD_CMD) try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError( 'The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) #while ( f.readImage() == False ): # pass try: key = f.readImage() if (key != False): ## Converts read image to characteristics and stores it in charbuffer 1 f.convertImage(0x01) ## Searchs template result = f.searchTemplate() positionNumber = result[0] lcd_byte(0x01, LCD_CMD) curs.execute( "SELECT status FROM user WHERE id_finger= ('%s')" % positionNumber) status = curs.fetchone() t_stat = status[0] print t_stat GPIO.output(21, True) time.sleep(.085) GPIO.output(21, False) ruang = "GD715" if (t_stat == "Dosen"): curs.execute( "SELECT Nama FROM Dosen WHERE id_finger = ('%s')" % positionNumber) nama = curs.fetchone() ntemp = nama[0] print ntemp #print today curs.execute( "SELECT matakuliah1 FROM Dosen WHERE id_finger = ('%s')" % positionNumber) matkul1 = curs.fetchone() t_matkul1 = matkul1[0] curs.execute( "SELECT matakuliah2 FROM Dosen WHERE id_finger = ('%s')" % positionNumber) matkul2 = curs.fetchone() t_matkul2 = matkul2[0] curs.execute( "SELECT matakuliah3 FROM Dosen WHERE id_finger = ('%s')" % positionNumber) matkul3 = curs.fetchone() t_matkul3 = matkul3[0] curs.execute( "SELECT matakuliah4 FROM Dosen WHERE id_finger = ('%s')" % positionNumber) matkul4 = curs.fetchone() t_matkul4 = matkul4[0] tampilayar(ntemp, clk) print "Memilih matakuliah" tampilayardosen(ntemp, t_matkul1, t_matkul2, t_matkul3, t_matkul4) print "Data sudah masuk" lcd_byte(0x01, LCD_CMD) lcd_string("DATA RECORDED", LCD_LINE_2, 2) time.sleep(1) lcd_byte(0x01, LCD_CMD) else: today = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") str(today) curs.execute( "SELECT nama FROM user WHERE id_finger = ('%s')" % positionNumber) nama = curs.fetchone() ntemp = nama[0] print ntemp print today mat = "-" tampilayar(ntemp, clk) curs.execute( "INSERT INTO Log (nama, datetime, ruangan, matakuliah) VALUES ('%s', '%s', '%s', '%s')" % (ntemp, today, ruang, mat)) db.commit() lcd_byte(0x01, LCD_CMD) except Exception as e: GPIO.output(21, True) time.sleep(.075) GPIO.output(21, False) time.sleep(.045) GPIO.output(21, True) time.sleep(.075) GPIO.output(21, False) time.sleep(.045) GPIO.output(21, True) time.sleep(.075) GPIO.output(21, False) print('Fingerprint belum didaftar!!!') lcd_string("COBA LAGI", LCD_LINE_2, 2) print('Exception message: ' + str(e)) time.sleep(2) lcd_byte(0x01, LCD_CMD)