-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRFIDMain.py
46 lines (35 loc) · 1.2 KB
/
RFIDMain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import datetime
import sys
import time
import RPi.GPIO as io
import select
from HNBC.HNBC.models import RFIDKey, RFIDLog
io.setmode(io.BCM)
power_pin = 2
pir_pin = 24
io.setup(pir_pin, io.IN)
io.setup(power_pin, io.OUT)
io.output(power_pin, False)
turnoff = datetime.datetime.now()
while True:
while sys.stdin in select.select([sys.stdin],[],[],0)[0]:
rfid = sys.stdin.readline()
if rfid:
rfid = ''.join(rfid.splitlines())
print(rfid)
try:
# Verify that there is a key, and that the user is active
key = RFIDKey.objects.get(code='asdf', user__isnull=False)
user = key.user
except RFIDKey.DoesNotExist:
continue # Key isn't in database
except RFIDKey.MultipleObjectsReturned:
continue # Possibly bad juju or mucked up database
if key and user.is_active:
RFIDLog(key=key).save()
print("POWER ON")
io.output(power_pin, True)
turnoff = datetime.datetime.now() + datetime.timedelta(0,10)
if turnoff < datetime.datetime.now():
io.output(power_pin, False)
time.sleep(.25)