Monday, 26 June 2017

RFID RC522 Send Data to Raspberry Pi

RFID RC522 Send Data to Raspberry Pi:



import MFRC522
import signal
import requests
import time
continue_reading = True
MIFAREReader = MFRC522.MFRC522()

cardA = [46,165,34,124,112]
cardB = [201,428,256,12,435]
cardC = [57,45,453,453]

def end_read(signal, frame):
  global continue_reading
  continue_reading = False
  print "Ctrl+C captured, ending read."
  MIFAREReader.GPIO_CLEEN()

signal.signal(signal.SIGINT, end_read)

while continue_reading:
  (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  if status == MIFAREReader.MI_OK:
    print "Card detected"
  (status,backData) = MIFAREReader.MFRC522_Anticoll()
  if status == MIFAREReader.MI_OK:
    print "Card read UID: "+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4])
    time.sleep(3)
    if  backData == cardA:
      response = requests.get('http://192.168.1.134/rfid_read.php?allow=1&id='+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4]$
      print "is Card A"
    elif backData == cardB:
      response = requests.get('http://192.168.1.134/rfid_read.php?allow=1&id='+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4]$
      print "is Card B"
    elif backData == cardC:
      print "is Card C"
    else:
      print "not valid Card"


Circuit Diagram:





0 comments:

Post a Comment

if you have any doubt please let me know