makeit heat
This commit is contained in:
parent
5aaccabc93
commit
338490e887
4
main.js
4
main.js
@ -30,4 +30,8 @@ fetch("/temps.json").then(function (resp) {
|
||||
}
|
||||
});
|
||||
|
||||
function heat(h) {
|
||||
fetch("/heat",{ method: 'POST', body: JSON.stringify({message:h})})
|
||||
}
|
||||
|
||||
createTimeline();
|
||||
|
16
main.py
16
main.py
@ -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,11 +122,8 @@ 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()
|
||||
temperature = dev.readline().decode().strip().split()
|
||||
if not temperature:
|
||||
continue
|
||||
print("temperature", temperature)
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user