/
attendance.py
executable file
·83 lines (75 loc) · 2.12 KB
/
attendance.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/home/darshil/MyApp/env/bin/python
from app import app, db, mail
from app.models import User, Logs
from time import sleep
import os
import RPi.GPIO as GPIO
from subprocess import *
import datetime
strpath = ""
strfile = "webcam"
IRPin=17
LEDRed=22
LEDGrn=23
LEDScan=27
global flagProx
flagProx=False
debug = False
GPIO.setmode(GPIO.BCM)
GPIO.setup(IRPin, GPIO.IN)
GPIO.setup(LEDRed, GPIO.OUT)
GPIO.setup(LEDGrn, GPIO.OUT)
GPIO.setup(LEDScan, GPIO.OUT)
GPIO.output(LEDGrn, GPIO.LOW);
GPIO.output(LEDRed, GPIO.LOW);
GPIO.output(LEDScan, GPIO.LOW);
def run_cmd(cmd):
p = Popen(cmd, shell=True, stdout=PIPE)
output = p.communicate()[0]
return output
def capture():
GPIO.output(LEDRed, GPIO.LOW)
os.system("sudo fswebcam --device /dev/video0 --input 0 --resolution 352x288 --save "+
strpath+strfile+".jpg --skip 2")
GPIO.output(LEDRed, GPIO.HIGH)
def scan():
GPIO.output(LEDScan, GPIO.HIGH)
scanned=''
count=0
global flagProx
while scanned=='' and flagProx:
count = count + 1
capture()
scanned=run_cmd("zbarimg "+strpath+strfile+".jpg")
#GPIO.output(LEDRed, GPIO.HIGH);
if count == 10:
flagProx=False
flagProx=False
user_obj = db.session.query(User).filter_by(qr_data = scanned[8:-1]).all()
if scanned!='':
GPIO.output(LEDGrn, GPIO.HIGH);
GPIO.output(LEDRed, GPIO.LOW);
sleep(8)
if debug == True:
print "Scanned hash %s User ID %s" % (scanned, user_obj[0].get_id())
return user_obj[0].get_id()
def blinkRED():
GPIO.output(LEDGrn, GPIO.LOW)
GPIO.output(LEDRed, GPIO.HIGH)
sleep(0.2)
GPIO.output(LEDRed, GPIO.LOW)
sleep(0.8)
if __name__ == "__main__":
while True:
if (GPIO.input(IRPin)):
global flagProx
flagProx=True
userid=scan()
logger = Logs()
logger.user_id = userid
logger.timestamp = datetime.datetime.now()
db.session.add(logger)
db.session.commit()
# Here goes something to add for Front-end
else:
blinkRED() # When nothing is there blink red LED with some predefined period