-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmasher_flask.py
executable file
·54 lines (47 loc) · 1.56 KB
/
masher_flask.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
#!/usr/bin/python
# 1) If temp hits target, turn off
# 2) If temp less than target, turn on
# 3) While loop to allow for warmup
# 4) Set a length of time to run at real temp (timedelta)
import time
import datetime
import yagmail
from temp_reader import readTempOnce
from outlet_control import turnOutletOn, turnOutletOff
from flask import Flask
from flask import render_template
app = Flask(__name__)
targetTemp = 150
allowedHighDifference = 3
allowedLowDifference = 1
timeLengthInMinutes = 30
onCode = '21811'
offCode = '21820'
@app.route('/')
def main():
startTemp = readTempOnce()
startTime = datetime.datetime.now()
warmup()
endTime = datetime.datetime.now() + datetime.timedelta(minutes=timeLengthInMinutes)
warmup()
temp = readTempOnce()
print 'temp is ' + str(temp)
return render_template('temp.html', temp=temp)
while datetime.datetime.now() < endTime:
warmup()
print str (timeLengthInMinutes) + ' minutes are up!'
print 'We started at ' + str(startTime) + ' at ' + str(startTemp) + ' degrees.'
def warmup():
print 'warming up...'
temp = readTempOnce()
if temp > targetTemp + allowedHighDifference:
yagmail.SMTP('[email protected]').send('[email protected]', '[ALERT]The temp is too high!', 'The temp is currently ' + str(temp))
print 'temp is ' + str(temp)
while temp < targetTemp:
turnOutletOn(onCode)
temp = readTempOnce()
print 'temp is ' + str(temp)
print 'all warmed up.'
turnOutletOff(offCode)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)