Created
March 24, 2023 04:41
-
-
Save lin-ycv/d818292315400bd429f8dd9ee434c642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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