Advertisement
Guest User

humpf_2

a guest
Feb 9th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf8 -*-
  3.  
  4. import RPi.GPIO as GPIO
  5. import MFRC522
  6. import MySQLdb as mdb
  7.  
  8.  
  9. con = mdb.connect('IP', 'USER', 'PASS', 'DATABASE')
  10. cur = con.cursor()
  11.  
  12.  
  13. def user_display(uid):
  14.     results = cur.execute("SELECT * FROM staff WHERE uid = "+uid+"")
  15.     return results
  16.  
  17.  
  18. MIFAREReader = MFRC522.MFRC522()
  19.  
  20. try:
  21.     while True:
  22.         (status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  23.  
  24.         if status == MIFAREReader.MI_OK:
  25.             print "Card detected"
  26.  
  27.         (status, uid) = MIFAREReader.MFRC522_Anticoll()
  28.  
  29.         if status == MIFAREReader.MI_OK:
  30.             UIDcode = str(uid[0]) + str(uid[1]) + str(uid[2]) + str(uid[3])
  31.  
  32.             print user_display(UIDcode)
  33.  
  34. except KeyboardInterrupt:
  35.     GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement