# If we have the UID, continue
    if status == MIFAREReader.MI_OK:

        # Print UID
        print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
    
        # This is the default key for authentication
        key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
        
        # Select the scanned tag
        MIFAREReader.MFRC522_SelectTag(uid)

        # Authenticate
        status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)

        # Check if authenticated
        if status == MIFAREReader.MI_OK:
            # Add the card to RFID table
            card = Entity()
            card.PartitionKey = "2019"
            card.RowKey = time.time()
            card.UID = str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
            card.Authenticate = status
            table_service.insert_or_replace_entity("RFID", card)
            
            MIFAREReader.MFRC522_Read(8)
            MIFAREReader.MFRC522_StopCrypto1()
        else:
            print "Authentication error"
Beispiel #2
0
        # Check if authenticated
        if status == MIFAREReader.MI_OK:
            # Beep
            #try:
            #    GPIO.output(BeepPin,GPIO.HIGH)
            #    time.sleep(0.5)
            #    GPIO.output(BeepPin,GPIO.LOW)
            #except KeyboardInterrupt:
            #    print "Exception:KeyboardInterrupt"
            #    GPIO.cleanup()

            # Add the card to RFID table
            card = Entity()
            card.PartitionKey = time.strftime("%Y-%m-%d", time.localtime())
            card.RowKey = time.strftime("%H:%M:%S", time.localtime())
            card.UID = CardUID
            card.Authenticate = status
            table_service.insert_or_replace_entity("RFID", card)

            # Update the Projects table
            projectlog = Entity()
            projectlog.PartitionKey = "CheckID"
            projectlog.RowKey = "001"
            projectlog.Value = CardUID
            table_service.insert_or_replace_entity("Projects", projectlog)

            MIFAREReader.MFRC522_Read(8)
            MIFAREReader.MFRC522_StopCrypto1()
            #time.sleep(0.5)
        else:
            print "Authentication error"