fix temp parsingn from arduino
This commit is contained in:
parent
d701b63914
commit
117ae69e27
20
main.py
20
main.py
@ -88,10 +88,10 @@ 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>
|
||||
</div-->
|
||||
<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-->
|
||||
</div>
|
||||
<canvas data-width="100"
|
||||
data-height="300"
|
||||
data-type="linear-gauge"
|
||||
@ -121,15 +121,14 @@ html = """<!DOCTYPE html>
|
||||
temps = deque(maxlen=10)
|
||||
|
||||
def stream(dev):
|
||||
with serial.Serial(dev, timeout=1) as s:
|
||||
while True:
|
||||
temperature = s.readline().decode().strip()
|
||||
temperature = dev.readline().decode().strip().split()[0]
|
||||
if not temperature:
|
||||
continue
|
||||
print("temperature", temperature)
|
||||
temps.append(temperature)
|
||||
|
||||
|
||||
arduino = None
|
||||
|
||||
def application(env, start_response):
|
||||
|
||||
@ -159,8 +158,8 @@ def application(env, start_response):
|
||||
if message.startswith("message="):
|
||||
message = parse_qs(message)["message"][0]
|
||||
|
||||
messages.appendleft(html_escape(message.strip()))
|
||||
#start_response("200 OK", [('Content-Type', 'application/json')])
|
||||
start_response("200 OK", [('Content-Type', 'application/json')])
|
||||
return [json.dumps("OK")]
|
||||
|
||||
if env["PATH_INFO"] == "/temps.json":
|
||||
start_response('200 OK', [('Content-Type', 'application/json')])
|
||||
@ -204,9 +203,12 @@ if __name__ == "__main__":
|
||||
print("{} is not a valid tty device".format(ser_dev))
|
||||
exit(1)
|
||||
|
||||
with serial.Serial(ser_dev, timeout=1) as s:
|
||||
arduino = s
|
||||
import threading
|
||||
t = threading.Thread(target=stream, args=[ser_dev])
|
||||
|
||||
|
||||
# classifying as a daemon, so they will die when the main dies
|
||||
t.daemon = True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user