diff --git a/README.md b/README.md index edba6a3..70f7052 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,9 @@ Data should be sent and received via MQTT to an ESP32. The Pi acts as a sensor g - `main.py` The main file for the project +- `The Graphs` + https://ron.sh/creating-real-time-charts-with-fastapi/ + ### Git Help ![A Git Cheatsheet](gitHelp.png "Git Cheatsheet") diff --git a/images/gitHelp.png b/images/gitHelp.png new file mode 100644 index 0000000..50dc28d Binary files /dev/null and b/images/gitHelp.png differ diff --git a/images/htmlHelp.png b/images/htmlHelp.png new file mode 100644 index 0000000..de7dfca Binary files /dev/null and b/images/htmlHelp.png differ diff --git a/images/mdHelp.png b/images/mdHelp.png new file mode 100644 index 0000000..82c5637 Binary files /dev/null and b/images/mdHelp.png differ diff --git a/main.py b/main.py index e69de29..e3e8151 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,12 @@ +# Copyright 2025 Kieler, Chiara +# +# Licensed under the AGPLv3.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.gnu.org/licenses/ + +# What this file should do? It should: +# 1. Start all the Sensors +# 2. Start the Webserver +# 3. Somehow transfer data from the Sensors to the Webserver diff --git a/webserver/server.py b/webserver/server.py index 1de45f9..b60be26 100644 --- a/webserver/server.py +++ b/webserver/server.py @@ -11,6 +11,7 @@ from datetime import datetime from flask import Flask, render_template import json import matplotlib +import hashlib matplotlib.use('Agg') import matplotlib.pyplot as plt @@ -45,6 +46,7 @@ class Sensor: self.values: list = value self.timeonly: list = [] self.timedate: list = [] + self.hash = hashlib.sha256(repr(ts).encode()).hexdigest() for i in ts: # print(i) self.timeonly.append(datetime.fromtimestamp(int(i)).strftime("%H:%M.%S")) @@ -108,6 +110,9 @@ class Sensor: plt.close() return path + def getHash(self): + return self.hash + readJson() @@ -122,6 +127,10 @@ app = Flask(__name__) def index(): return render_template("index.html", data=sensors) +@app.before_request +def reload_data(): + readJson() + print("hello") if __name__ == "__main__": app.run(debug=True) diff --git a/webserver/templates/index.html b/webserver/templates/index.html index def82e5..106707f 100644 --- a/webserver/templates/index.html +++ b/webserver/templates/index.html @@ -27,6 +27,9 @@ font-size: 18px; color: white; background: #1c1c1c; + + + } .container { display: flex; /* Enable flexbox */ @@ -41,18 +44,26 @@ background-color: #C4FA05; /* Background color for the boxes */ justify-content: left; /* Center text horizontally */ } + .txtbox h1 { + margin: 0; + padding: 0.5em 0; /* optional: add some vertical padding */ + } + .txtbox h2 { + margin: 0; + padding: 0em 0; /* optional: add some vertical padding */ + } +
-
+

Sensor Readings

{% for sensor in data.items() %}


{{ sensor[1].getId() }}[{{ sensor[1].getType() }}]

-

{{ sensor[1].renderPlot() }}

    @@ -63,11 +74,12 @@
Graph
+ {{ sensor[1].getHash() }} {% endfor %}