Closed a1eaiactaest closed 3 years ago
pi@raspberrypi:~/rere-api $ cat patch commit a848d1b9fd8a511b9f637957dd228b5ec75e6549 Author: Your Name <you@example.com> Date: Thu Oct 14 14:30:05 2021 +0200 adf diff --git a/connection.py b/connection.py index 103988f..5d5e105 100755 --- a/connection.py +++ b/connection.py @@ -13,8 +13,9 @@ import datetime import json class Connection: - def __init__(self, port, sim_mode): - self.sim_mode = sim_mode is not None + def __init__(self, port, sim_mode=False): + self.sim_mode = sim_mode is True + self.multiline_mode = sim_mode is not None self.port = port #/dev/tty* self.s = serial.Serial(port, 9600) self.s.reset_input_buffer() @@ -34,39 +35,36 @@ class Connection: def read(self, DEBUG=False): s_bytes = self.s.readline() try: - bytes_decoded = s_bytes[0:len(s_bytes)-3].decode("utf-8") + bytes_decoded = s_bytes[0:len(s_bytes)].decode("utf-8") + print(bytes_decoded) val = [float(v) for v in bytes_decoded.split(" ")] except ValueError as e: print(e) ct = str(datetime.datetime.now()) - try: - if self.sim_mode: - ret = {"time": ct, - "id": val[0], - "pres": val[1], - "gas_res": val[2], - "a_temp": val[3], - "a_hum": val[4], - "gd_temp": val[5], - "gd_hum": val[6], - "gps_lat": val[7], - "gps_lon": val[8], - "gps_angle": val[9], - "gps_speed": val[10]} - else: - ret = {"time": ct, - "id": val[0], - "pres": val[1], - "gas_res": val[2], - "a_temp": val[3], - "a_hum": val[4], - "gd_temp": val[5], - "gd_hum": val[6]} - if DEBUG: - print(ret) - except (IndexError, UnboundLocalError) as e: - print(e) - return self.read() + if self.sim_mode: + ret = {"time": ct, + "id": val[0], + "pres": val[1], + "gas_res": val[2], + "a_temp": val[3], + "a_hum": val[4], + "gd_temp": val[5], + "gd_hum": val[6], + "gps_lat": val[7], + "gps_lon": val[8], + "gps_angle": val[9], + "gps_speed": val[10]} + else: + ret = {"time": ct, + "id": val[0], + "pres": val[1], + "gas_res": val[2], + "a_temp": val[3], + "a_hum": val[4], + "gd_temp": val[5], + "gd_hum": val[6]} + if DEBUG: + print(ret) self.reset() return ret @@ -84,4 +82,4 @@ if __name__ == "__main__": while(1): time.sleep(1) c.read(True) - + c.s.reset_output_buffer() diff --git a/db.py b/db.py index a5d8065..043f47a 100755 --- a/db.py +++ b/db.py @@ -105,7 +105,7 @@ if __name__ == "__main__": if WRITE: while (1): #db.write_db(300) # every 5 minutes - db.write_db(10) + db.write_db(5) if READ: # usage: # n -> returns last n elements diff --git a/serve.py b/serve.py index 09cd8a0..1eb195b 100755 --- a/serve.py +++ b/serve.py @@ -39,6 +39,11 @@ def info(): print(e) return 400 + +@app.route('/stations') +def hello_stations(): + return render_template('stations.html') + @app.route('/data') def data(): return str(d.execute("SELECT * FROM serial_data")) diff --git a/static/index.js b/static/index.js index 66b7ef7..54ddfd7 100644 --- a/static/index.js +++ b/static/index.js @@ -16,5 +16,5 @@ function fetch_data(){ var intervalId = window.setInterval(function(){ fetch_data(); -}, 10000); +}, 5000); diff --git a/templates/notsim.html b/templates/notsim.html index 2647c77..ec0ec75 100644 --- a/templates/notsim.html +++ b/templates/notsim.html @@ -13,6 +13,7 @@ table, th, td { <script type="text/javascript" src="static/index.js"></script> <script type="text/javascript" src="static/notsim.js"></script> <h1>rere</h1> +<a href='/stations'>stations</a> <table id="datatable"> <tr style="width: 100%"> <th>time</th> diff --git a/templates/stations.html b/templates/stations.html new file mode 100644 index 0000000..88c2d26 --- /dev/null +++ b/templates/stations.html @@ -0,0 +1,10 @@ +<html> +<body> + <h1>Stations</h1> + <ul> + <li><a href=''>Station 3</a></li> + <li><a href=''>Station 5</a></li> + <li><a href=''>Station 11</a></li> + </ul> +</body> +</html>
patched in e6c360b84626e4ec4a31ab0e15a5bed1c7680629