-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebAPI.py
executable file
·117 lines (95 loc) · 2.98 KB
/
webAPI.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
from flask import Flask
app = Flask(__name__)
webAPIRoot = "/home/rock64/webAPI"
def heaterON(gpionr, room):
with open('/sys/class/gpio/gpio{}/value'.format(gpionr), 'w') as f:
f.write("1")
return '{}: ogrzewanie wlaczone'.format(room)
def heaterOFF(gpionr, room):
with open('/sys/class/gpio/gpio{}/value'.format(gpionr), 'w') as f:
f.write("0")
return '{}: ogrzewanie wlaczone'.format(room)
def heaterStatus(gpionr, room):
with open('/sys/class/gpio/gpio{}/value'.format(gpionr)) as f:
status = f.read()
if status.split('\n')[0] == "1":
return "{}: ogrzewanie jest wlaczone".format(room)
if status.split('\n')[0] == "0":
return "{}: ogrzewanie jest wylaczone".format(room)
return "{}: status ogrzewania nieznany".format(room)
@app.route('/areyoualive')
def areyoualive():
with open('{}/status'.format(webAPIRoot)) as f:
return f.read().split('\n')[0]
@app.route('/lazienka-gora-on')
def lazienkaGoraOn():
return heaterON(84, "lazienka-gora")
@app.route('/lazienka-gora-off')
def lazienkaGoraOff():
return heaterOFF(84, "lazienka-gora")
@app.route('/lazienka-gora-status')
def lazienkaGoraStatus():
return heaterStatus(84, "lazienka-gora")
@app.route('/gabinet-on')
def gabinetOn():
return heaterON(82, "gabinet")
@app.route('/gabinet-off')
def gabinetOff():
return heaterOFF(82, "gabinet")
@app.route('/gabinet-status')
def gabinetStatus():
return heaterStatus(82, "gabinet")
@app.route('/sypialnia-on')
def sypialniaON():
return heaterON(79, "sypialnia")
@app.route('/sypialnia-off')
def sypialniaOFF():
return heaterOFF(79, "sypialnia")
@app.route('/sypialnia-status')
def sypialniaStatus():
return heaterStatus(79, "sypialnia")
@app.route('/przedpokoj-on')
def przepokojON():
return heaterON(83, "przedpokoj")
@app.route('/przedpokoj-off')
def przedpokojOff():
return heaterOFF(83, "przedpokoj")
@app.route('/przedpokoj-status')
def przedpokojStatus():
return heaterStatus(83, "przedpokoj")
@app.route('/lazienka-dol-on')
def lazienkaDolOn():
return heaterON(87, "lazienka-dol")
@app.route('/lazienka-dol-off')
def lazienkaDolOff():
return heaterOFF(87, "lazienka-dol")
@app.route('/lazienka-dol-status')
def lazienkaDolStatus():
return heaterStatus(87, "lazienka-dol")
@app.route('/zosia-on')
def zosiaON():
return heaterON(80, "zosia")
@app.route('/zosia-off')
def zosiaOFF():
return heaterOFF(80, "zosia")
@app.route('/zosia-status')
def zosiaStatus():
return heaterStatus(80, "zosia")
@app.route('/justyna-on')
def justynaON():
return heaterON(81, "justyna")
@app.route('/justyna-off')
def justynaOFF():
return heaterOFF(81, "justyna")
@app.route('/justyna-status')
def justynaStatus():
return heaterStatus(81, "justyna")
@app.route('/salon-on')
def salonON():
return heaterON(86, "salon")
@app.route('/salon-off')
def salonOFF():
return heaterOFF(86, "salon")
@app.route('/salon-status')
def salonStatus():
return heaterStatus(86, "salon")