From dfab16037cd36563d336189bafb15f59ea681a25 Mon Sep 17 00:00:00 2001 From: Ben Coombs <bencoombs@protonmail.com> Date: Wed, 6 Jan 2021 02:17:08 +1300 Subject: [PATCH] Added Flask server, simple Arduino serial script. TODO: connect these together. --- app.py | 26 +++++++++++++++++++ simple_serial/simple_serial.ino | 18 +++++++++++++ {js => static/js}/respiration_math.js | 0 .../breath_plot.html | 6 +++-- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 app.py create mode 100644 simple_serial/simple_serial.ino rename {js => static/js}/respiration_math.js (100%) rename breath_plot.html => templates/breath_plot.html (99%) diff --git a/app.py b/app.py new file mode 100644 index 0000000..e0dc8a6 --- /dev/null +++ b/app.py @@ -0,0 +1,26 @@ +from flask import Flask, render_template; +import serial; +import time; + +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('breath_plot.html') + +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0') + +#ser = serial.Serial('COM4', 112500, timeout=1) +#print(ser.name) +#ser.flushInput() + +#while True: +# try: +# ser.write(b'A') +# time.sleep(0.1) +# ser_bytes = ser.readline() +# print(ser_bytes) +# except KeyboardInterrupt: +# print("Keyboard Interrupt") +# break diff --git a/simple_serial/simple_serial.ino b/simple_serial/simple_serial.ino new file mode 100644 index 0000000..59197af --- /dev/null +++ b/simple_serial/simple_serial.ino @@ -0,0 +1,18 @@ +int incomingByte = 0; // for incoming serial data + +void setup() { + Serial.begin(112500); +} + +void loop() { + // put your main code here, to run repeatedly: + // reply only when you receive data: + if (Serial.available() > 0) { + // read the incoming byte: + incomingByte = Serial.read(); + + // say what you got: + Serial.print("I received: "); + Serial.println(incomingByte, DEC); + } +} diff --git a/js/respiration_math.js b/static/js/respiration_math.js similarity index 100% rename from js/respiration_math.js rename to static/js/respiration_math.js diff --git a/breath_plot.html b/templates/breath_plot.html similarity index 99% rename from breath_plot.html rename to templates/breath_plot.html index a5ac628..3cc59a7 100644 --- a/breath_plot.html +++ b/templates/breath_plot.html @@ -28,7 +28,7 @@ Breath Plot: COVID-19 Respiration Analysis Software <!-- Load plotly.js into the DOM --> <script src='https://cdn.plot.ly/plotly-latest.min.js'></script> - <script src='./js/respiration_math.js'></script> + <script src='./static/js/respiration_math.js'></script> <title>Public Invention Respiration Analysis</title> @@ -1470,10 +1470,12 @@ $( document ).ready(function() { // CONTROL PANEL INIT START $("#control_area_button").click(function(event) { - alert('Starting ventilator (not really)'); + //alert('Starting ventilator (not really)'); // Send a command to a connected device via serial port + var rr = $("#control-rr").val(); + console.log("rr: " + rr); /*var lh = "http://localhost:8080"; alert('making ajax call'); $.ajax({url: lh+"/README.md", -- GitLab