-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
122 lines (92 loc) · 2.72 KB
/
Copy path__init__.py
File metadata and controls
122 lines (92 loc) · 2.72 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from flask import Flask, request, render_template, jsonify
import RPi.GPIO as GPIO
import time
from flask_mail import Mail, Message
import ConfigParser
import os
shutdown = False
parser = ConfigParser.ConfigParser()
parser.read(os.path.expanduser('/home/pi/Desktop/.config.txt'))
app = Flask(__name__)
app.config.update(dict(
DEBUG = True,
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 587,
MAIL_USE_TLS= True,
MAIL_USE_SSL = False,
MAIL_USERNAME = 'edwinyjlim@gmail.com',
MAIL_PASSWORD = parser.get('important', 'email_pw')
))
mail = Mail(app)
the_punchline = parser.get('important', 'punchline')
@app.context_processor
def inject_template_globals():
return {
'ts': time.clock(),
}
def set_GPIO (pin):
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.OUT)
def reset_GPIO():
GPIO.cleanup()
def blink_GPIO (pin, blink_count):
set_GPIO(pin)
for i in range(0, blink_count):
GPIO.output(pin, 1)
time.sleep(1)
GPIO.output(pin, 0)
time.sleep(1)
reset_GPIO()
return
def activate_GPIO (pin, duration):
set_GPIO(pin)
GPIO.output(pin, 1)
time.sleep(duration)
GPIO.output(pin, 0)
reset_GPIO()
return
@app.route('/')
def hello_world():
if shutdown:
return "shutdown variable enabled"
return render_template('index.html')
@app.route('/knockknock')
def knockknock():
if shutdown:
return "shutdown variable enabled"
return render_template('knockknock.html')
@app.route('/punchline', methods=['POST'])
def punchline():
if shutdown:
return "shutdown variable enabled"
punchline = request.form.get('punchline')
print 'user submitted passphrase: '+punchline
door_status = 'closed'
message = 'Incorrect passphrase.'
if punchline == the_punchline:
door_status = 'open'
message = 'Welcome.'
return jsonify(door_status=door_status,
message=message);
@app.route('/buzzer', methods=['POST'])
def buzzer():
if shutdown:
return "shutdown variable enabled"
punchline = request.form.get('punchline')
door_status = 'closed'
msg = Message("RPi buzzed open the door",
sender="edwinyjlim@gmail.com",
recipients=["edwinyjlim@gmail.com"])
msg.body = "delivered by Flask mail"
if punchline == the_punchline:
activate_GPIO(7,7)
door_status = 'open'
mail.send(msg)
return jsonify(door_status=door_status)
@app.route('/shutdown', methods=['POST', 'GET'])
def shutdown_server():
global shutdown
shutdown = True
return 'Server shutdown variable set to True.'
if __name__ == "__main__":
app.run()