some deletes and refs
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
<span>
|
<span>
|
||||||
<form action="/on"><button type="submit">Relay On</button></form>
|
<form action="/on"><button type="submit">Relay On</button></form>
|
||||||
<form action="/off"><button type="submit">Relay Off</button></form>
|
<form action="/off"><button type="submit">Relay Off</button></form>
|
||||||
<form action="/toggle"><button type="submit">Toggle Relay</button></form>
|
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ name = "Test Sensor"
|
|||||||
|
|
||||||
humidity_limit_path = 'humidity_limit'
|
humidity_limit_path = 'humidity_limit'
|
||||||
sensor_log_path = 'sensors.log'
|
sensor_log_path = 'sensors.log'
|
||||||
|
|
||||||
log_file: io.TextIOWrapper
|
log_file: io.TextIOWrapper
|
||||||
log_cursor_file: io.TextIOWrapper
|
log_cursor_file: io.TextIOWrapper
|
||||||
|
|
||||||
@@ -47,8 +48,12 @@ def write_log():
|
|||||||
|
|
||||||
log_values(log_file)
|
log_values(log_file)
|
||||||
|
|
||||||
|
pos = log_file.tell()
|
||||||
|
update_cursor_file(pos)
|
||||||
|
|
||||||
|
def update_cursor_file(pos):
|
||||||
log_cursor_file.seek(0,0)
|
log_cursor_file.seek(0,0)
|
||||||
log_cursor_file.write(str(log_file.tell()))
|
log_cursor_file.write(str(pos))
|
||||||
|
|
||||||
def log_values(file):
|
def log_values(file):
|
||||||
global temp, humidity
|
global temp, humidity
|
||||||
@@ -75,11 +80,10 @@ def update(_):
|
|||||||
write_log()
|
write_log()
|
||||||
|
|
||||||
def update_relay():
|
def update_relay():
|
||||||
if humidity > humidity_limit:
|
if high_humidity():
|
||||||
relay_on()
|
relay_on()
|
||||||
return
|
else:
|
||||||
|
relay_off()
|
||||||
relay_off()
|
|
||||||
|
|
||||||
def high_humidity() -> bool:
|
def high_humidity() -> bool:
|
||||||
return humidity >= humidity_limit
|
return humidity >= humidity_limit
|
||||||
@@ -107,13 +111,6 @@ def serve_root(_):
|
|||||||
|
|
||||||
send_response(server, index)
|
send_response(server, index)
|
||||||
|
|
||||||
def toggle_relay(_):
|
|
||||||
global relay
|
|
||||||
val = relay.value()
|
|
||||||
relay.value(not val)
|
|
||||||
|
|
||||||
redirect_root()
|
|
||||||
|
|
||||||
def handle_relay_off(_):
|
def handle_relay_off(_):
|
||||||
relay_off()
|
relay_off()
|
||||||
redirect_root()
|
redirect_root()
|
||||||
@@ -160,7 +157,6 @@ def read_limit() -> int:
|
|||||||
return int(file.readline())
|
return int(file.readline())
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
init_clock()
|
|
||||||
init_log()
|
init_log()
|
||||||
init_settings()
|
init_settings()
|
||||||
init_timer()
|
init_timer()
|
||||||
@@ -179,18 +175,14 @@ def init_log():
|
|||||||
|
|
||||||
cursor = 0
|
cursor = 0
|
||||||
cursor_content = log_cursor_file.readline()
|
cursor_content = log_cursor_file.readline()
|
||||||
print(cursor_content)
|
|
||||||
try:
|
try:
|
||||||
cursor = int(cursor_content)
|
cursor = int(cursor_content)
|
||||||
except:
|
except:
|
||||||
cursor = 0
|
cursor = 0
|
||||||
|
|
||||||
print(cursor)
|
|
||||||
log_file.seek(cursor, 0)
|
log_file.seek(cursor, 0)
|
||||||
|
|
||||||
def init_clock():
|
|
||||||
ntptime.settime()
|
|
||||||
|
|
||||||
def init_settings():
|
def init_settings():
|
||||||
global humidity_limit
|
global humidity_limit
|
||||||
|
|
||||||
@@ -208,7 +200,6 @@ def init_timer():
|
|||||||
def init_webserver():
|
def init_webserver():
|
||||||
load_index_template()
|
load_index_template()
|
||||||
server.add_route('/', serve_root)
|
server.add_route('/', serve_root)
|
||||||
server.add_route('/toggle', toggle_relay)
|
|
||||||
server.add_route('/off', handle_relay_off)
|
server.add_route('/off', handle_relay_off)
|
||||||
server.add_route('/on', handle_relay_on)
|
server.add_route('/on', handle_relay_on)
|
||||||
server.add_route('/set_limit', set_humidity_limit, method="POST")
|
server.add_route('/set_limit', set_humidity_limit, method="POST")
|
||||||
@@ -217,8 +208,8 @@ def init_webserver():
|
|||||||
|
|
||||||
def load_index_template():
|
def load_index_template():
|
||||||
global index_template
|
global index_template
|
||||||
with open('index.html') as index_html:
|
with open('index.html') as index_html_file:
|
||||||
index_template = ''.join(index_html.readlines())
|
index_template = ''.join(index_html_file.readlines())
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global server
|
global server
|
||||||
|
|||||||
Reference in New Issue
Block a user