i think its working now

This commit is contained in:
madeofstown
2025-03-07 22:06:16 -08:00
parent 10c1bea76f
commit 93c1185447
6 changed files with 68 additions and 47 deletions

23
main.py
View File

@@ -5,9 +5,6 @@ from meshview import mqtt_reader
from meshview import database
from meshview import mqtt_store
from meshview import web
from meshview import http
from meshview import models
import json
@@ -19,26 +16,8 @@ async def load_database_from_mqtt(mqtt_server: str , mqtt_port: int, topic: list
async def main(config):
database.init_database(config["database"]["connection_string"])
await database.create_tables()
mqtt_user = None
mqtt_passwd = None
if config["mqtt"]["username"] != "":
mqtt_user: str = config["mqtt"]["username"]
if config["mqtt"]["password"] != "":
mqtt_passwd: str = config["mqtt"]["password"]
mqtt_topics = json.loads(config["mqtt"]["topics"])
#await database.create_tables()
# Create database with site configuration
async with database.async_session() as session:
site_config = models.SiteConfig(
site_domain = config["site"]["domain"],
site_title = config["site"]["title"],
site_message = config["site"]["message"]
)
session.add(site_config)
# print("Site configuration loaded to database")
async with asyncio.TaskGroup() as tg:
tg.create_task(
web.run_server(

View File

@@ -318,6 +318,6 @@ async def get_site_config():
async with database.async_session() as session:
query = select(SiteConfig)
result = await session.execute(query)
#print(result.scalar())
site_config = result.scalars().all()[-1]
return site_config

View File

@@ -1,6 +1,6 @@
<div class="row chat-packet">
<span class="col-2 timestamp">{{packet.import_time.strftime('%-I:%M:%S %p - %d-%m-%Y')}} </span>
<span class="col-1 timestamp"><a href="/packet/{{packet.id}}">✉️</a> {{packet.from_node.channel}}</span>
<span class="col-2 username"><a href="/packet_list/{{packet.from_node_id}}">{{packet.from_node.long_name or (packet.from_node_id | node_id_to_hex) }}</a></span>
<span class="col-6 message">{{packet.payload}}</span>
<span class="col-1 timestamp" style="font-size: smaller;"><a href="/packet/{{packet.id}}">✉️</a> {{packet.from_node.channel}}<div>{{packet.import_time.strftime('%-I:%M:%S %p - %d-%m-%Y')}}</div></span>
<!-- <span class="col-1 timestamp"></span> -->
<span class="col-4 username" style="text-align: center;"><a href="/packet_list/{{packet.from_node_id}}">{{packet.from_node.long_name or (packet.from_node_id | node_id_to_hex) }}</a></span>
<span class="col message" style="text-align: right;">{{packet.payload}}</span>
</div>

View File

@@ -41,18 +41,28 @@
<!-- Node Information Card -->
<div class="card" id="node_info">
{% if node %}
<div class="card-header">
{{node.long_name}} ({{node.node_id|node_id_to_hex}})
</div>
<div class="card-body">
<dl>
<dt>ShortName</dt>
<dd>{{node.short_name}}</dd>
<dt>HW Model</dt>
<dd>{{node.hw_model}}</dd>
<dt>Role</dt>
<dd>{{node.role}}</dd>
</dl>
<div class="card-header" id="node_color">
<strong style="margin-right: 1em ; margin-left: 1em; font-size: x-large;">{{node.short_name}}</strong>
<p style="margin-bottom: 0px; font-size: large; font-weight: bold;">{{node.long_name}}</p>
</div>
<div class="card-body">
<dl >
{% if trace %}
<dd id="map"></dd>
{% endif %}
<dt>NodeID</dt>
<dd>{{node.node_id|node_id_to_hex}}</dd>
<dt>Channel</dt>
<dd>{{node.channel}}</dd>
<dt>HW Model</dt>
<dd>{{node.hw_model}}</dd>
<dt>Role</dt>
<dd>{{node.role}}</dd>
{% if node.firmware %}
<dt>Firmware</dt>
<dd>{{node.firmware}}</dd>
{% endif %}
</dl>
<a href="/top?node_id={{node.node_id}}" >Get node traffic totals</a>
{% include "node_graphs.html" %}
</div>
@@ -63,11 +73,6 @@
{% endif %}
</div>
</div>
<div class="col mb-3">
<!-- Map Container -->
<div id="map"></div>
</div>
</div>
<div class="row">
@@ -85,6 +90,29 @@
</div>
</div>
<script>
var node_color = document.getElementById('node_color');
var node_id = '{{node.node_id | node_id_to_hex}}';
var color = node_id.slice(-6);
var bg_color = "#"+color;
node_color.style.background = bg_color;
var hex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(bg_color);
var text_color = [
parseInt(hex[1], 16),
parseInt(hex[2], 16),
parseInt(hex[3], 16),
];
const brightness = Math.round(((parseInt(text_color[0]) * 299) +
(parseInt(text_color[1]) * 587) +
(parseInt(text_color[2]) * 114)) / 1000);
if (brightness > 125) {
var textColor = '#212529'
node_color.style.color = textColor
}
</script>
{% if trace %}
<script>
var trace = {{ trace | tojson }}; // Load trace data into JavaScript

View File

@@ -191,7 +191,6 @@ def generate_response(request, body, raw_node_id="", node=None):
raw_node_id=raw_node_id,
node_html=Markup(body),
node=node,
site_config = await store.get_site_config(),
),
content_type="text/html",
)
@@ -1190,7 +1189,7 @@ async def top(request):
node_traffic = await store.get_node_traffic(int(node_id))
print(node_traffic)
template = env.get_template("node_traffic.html") # Render a different template
html_content = template.render(traffic=node_traffic, node_id=node_id)
html_content = template.render(traffic=node_traffic, node_id=node_id, site_config = await store.get_site_config())
else:
# Otherwise, fetch top traffic nodes as usual
top_nodes = await store.get_top_traffic_nodes()
@@ -1323,6 +1322,7 @@ async def nodegraph(request):
text=template.render(
nodes=nodes_with_edges,
edges=edges, # Pass edges with color info
site_config = await store.get_site_config(),
),
content_type="text/html",
)

View File

@@ -4,6 +4,7 @@ import configparser
from meshview import mqtt_reader
from meshview import mqtt_database
from meshview import mqtt_store
from meshview import models
import json
@@ -23,12 +24,25 @@ async def main(config):
if config["mqtt"]["password"] != "":
mqtt_passwd: str = config["mqtt"]["password"]
mqtt_topics = json.loads(config["mqtt"]["topics"])
# Create database with site configuration
async with mqtt_database.async_session() as session:
print(config["site"]["domain"])
site_config = models.SiteConfig(
site_domain = config["site"]["domain"],
site_title = config["site"]["title"],
site_message = config["site"]["message"]
)
session.add(site_config)
await session.commit()
# print("Site configuration loaded to database")
async with asyncio.TaskGroup() as tg:
tg.create_task(
load_database_from_mqtt(config["mqtt"]["server"], int(config["mqtt"]["port"]), mqtt_topics, mqtt_user, mqtt_passwd)
)
def load_config(file_path):
"""Load configuration from an INI-style text file."""