-
Notifications
You must be signed in to change notification settings - Fork 0
/
domoticapp.py
133 lines (106 loc) · 3.55 KB
/
domoticapp.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
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
123
124
125
126
127
128
129
130
131
132
133
'''
Codigo adaptado para la raspberry pi
este codigo es exclusivamente para la funcion de backend
para casa domotica.
'''
from flask import Flask ,render_template , url_for, request
import RPi.GPIO as GPIO
#como estan organizados los GPIO's
room1 = 17
room2 = 4
room3 = 27
living = 22
kitchen = 18
garage = 23
tv1 = 24
tv2 = 25
salidas = [room1,room2,room3,living,kitchen,garage,tv1,tv2]
GPIO.setmode(GPIO.BCM)
for i in range(8):
GPIO.setup(salidas[i],GPIO.OUT)
app = Flask(__name__)
@app.route('/', methods=["GET"])
def hello():
return render_template('main.html')
@app.route('/maindooropen', methods=["POST"])
def room1on():
name = "Main Door Open!"
GPIO.output(room1,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/maindoorclosed', methods=["POST"])
def room1off():
name = "Main Door Closed!"
GPIO.output(room1,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/bedroomdooropen', methods=["POST"])
def room2on():
name = "Bedroom Door Open"
GPIO.output(room2,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/bedroomdoorclosed', methods=["POST"])
def room2off():
name = "Bedroom Door Closed"
GPIO.output(room2,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/bedroomlighton', methods=["POST"])
def room3on():
name = "Bedroom Light on!"
GPIO.output(room3,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/bedroomlightoff', methods=["POST"])
def room3off():
name = "Bedroom Light off!"
GPIO.output(room3,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/kitchenon', methods=["POST"])
def kitchenon():
name = "Kitchen on!"
GPIO.output(kitchen,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/kitchenoff', methods=["POST"])
def kitchenoff():
name = "Kitchen off!"
GPIO.output(kitchen,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/livingon', methods=["POST"])
def livingon():
name = "Living room on!"
GPIO.output(living,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/livingoff', methods=["POST"])
def livingoff():
name = "Living room off!"
GPIO.output(living,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/garageon', methods=["POST"])
def garageon():
name = "Garage on!"
GPIO.output(garage,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/garageoff', methods=["POST"])
def garageoff():
name = "Garage off!"
GPIO.output(garage,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/tv1on', methods=["POST"])
def tvoneon():
name = "TV #1 on!"
GPIO.output(tv1,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/tv1off', methods=["POST"])
def tvoneoff():
name = "TV #1 off!"
GPIO.output(tv1,GPIO.LOW)
return render_template("main.html", name=name)
@app.route('/tv2on', methods=["POST"])
def tvtwoon():
name = "TV #2 on!"
GPIO.output(tv2,GPIO.HIGH)
return render_template("main.html", name=name)
@app.route('/tv2off', methods=["POST"])
def tvtwooff():
name = "TV #2 off!"
GPIO.output(tv2,GPIO.LOW)
return render_template("main.html", name=name)
if __name__ == '__main__':
app.run(debug = "True", host = "0.0.0.0")