2017-02-17 15:47:19 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
import MFRC522
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-28 08:50:49 +00:00
|
|
|
# [1] Create an object of the class MFRC522
|
2017-09-27 16:09:50 +00:00
|
|
|
GPIO.setwarnings(False);
|
2017-02-17 15:47:19 +00:00
|
|
|
MIFAREReader = MFRC522.MFRC522()
|
|
|
|
|
2017-09-28 08:50:49 +00:00
|
|
|
# [2] Scan for cards
|
2017-02-17 15:47:19 +00:00
|
|
|
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
|
|
|
|
|
2017-09-28 08:50:49 +00:00
|
|
|
# [3] If no card found -> exit 1
|
|
|
|
if status != MIFAREReader.MI_OK:
|
2017-09-28 08:55:59 +00:00
|
|
|
print 127;
|
|
|
|
exit(127);
|
2017-02-17 15:47:19 +00:00
|
|
|
|
2017-09-28 08:50:49 +00:00
|
|
|
# [4] Get the UID of the card
|
2017-02-17 15:47:19 +00:00
|
|
|
(status,uid) = MIFAREReader.MFRC522_Anticoll()
|
|
|
|
|
2017-09-28 08:50:49 +00:00
|
|
|
# [5] If no UID read -> exit 1
|
|
|
|
if status != MIFAREReader.MI_OK:
|
2017-09-28 08:55:59 +00:00
|
|
|
print 127;
|
|
|
|
exit(127);
|
2017-02-17 15:47:19 +00:00
|
|
|
|
2017-09-28 08:50:49 +00:00
|
|
|
# [6] Print UID
|
2017-10-12 18:10:05 +00:00
|
|
|
hexCode = [];
|
2017-10-12 18:12:12 +00:00
|
|
|
hexCode.append( str(hex(uid[0]))[2:] );
|
|
|
|
hexCode.append( str(hex(uid[1]))[2:] );
|
|
|
|
hexCode.append( str(hex(uid[2]))[2:] );
|
|
|
|
hexCode.append( str(hex(uid[3]))[2:] );
|
2017-10-12 18:10:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( len(hexCode[0]) == 1 ):
|
|
|
|
hexCode[0] = '0' + hexCode[0];
|
|
|
|
|
|
|
|
if( len(hexCode[1]) == 1 ):
|
|
|
|
hexCode[1] = '0' + hexCode[1];
|
|
|
|
|
|
|
|
if( len(hexCode[2]) == 1 ):
|
|
|
|
hexCode[2] = '0' + hexCode[2];
|
|
|
|
|
|
|
|
if( len(hexCode[3]) == 1 ):
|
|
|
|
hexCode[3] = '0' + hexCode[3];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suid = hexCode[0];
|
|
|
|
suid += '-' + hexCode[1];
|
|
|
|
suid += '-' + hexCode[2];
|
|
|
|
suid += '-' + hexCode[3];
|
2017-02-17 15:47:19 +00:00
|
|
|
|
2017-02-24 09:14:51 +00:00
|
|
|
print suid;
|
|
|
|
exit(0);
|