Skip to content

Instantly share code, notes, and snippets.

@lin-ycv
Created March 24, 2023 04:41
Show Gist options
  • Save lin-ycv/d818292315400bd429f8dd9ee434c642 to your computer and use it in GitHub Desktop.
Save lin-ycv/d818292315400bd429f8dd9ee434c642 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
import datetime
relayPin = 4
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(relayPin, GPIO.OUT)
GPIO.output(relayPin,1)
def pin_on(pin):
GPIO.output(pin,0)
def pin_off(pin):
GPIO.output(pin,1)
with open("/home/pi/Desktop/id.txt") as file:
verified = [line.strip() for line in file]
rfid= SimpleMFRC522()
print("Sentry started")
try:
while True:
cardid = rfid.read_id()
if str(cardid) in verified:
now = datetime.datetime.now()
if(str(cardid)=="???")or (6 > now.weekday() > 4 and 21 > now.hour > 7):
pin_on(relayPin)
print(cardid,":",now)
time.sleep(2)
pin_off(relayPin)
else:
print(cardid, ":Time restricted")
time.sleep(2)
else:
print(cardid)
time.sleep(2)
finally:
pin_off(relayPin)
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment