def run(self): global rfidQueue global continue_reading while continue_reading: try: rfidValue = rfid.readRFID() if rfidValue != -1: GPIO.output(CARD_READ_LED,True) tone.playTone() #log.info("RFID=" + rfidValue) rfidQueue.put(rfidValue) GPIO.output(CARD_READ_LED,False) time.sleep(0.5) else: time.sleep(0.005) except Exception, e: GPIO.output(CARD_READ_LED,False) log.info("Error :" + str(e))
def end_read(signal,frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False MFRC522.cleanup() GPIO.cleanup()
def __init__(self): self.READER = MFRC522.MFRC522()
db = MySQLdb.connect("localhost", "root", "NEWPASSWORD", "rfiddb") #Capture SIGINT for cleanup when the script is aborted def end_read(signal, frame): global continue_reading print("Ctrl+C captured, ending read.") continue_reading = False GPIO.cleanup() #Hook the SGINT signal.signal(signal.SIGINT, end_read) #Create an object of the class MFRC522 MIFAREReader = MFRC522.MFRC522() #Welcom massage print("Welcome to the RFID log in system") #To check for chips while continue_reading: (status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQUDL) if status == MIFAREReader.MI_OK: print("Card Detected") pass #Get the UID of the card (status, _uid) = MIFAREReader.MFRC522_Anticoll()
def __init__(self, key): self.key = key self.rfid = MFRC522.MFRC522() self.setoresReservados = 8 self.tamanhoPermissao = 21 self.tamanhoSetor = 16
import MFRC522 import RPi.GPIO as GPIO import time LeitorRFID = MFRC522.MFRC522() print('Aproxime a TAG') while True: # Verifica se existe TAG no leitor (status, TagType) = LeitorRFID.MFRC522_Request(LeitorRFID.PICC_REQIDL) # Leitura da TAG if status == LeitorRFID.MI_OK: print('TAG Detectada!') (status, uid) = LeitorRFID.MFRC522_Anticoll() print('uid: ', uid) time.sleep(.5)
# Capture SIGINT for cleanup when the script is aborted def end_read(signal, frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False GPIO.cleanup() # Hook the SIGINT signal.signal(signal.SIGINT, end_read) # Create an object of the class MFRC522 # Correct values for the Raspberry Pi MIFAREReader = MFRC522.Reader(0, 0, 22) # This loop keeps checking for chips. If one is near it will get the UID and authenticate while continue_reading: # Scan for cards (status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) # If a card is found if status == MIFAREReader.MI_OK: print "Card detected" # Get the UID of the card (status, uid) = MIFAREReader.MFRC522_Anticoll() # If we have the UID, continue if status == MIFAREReader.MI_OK:
display("Entry is Free", "") return str(price) # =================================================================== # Variable Declarations # =================================================================== carparkname = "Bukit Batok Carpark" uid = None prev_uid = None continue_reading = True # Hook the SIGINT signal.signal(signal.SIGINT, end_read) # Create an object of the class MFRC522 mfrc522 = MFRC522.MFRC522() lcd = LCD() dynamodb = boto3.resource( 'dynamodb', aws_access_key_id="XXXXXXXXXXXXXXXXXXXX", aws_secret_access_key="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", region_name='us-west-2') # =================================================================== # Main # =================================================================== if __name__ == "__main__": # Publish to the same topic in a loop forever print("Exit Gantry Scanning for Next Car") while continue_reading:
def __init__(self, connection): threading.Thread.__init__(self) self.connection = connection self.reading = True self.MIFAREReader = MFRC522.MFRC522()
#!/usr/bin/env python3 ######################################################################## # Filename : RFID.py # Description : Use MFRC522 read and write Mifare Card. # auther : www.freenove.com # modification: 2019/03/26 ######################################################################## import RPi.GPIO as GPIO import MFRC522 import sys import os # Create an object of the class MFRC522 mfrc = MFRC522.MFRC522() def dis_ConmandLine(): print ("RC522>",end="") def dis_CardID(cardID): print ("%2X%2X%2X%2X%2X>"%(cardID[0],cardID[1],cardID[2],cardID[3],cardID[4]),end="") def setup(): print ("Program is starting ... " ) print ("Press Ctrl-C to exit.") pass def loop(): global mfrc while(True): dis_ConmandLine() inCmd = input() print (inCmd) if (inCmd == "scan"):
import MFRC522 import signal import time rdr = MFRC522.MFRC522() util = rdr.util() #Set util debug to true - it will print what's going on util.debug = True while True: #Request tag (error, data) = rdr.request() if not error: print "\nDetected" (error, uid) = rdr.anticoll() if not error: #Print UID print "Card read UID: " + str(uid[0]) + "," + str( uid[1]) + "," + str(uid[2]) + "," + str(uid[3]) #Set tag as used in util. This will call RFID.select_tag(uid) util.set_tag(uid) #Save authorization info (key B) to util. It doesn't call RFID.card_auth(), that's called when needed util.auth(rdr.auth_b, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]) #Print contents of block 4 in format "S1B0: [contents in decimal]". RFID.card_auth() will be called now util.read_out(4) #Print it again - now auth won't be called, because it doesn't have to be util.read_out(4) #Print contents of different block - S1B2 - RFID.card_auth() will be called again util.read_out(6)