-
Notifications
You must be signed in to change notification settings - Fork 0
/
doorlock.py
77 lines (61 loc) · 2.31 KB
/
doorlock.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
#!usr/bin/env python
import sys
import MySQLdb
from threading import Thread
import threading
import time
import RPi.GPIO as GPIO
import json
from random import randint
from evdev import InputDevice
from select import select
import SimpleMFRC522
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(13,GPIO.OUT)
class doorlock:
global dbHost
global dbName
global dbUser
global dbPass
dbHost = 'localhost'
dbName = 'mysql'
dbUser = 'root'
dbPass = 'raspberry'
def __init__(self):
try:
while 1:
self.listen_rfid()
#t.daemoon = True
#t.start()
except KeyboardInterrupt:
pass
def returnToIdle_fromAccessGranted(self):
GPIO.output(13,GPIO.LOW)
def listen_rfid(self):
reader = SimpleMFRC522.SimpleMFRC522()
print("Please place your rfid")
try:
id, text = reader.read()
dbConnection = MySQLdb.connect(host=dbHost, user=dbUser$
cur = dbConnection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("SELECT * FROM access_list WHERE rfid_code $
if cur.rowcount !=1:
print("Access Denied")
cur.execute("INSERT INTO access_log SET Name = $
dbConnection.commit()
time.sleep(3)
self.returnToIdle_fromAccessGranted()
else:
cur.execute("INSERT INTO access_log SET Name = $
dbConnection.commit()
print("Access Granted, now an sms is sent")
GPIO.output(13,GPIO.HIGH)
dbConnection.close()
time.sleep(5)
self.returnToIdle_fromAccessGranted()
finally:
GPIO.cleanup()
if __name__ == '__main__':
w = doorlock()
w.t.mainloop()