makeit heat

This commit is contained in:
Arti Zirk 2016-10-15 12:21:32 +02:00
parent 5aaccabc93
commit 338490e887
2 changed files with 17 additions and 13 deletions

View File

@ -30,4 +30,8 @@ fetch("/temps.json").then(function (resp) {
}
});
function heat(h) {
fetch("/heat",{ method: 'POST', body: JSON.stringify({message:h})})
}
createTimeline();

26
main.py
View File

@ -89,8 +89,9 @@ html = """<!DOCTYPE html>
<div style="display: flex;flex-direction: row;flex-wrap: wrap;justify-content: center;align-items: center;">
<div id="temp_container">
<div style="display: inline-block; position: relative; top: -24px;">
<!--input type="text" style="display: block; width: 46px; font-size: 20px; padding: 0; margin: 20px 0;">
<button style="display:block; height:50px; width:50px;padding:10px;">set</button-->
<!--input type="text" style="display: block; width: 46px; font-size: 20px; padding: 0; margin: 20px 0;"-->
<button style="display:block; height:50px; width:50px;padding:10px;font-size: 25px;" onclick="heat('1')"></button>
<button style="display:block; height:50px; width:50px;padding:10px;font-size: 25px;" onclick="heat('0')"></button>
</div>
<canvas data-width="100"
data-height="300"
@ -121,15 +122,12 @@ html = """<!DOCTYPE html>
temps = deque(maxlen=10)
arduino = None
def stream(dev):
with serial.Serial(ser_dev, timeout=1) as s:
global arduino
arduino = s
while True:
temperature = s.readline().decode().strip().split()
if not temperature:
continue
print("temperature", temperature)
temps.append(temperature[0])
while True:
temperature = dev.readline().decode().strip().split()
if not temperature:
continue
print("temperature", temperature)
temps.append(temperature[0])
@ -162,7 +160,8 @@ def application(env, start_response):
message = parse_qs(message)["message"][0]
start_response("200 OK", [('Content-Type', 'application/json')])
return [json.dumps("OK")]
print(arduino.write(message.encode()))
return [json.dumps(message).encode()]
if env["PATH_INFO"] == "/temps.json":
start_response('200 OK', [('Content-Type', 'application/json')])
@ -206,8 +205,9 @@ if __name__ == "__main__":
print("{} is not a valid tty device".format(ser_dev))
exit(1)
arduino = serial.Serial(ser_dev, timeout=2)
import threading
t = threading.Thread(target=stream, args=[ser_dev])
t = threading.Thread(target=stream, args=[arduino])
# classifying as a daemon, so they will die when the main dies
t.daemon = True