Guest User

python_rfid

a guest
Apr 12th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2. import nfc
  3. #import mysql
  4. import os
  5. import sys
  6. #import tty
  7. #import termios
  8. #import logging
  9. import thread
  10. import time
  11. import RPi.GPIO as GPIO
  12. #import urllib2
  13.  
  14.  
  15.  
  16. #def debug(message):
  17. # logging.debug(message)
  18.  
  19.  
  20. def read():
  21. # cardId=nfc.readNfc()
  22.  
  23.  
  24. # return cardId
  25. return nfc.readNfc()
  26.  
  27. #def readNfc():
  28. # if(action==55):
  29. # cardId=read()
  30. # print(cardId)
  31. # time.sleep(1)
  32. def beep():
  33. #starting beeping in separate thread to not slow down whole application
  34. thr = thread.start_new_thread(beepAsync, ())
  35. def beepAsync():
  36. GPIO.output(13,True)
  37. time.sleep(0.5)
  38. GPIO.output(13,False)
  39.  
  40.  
  41.  
  42. def initGpio():
  43. GPIO.setmode(GPIO.BOARD)
  44. # GPIO.setup(8, GPIO.OUT)
  45. GPIO.setup(13, GPIO.OUT)
  46.  
  47.  
  48. def main():
  49. # GPIO.cleanup()
  50. try:
  51. initGpio()
  52.  
  53. while True:
  54.  
  55. # os.system("sudo python /usr/lib/python2.7/webbrowser.py -t 'http://192.168.10.86/pi/userinfo.php?tagid=00001$
  56.  
  57.  
  58. cardId = read()
  59. beep()
  60. # print(cardId)
  61. time.sleep(1)
  62. #if not os.path.exits("/home/pi/Desktop/attendance2/"+cardId+".txt"):
  63. # os.system("sudo python /usr/lib/python2.7/webbrowser.py -t '192.168.xx.xx/pi/userinfo.php?tagid=0000101'")
  64. os.system("sudo touch /home/pi/Desktop/attendance2/temp/carduser/"+read()+".txt")
  65. os.system("sudo echo "+read()+" > /home/pi/Desktop/attendance2/temp/carduser/"+read()+".txt")
  66.  
  67.  
  68. print("hi")
  69. except KeyboardInterrupt:
  70. # GPIO.cleanup()
  71. pass
  72. # GPIO.cleanup()
  73.  
  74. if __name__ == '__main__':
  75.  
  76. print("----------========== Starting session! ==========----------")
  77. main()
Add Comment
Please, Sign In to add comment