SHARE
TWEET

Untitled

a guest Aug 17th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf8 -*-
  3. #
  4. #    Copyright 2014,2018 Mario Gomez <mario.gomez@teubi.co>
  5. #
  6. #    This file is part of MFRC522-Python
  7. #    MFRC522-Python is a simple Python implementation for
  8. #    the MFRC522 NFC Card Reader for the Raspberry Pi.
  9. #
  10. #    MFRC522-Python is free software: you can redistribute it and/or modify
  11. #    it under the terms of the GNU Lesser General Public License as published by
  12. #    the Free Software Foundation, either version 3 of the License, or
  13. #    (at your option) any later version.
  14. #
  15. #    MFRC522-Python is distributed in the hope that it will be useful,
  16. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #    GNU Lesser General Public License for more details.
  19. #
  20. #    You should have received a copy of the GNU Lesser General Public License
  21. #    along with MFRC522-Python.  If not, see <http://www.gnu.org/licenses/>.
  22. #
  23.  
  24. import RPi.GPIO as GPIO
  25. import MFRC522
  26. import signal
  27.  
  28. continue_reading = True
  29.  
  30. # Capture SIGINT for cleanup when the script is aborted
  31. def end_read(signal,frame):
  32.     global continue_reading
  33.     print ("Ctrl+C captured, ending read.")
  34.     continue_reading = False
  35.     GPIO.cleanup()
  36.  
  37. # Hook the SIGINT
  38. signal.signal(signal.SIGINT, end_read)
  39.  
  40. # Create an object of the class MFRC522
  41. MIFAREReader = MFRC522.MFRC522()
  42.  
  43. # Welcome message
  44. print ("Welcome to the MFRC522 data read example")
  45. print ("Press Ctrl-C to stop.")
  46.  
  47.  
  48. # This loop keeps checking for chips. If one is near it will get the UID and authenticate
  49. while continue_reading:
  50.    
  51.     # Scan for cards    
  52.     (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  53.  
  54.     # If a card is found
  55.     if status == MIFAREReader.MI_OK:
  56.         print ("Card detected")        
  57.    
  58.     # Get the UID of the card
  59.     (status,uid) = MIFAREReader.MFRC522_Anticoll()
  60.  
  61.     # If we have the UID, continue
  62.     if status == MIFAREReader.MI_OK:
  63.         userid = uid
  64.         if (uid[0], uid[1], uid[2], uid[3]) == (121, 27, 168, 90):
  65.             print ("Funktioniert")
  66.  
  67.         # Print UID
  68.         print ("Card read UID: %s,%s,%s,%s") % (uid[0], uid[1], uid[2], uid[3])
  69.    
  70.         # This is the default key for authentication
  71.         key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
  72.        
  73.         # Select the scanned tag
  74.         MIFAREReader.MFRC522_SelectTag(uid)
  75.  
  76.         # Authenticate
  77.         status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)
  78.         print status
  79.  
  80.         # Check if authenticated
  81.         if status == MIFAREReader.MI_OK:
  82.             MIFAREReader.MFRC522_Read(8)
  83.             MIFAREReader.MFRC522_StopCrypto1()
  84.         else:
  85.             print ("Authentication error")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top