forked from photous/gpio_web_control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (49 loc) · 1.52 KB
/
app.py
File metadata and controls
56 lines (49 loc) · 1.52 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
# This app basicly just calls 2 functions (on and off)
# using 2 Buttons
# This is Awesome
# You can Click On and it will print "IT'S ON!" and switches the GPIO pin On
# You can Click Off and it will print "IT'S OFF!" and switches the GPIO pin On
import RPi.GPIO as GPIO
import time
from flask import Flask, render_template, request
app = Flask(__name__)
@app.before_first_request
def _set_everything():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
def gpio_on(pin):
# to use Raspberry Pi board pin numbers
# set up GPIO output channel
##############
GPIO.output(pin,GPIO.HIGH)
return
def gpio_off(pin):
# to use Raspberry Pi board pin numbers
# set up GPIO output channel
##############
GPIO.output(pin,GPIO.LOW)
return
@app.route('/', methods=['GET', 'POST'])
def root(x=None, y=None):
# do something to send email
print "IT'S Root!"
return render_template('click.html', x=x)
@app.route('/on', methods=['GET', 'POST'])
def on(x=None, y=None):
# do some other thing
print "IT'S ON!"
# You can change 11 to use a different GPIO pin
gpio_on(11)
return render_template('off.html', x=x)
return redirect('/off')
@app.route('/off', methods=['GET', 'POST'])
def off(x=None, y=None):
# do something to send email
print "IT'S OFF!"
# You can change 11 to use a different GPIO pin
gpio_off(11)
return render_template('on.html', x=x)
return redirect('/on')
GPIO.cleanup()
if __name__ == '__main__':
app.run(host= '0.0.0.0', debug=True)