initial commit
This commit is contained in:
20
reader_data/sarah/src/open.py
Normal file
20
reader_data/sarah/src/open.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import board
|
||||
import time
|
||||
import busio
|
||||
from digitalio import DigitalInOut, Direction
|
||||
|
||||
|
||||
def main():
|
||||
PIN_DOOR = 6
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(PIN_DOOR,GPIO.OUT)
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
while True:
|
||||
time.sleep(1)
|
||||
GPIO.output(PIN_DOOR,True)
|
||||
time.sleep(4)
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
76
reader_data/sarah/src/pn532_low_power.py
Normal file
76
reader_data/sarah/src/pn532_low_power.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
This example shows connecting to the PN532 with I2C (requires clock
|
||||
stretching support), SPI, or UART. SPI is best, it uses the most pins but
|
||||
is the most reliable and universally supported. In this example we put the PN532
|
||||
into low power mode and sleep for 1 second in-between trying to read tags.
|
||||
After initialization, try waving various 13.56MHz RFID cards over it!
|
||||
"""
|
||||
|
||||
import time
|
||||
import board
|
||||
import busio
|
||||
import RPi.GPIO as GPIO
|
||||
import pandas as pd
|
||||
|
||||
from digitalio import DigitalInOut
|
||||
|
||||
#
|
||||
# NOTE: pick the import that matches the interface being used
|
||||
#
|
||||
from adafruit_pn532.i2c import PN532_I2C
|
||||
|
||||
# from adafruit_pn532.spi import PN532_SPI
|
||||
# from adafruit_pn532.uart import PN532_UART
|
||||
|
||||
# I2C connection:
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
|
||||
# Non-hardware
|
||||
# pn532 = PN532_I2C(i2c, debug=False)
|
||||
|
||||
# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
|
||||
# harware reset
|
||||
reset_pin = DigitalInOut(board.D6)
|
||||
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
|
||||
# wakeup! this means we don't need to do the I2C clock-stretch thing
|
||||
req_pin = DigitalInOut(board.D12)
|
||||
pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)
|
||||
|
||||
# SPI connection:
|
||||
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
# cs_pin = DigitalInOut(board.D5)
|
||||
# pn532 = PN532_SPI(spi, cs_pin, debug=False)
|
||||
|
||||
# UART connection
|
||||
# uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
|
||||
# pn532 = PN532_UART(uart, debug=False)
|
||||
|
||||
ic, ver, rev, support = pn532.firmware_version
|
||||
print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
|
||||
|
||||
# Configure PN532 to communicate with MiFare cards
|
||||
pn532.SAM_configuration()
|
||||
|
||||
df = pd.read_csv('data.csv')
|
||||
|
||||
#for csv_id in data.loc[:,"ID"]:
|
||||
# if("0432450A354B80" in csv_id):
|
||||
# print("yes")
|
||||
|
||||
t = [df.loc[lambda df: df['ID'] == "0432450A354B80"]]
|
||||
t
|
||||
|
||||
print("Waiting for RFID/NFC card...")
|
||||
|
||||
while True:
|
||||
# Check if a card is available to read
|
||||
uid = pn532.read_passive_target(timeout=0.5)
|
||||
print(".", end="")
|
||||
if uid is not None:
|
||||
print("Found card with UID:", [hex(i) for i in uid])
|
||||
print(uid)
|
||||
pn532.power_down()
|
||||
time.sleep(1.0)
|
||||
60
reader_data/sarah/src/pn532_simpletest.py
Normal file
60
reader_data/sarah/src/pn532_simpletest.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
This example shows connecting to the PN532 with I2C (requires clock
|
||||
stretching support), SPI, or UART. SPI is best, it uses the most pins but
|
||||
is the most reliable and universally supported.
|
||||
After initialization, try waving various 13.56MHz RFID cards over it!
|
||||
"""
|
||||
|
||||
import board
|
||||
import busio
|
||||
from digitalio import DigitalInOut
|
||||
|
||||
#
|
||||
# NOTE: pick the import that matches the interface being used
|
||||
#
|
||||
from adafruit_pn532.i2c import PN532_I2C
|
||||
|
||||
# from adafruit_pn532.spi import PN532_SPI
|
||||
# from adafruit_pn532.uart import PN532_UART
|
||||
|
||||
# I2C connection:
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
|
||||
# Non-hardware
|
||||
# pn532 = PN532_I2C(i2c, debug=False)
|
||||
|
||||
# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
|
||||
# harware reset
|
||||
reset_pin = DigitalInOut(board.D6)
|
||||
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
|
||||
# wakeup! this means we don't need to do the I2C clock-stretch thing
|
||||
req_pin = DigitalInOut(board.D12)
|
||||
pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)
|
||||
|
||||
# SPI connection:
|
||||
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
# cs_pin = DigitalInOut(board.D5)
|
||||
# pn532 = PN532_SPI(spi, cs_pin, debug=False)
|
||||
|
||||
# UART connection
|
||||
# uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=100)
|
||||
# pn532 = PN532_UART(uart, debug=False)
|
||||
|
||||
ic, ver, rev, support = pn532.firmware_version
|
||||
print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
|
||||
|
||||
# Configure PN532 to communicate with MiFare cards
|
||||
pn532.SAM_configuration()
|
||||
|
||||
print("Waiting for RFID/NFC card...")
|
||||
while True:
|
||||
# Check if a card is available to read
|
||||
uid = pn532.read_passive_target(timeout=0.5)
|
||||
print(".", end="")
|
||||
# Try again if no card is available.
|
||||
if uid is None:
|
||||
continue
|
||||
print("Found card with UID:", uid)#[i for i in uid])
|
||||
142
reader_data/sarah/src/reader.py
Normal file
142
reader_data/sarah/src/reader.py
Normal file
@@ -0,0 +1,142 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import board
|
||||
import busio
|
||||
from digitalio import DigitalInOut, Direction
|
||||
from adafruit_pn532.i2c import PN532_I2C
|
||||
import time
|
||||
from datetime import datetime
|
||||
import os
|
||||
import shutil
|
||||
|
||||
#
|
||||
# This tool was written by Kourosh (aladdin@fet.at) in 2022
|
||||
# and extended by Pet (pet@fet.at) in 6.2022
|
||||
#
|
||||
# It reads the ID from a RFID card and compares it to a stored set of cards
|
||||
# if the card is valid, it pulls a pin HIGH, which in turn opens the door
|
||||
# to the FET lab.
|
||||
#
|
||||
|
||||
def main():
|
||||
|
||||
#create a debug log to print everything that happens into there
|
||||
debug_file = open("/home/zutritt/Documents/sarah/logs/"+datetime.today().strftime('%Y%m%d')+"_debug_log.csv", "a")
|
||||
debug_file.write("\n\n" + datetime.now().strftime("%d/%m/%Y %H:%M:%S") +": Sarah (Simple Access for RFID Authenticated Homes) reader startup. \n\n")
|
||||
debug_file.close()
|
||||
|
||||
|
||||
##set up the hardware
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
reset_pin = DigitalInOut(board.D6)
|
||||
req_pin = DigitalInOut(board.D12)
|
||||
pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)
|
||||
pn532.SAM_configuration()
|
||||
PIN_DOOR = 6
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
GPIO.setup(4,GPIO.OUT)
|
||||
GPIO.setup(22,GPIO.OUT)
|
||||
GPIO.setup(5,GPIO.OUT)
|
||||
GPIO.setup(26,GPIO.OUT)
|
||||
GPIO.setup(PIN_DOOR,GPIO.OUT)
|
||||
GPIO.output(4,False)
|
||||
GPIO.output(22,False)
|
||||
GPIO.output(26,False)
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
|
||||
#create a backup of the data file
|
||||
shutil.copy('/home/zutritt/Documents/sarah/data.csv', '/home/zutritt/Documents/sarah/logs/' + datetime.today().strftime('%Y%m%d') + '_data_backup.csv')
|
||||
|
||||
#read the data file once. it will be re-read, if we don't know the UID of a read card or the card is expired.
|
||||
#this saves read/write cycles on the SD card
|
||||
data = pd.read_csv(r'/home/zutritt/Documents/sarah/data.csv') #,names=col_names)
|
||||
|
||||
#mail loop
|
||||
while True:
|
||||
|
||||
#try reading a tag
|
||||
time.sleep(0.5)
|
||||
uid = pn532.read_passive_target(timeout=0.5)
|
||||
#print(uid)
|
||||
|
||||
### DEBUG!!!!!
|
||||
#string = "04 4c 80 32 50 38 81" #pet80
|
||||
#uid = bytearray.fromhex(string)
|
||||
### DEBUG END!!!!
|
||||
|
||||
#there is the possibility to open the door via the website
|
||||
#the webserver saves an emtpy file (manual_door_open_request_set) to the disk
|
||||
#if the file is there, we open the door and delete the file afterwards
|
||||
if os.path.isfile('/home/zutritt/Documents/sarah/system_request_commands/manual_door_open_request_set'):
|
||||
#if this file exists, there was a door open request made from the browser
|
||||
GPIO.output(PIN_DOOR,True)
|
||||
time.sleep(4)
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
debug_file = open("/home/zutritt/Documents/sarah/logs/"+datetime.today().strftime('%Y%m%d')+"_debug_log.csv", "a")
|
||||
debug_file.write("\n"+datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ", Manual open via website.")
|
||||
debug_file.close()
|
||||
with open("/home/zutritt/Documents/sarah/logs/"+ datetime.today().strftime('%Y%m%d') +"_entrance_log.csv", "a") as x:
|
||||
x.write("Manual entry via website, " + datetime.now().strftime("%d/%m/%Y %H:%M:%S") + "\n")
|
||||
x.close()
|
||||
|
||||
os.remove('/home/zutritt/Documents/sarah/system_request_commands/manual_door_open_request_set')
|
||||
|
||||
#after reading a tag, we check if any numbers have been read
|
||||
#no numbers mean no tag has been detected
|
||||
if (not isinstance(uid,bytearray)):
|
||||
continue
|
||||
uid = [hex(i) for i in uid]
|
||||
uid = "".join(uid)
|
||||
|
||||
#write to the debug file that we found a tag
|
||||
debug_file = open("/home/zutritt/Documents/sarah/logs/"+datetime.today().strftime('%Y%m%d')+"_debug_log.csv", "a")
|
||||
debug_file.write("\n"+datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ", UID:" + uid)
|
||||
|
||||
#print (uid)
|
||||
#print (list(data["uid"]))
|
||||
|
||||
# check if the card is anywhere in our saved cards
|
||||
if uid in list(data["uid"]):
|
||||
#save the line where he card is in
|
||||
line = data.query("uid == @uid")
|
||||
print(line)
|
||||
expiration_date = datetime.strptime(str(list(line["expire"])[0]), "%Y-%m-%d")
|
||||
|
||||
#check if the card is expired
|
||||
if datetime.now() < expiration_date:
|
||||
|
||||
#open the door if the card is valid
|
||||
GPIO.output(PIN_DOOR,True)
|
||||
time.sleep(4)
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
|
||||
#log the entry to the entrance log and the debug log
|
||||
with open("/home/zutritt/Documents/sarah/logs/"+ datetime.today().strftime('%Y%m%d') +"_entrance_log.csv", "a") as x:
|
||||
debug_file.write(", Name:" + str(list(line["name"])[0]) + ", Matrikelnummer:" + str(list(line["matrikelnummer"])[0]) + ", !OKAY! access granted.")
|
||||
x.write(str(list(line["name"])[0]) + "," + datetime.now().strftime("%d/%m/%Y %H:%M:%S") + "\n")
|
||||
x.close()
|
||||
|
||||
|
||||
else: #card is expired
|
||||
debug_file.write(", Name:" + str(list(line["name"])[0]) + ", Matrikelnummer:" + str(list(line["matrikelnummer"])[0]) + ", !EXPIRED! no entry!")
|
||||
try:
|
||||
data = pd.read_csv(r'/home/zutritt/Documents/sarah/data.csv') #read the file again, in case something has changed
|
||||
debug_file.write(" (data.csv reloaded)")
|
||||
except OSError as e:
|
||||
debug_file.write(", !data.csv reloaded failed!")
|
||||
|
||||
else:#the card is not in the system
|
||||
debug_file.write(", !No known UID! no entry!")
|
||||
try:
|
||||
data = pd.read_csv(r'/home/zutritt/Documents/sarah/data.csv') #read the file again, in case something has changed
|
||||
debug_file.write(" (data.csv reloaded)")
|
||||
except OSError as e:
|
||||
debug_file.write(", !data.csv reloaded failed!")
|
||||
|
||||
GPIO.output(PIN_DOOR,False)
|
||||
debug_file.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user