Example #1
0
#!/usr/bin/env python

import signal
import time
import sys

from rc522 import RFID

run = True
rdr = RFID()
util = rdr.util()
util.debug = True

def end_read(signal,frame):
    global run
    print("\nCtrl+C captured, ending read.")
    run = False
    rdr.cleanup()
    sys.exit()


def read_card():
    rdr.wait_for_tag()
    (error, data) = rdr.request()
    if not error:
        print("\nDetected: " + format(data, "02x"))
    (error, uid) = rdr.anticoll()
    bKeyValue = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
    if not error:
        print("Card read UID {:02x}{:02x}{:02x}{:02x}: ".format(uid[0], uid[1], uid[2], uid[3]))
        if not rdr.select_tag(uid):
Example #2
0
import RPi.GPIO as GPIO

from rc522 import RFID

# UID en cours de lecture
uid_en_cours = "START_STOPPED"

# Volume par défaut
volume_au_demarrage = 80

# Stopper la lecture
stop_lecture = False

# On instancie la lib
rc522 = RFID()

#Definition des pins
pin31 = 31  #(GPIO.BCM = 06)
pin32 = 32  #(GPIO.BCM = 12)
pin33 = 33  #(GPIO.BCM = 13)
pin35 = 35  #(GPIO.BCM = 19)
pin36 = 36  #(GPIO.BCM = 16)
pin37 = 37  #(GPIO.BCM = 26)
pin38 = 38  #(GPIO.BCM = 20)
pin40 = 40  #(GPIO.BCM = 21)
#GPIO.setmode(GPIO.BCM)
GPIO.setup(pin31, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin32, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin33, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin35, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #3
0
from rc522 import RFID
rdr = RFID()

while True:
    rdr.wait_for_tag()
    (error, tag_type) = rdr.request()
    if not error:
        print("Tag detected")
        (error, uid) = rdr.anticoll()
        if not error:
            print("UID: " + str(uid))
            # Select Tag is required before Auth
            if not rdr.select_tag(uid):
                # Auth for block 10 (block 2 of sector 2) using default shipping key A
                if not rdr.card_auth(rdr.auth_a, 10,
                                     [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
                                     uid):
                    # This will print something like (False, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
                    print("Reading block 10: " + str(rdr.read(10)))
                    # Always stop crypto1 when done working
                    rdr.stop_crypto()

# Calls GPIO cleanup
rdr.cleanup()
Example #4
0
#!/usr/bin/env python

import signal
import time
import sys

from rc522 import RFID

run = True
rdr = RFID()
util = rdr.util()
util.debug = False


def end_read(signal, frame):
    global run
    print("\nCtrl+C captured, ending read.")
    run = False
    rdr.cleanup()
    sys.exit()


signal.signal(signal.SIGINT, end_read)

print("Starting")
while run:
    rdr.wait_for_tag()

    (error, data) = rdr.request()
    if not error:
        print("\nDetected: " + format(data, "02x"))
Example #5
0
#!/usr/bin/env python

import signal
import time

from rc522 import RFID

rdr = RFID()
util = rdr.util()
# Set util debug to true - it will print what's going on
util.debug = True

while True:
    # Wait for tag
    rdr.wait_for_tag()

    # Request tag
    (error, data) = rdr.request()
    if not error:
        print("\nDetected")

        (error, uid) = rdr.anticoll()
        if not error:
            # Print UID
            print("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

            # Set tag as used in util. This will call RFID.select_tag(uid)
            util.set_tag(uid)
            # Save authorization info (key B) to util. It doesn't call RFID.card_auth(), that's called when needed
            util.auth(rdr.auth_b, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
            # Print contents of block 4 in format "S1B0: [contents in decimal]". RFID.card_auth() will be called now