venerdì 9 settembre 2016

Raspberry Pi - NFC door opener

As shown in the previous tutorial, using the MFRC522-python library ( and the data read example script, I'm able to read the UniqueID (UID) of my NFC card.

On GPIO17 (= pin 11) I have the 220v relay signal that open the electric door lock. Therefore, editing the read example script, if an allowed UID is read than the door will be opened!

I add also a log file to control if somebody try to force the system
import RPi.GPIO as GPIO
import MFRC522
import signal
import time
import logging

# Logging
                            format='%(asctime)s %(levelname)s %(message)s',
                            datefmt='%d/%m/%Y %H:%M:%S',
                            level=logging.DEBUG)"script initialized")

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# 220v relay - electric door opener
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(11, GPIO.OUT) ## Setup GPIO17 -> pin 11 to OUT

# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while true:
    # Scan for cards    
    (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

    # If a card is found
    if status == MIFAREReader.MI_OK:
          # Get the UID of the card
          (status,uid) = MIFAREReader.MFRC522_Anticoll()

          # If we have the UID, continue
          if status == MIFAREReader.MI_OK:

          # My card UID
myUID = [141,113,243,56, 231]

# Check if authenticated
          if uid == myUID:
                  # open the door
                  # save to log file
        'Authenticated uid = %s' % uid)
                 logging.error('Authentication failed uid = %s' % uid)

Nessun commento:

Posta un commento