moved images to appropriate folder
added image hash
This commit is contained in:
parent
70c4de1a30
commit
4e2311df7d
7 changed files with 39 additions and 3 deletions
|
@ -81,6 +81,9 @@ Data should be sent and received via MQTT to an ESP32. The Pi acts as a sensor g
|
||||||
- `main.py`
|
- `main.py`
|
||||||
The main file for the project
|
The main file for the project
|
||||||
|
|
||||||
|
- `The Graphs`
|
||||||
|
https://ron.sh/creating-real-time-charts-with-fastapi/
|
||||||
|
|
||||||
### Git Help
|
### Git Help
|
||||||
|
|
||||||

|

|
||||||
|
|
BIN
images/gitHelp.png
Normal file
BIN
images/gitHelp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 521 KiB |
BIN
images/htmlHelp.png
Normal file
BIN
images/htmlHelp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 701 KiB |
BIN
images/mdHelp.png
Normal file
BIN
images/mdHelp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 KiB |
12
main.py
12
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
|
|
@ -11,6 +11,7 @@ from datetime import datetime
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
import json
|
import json
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
import hashlib
|
||||||
matplotlib.use('Agg')
|
matplotlib.use('Agg')
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ class Sensor:
|
||||||
self.values: list = value
|
self.values: list = value
|
||||||
self.timeonly: list = []
|
self.timeonly: list = []
|
||||||
self.timedate: list = []
|
self.timedate: list = []
|
||||||
|
self.hash = hashlib.sha256(repr(ts).encode()).hexdigest()
|
||||||
for i in ts:
|
for i in ts:
|
||||||
# print(i)
|
# print(i)
|
||||||
self.timeonly.append(datetime.fromtimestamp(int(i)).strftime("%H:%M.%S"))
|
self.timeonly.append(datetime.fromtimestamp(int(i)).strftime("%H:%M.%S"))
|
||||||
|
@ -108,6 +110,9 @@ class Sensor:
|
||||||
plt.close()
|
plt.close()
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def getHash(self):
|
||||||
|
return self.hash
|
||||||
|
|
||||||
|
|
||||||
readJson()
|
readJson()
|
||||||
|
|
||||||
|
@ -122,6 +127,10 @@ app = Flask(__name__)
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html", data=sensors)
|
return render_template("index.html", data=sensors)
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def reload_data():
|
||||||
|
readJson()
|
||||||
|
print("hello")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
color: white;
|
color: white;
|
||||||
background: #1c1c1c;
|
background: #1c1c1c;
|
||||||
|
<!-- margin: 0; -->
|
||||||
|
<!-- padding: 0; -->
|
||||||
|
<!-- box-sizing: border-box; -->
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
display: flex; /* Enable flexbox */
|
display: flex; /* Enable flexbox */
|
||||||
|
@ -41,18 +44,26 @@
|
||||||
background-color: #C4FA05; /* Background color for the boxes */
|
background-color: #C4FA05; /* Background color for the boxes */
|
||||||
justify-content: left; /* Center text horizontally */
|
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 */
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class = "container">
|
<div class = "container">
|
||||||
<div class = "txtbox">
|
<div class = "txtbox" style="text-align: center; margin: auto;">
|
||||||
<h1>Sensor Readings</h1>
|
<h1>Sensor Readings</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h2>{% for sensor in data.items() %}</h2>
|
<h2>{% for sensor in data.items() %}</h2>
|
||||||
<hr>
|
<hr>
|
||||||
<h2>{{ sensor[1].getId() }}[{{ sensor[1].getType() }}]</h2>
|
<h2>{{ sensor[1].getId() }}[{{ sensor[1].getType() }}]</h2>
|
||||||
<h3>{{ sensor[1].renderPlot() }}</h3>
|
|
||||||
<div class = "container">
|
<div class = "container">
|
||||||
<div class = "txtbox">
|
<div class = "txtbox">
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -63,11 +74,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div class = "imgbox">
|
<div class = "imgbox">
|
||||||
<img
|
<img
|
||||||
src="{{ url_for('static', filename='plots/' + sensor[1].getId() + '.png') }}"
|
src="{{ url_for('static', filename= sensor[1].renderPlot()) }}"
|
||||||
alt="Graph"
|
alt="Graph"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<sub style="text-align: right; float: right;"> {{ sensor[1].getHash() }} </sub>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue