mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-07-06 18:01:05 +02:00
i think its working now
This commit is contained in:
@@ -5,9 +5,6 @@ from meshview import mqtt_reader
|
|||||||
from meshview import database
|
from meshview import database
|
||||||
from meshview import mqtt_store
|
from meshview import mqtt_store
|
||||||
from meshview import web
|
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):
|
async def main(config):
|
||||||
database.init_database(config["database"]["connection_string"])
|
database.init_database(config["database"]["connection_string"])
|
||||||
|
|
||||||
await database.create_tables()
|
#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"])
|
|
||||||
|
|
||||||
# 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:
|
async with asyncio.TaskGroup() as tg:
|
||||||
tg.create_task(
|
tg.create_task(
|
||||||
web.run_server(
|
web.run_server(
|
||||||
|
|||||||
+1
-1
@@ -318,6 +318,6 @@ async def get_site_config():
|
|||||||
async with database.async_session() as session:
|
async with database.async_session() as session:
|
||||||
query = select(SiteConfig)
|
query = select(SiteConfig)
|
||||||
result = await session.execute(query)
|
result = await session.execute(query)
|
||||||
|
#print(result.scalar())
|
||||||
site_config = result.scalars().all()[-1]
|
site_config = result.scalars().all()[-1]
|
||||||
|
|
||||||
return site_config
|
return site_config
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="row chat-packet">
|
<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" 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"><a href="/packet/{{packet.id}}">✉️</a> {{packet.from_node.channel}}</span>
|
<!-- <span class="col-1 timestamp"></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-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-6 message">{{packet.payload}}</span>
|
<span class="col message" style="text-align: right;">{{packet.payload}}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -41,18 +41,28 @@
|
|||||||
<!-- Node Information Card -->
|
<!-- Node Information Card -->
|
||||||
<div class="card" id="node_info">
|
<div class="card" id="node_info">
|
||||||
{% if node %}
|
{% if node %}
|
||||||
<div class="card-header">
|
<div class="card-header" id="node_color">
|
||||||
{{node.long_name}} ({{node.node_id|node_id_to_hex}})
|
<strong style="margin-right: 1em ; margin-left: 1em; font-size: x-large;">{{node.short_name}}</strong>
|
||||||
</div>
|
<p style="margin-bottom: 0px; font-size: large; font-weight: bold;">{{node.long_name}}</p>
|
||||||
<div class="card-body">
|
</div>
|
||||||
<dl>
|
<div class="card-body">
|
||||||
<dt>ShortName</dt>
|
<dl >
|
||||||
<dd>{{node.short_name}}</dd>
|
{% if trace %}
|
||||||
<dt>HW Model</dt>
|
<dd id="map"></dd>
|
||||||
<dd>{{node.hw_model}}</dd>
|
{% endif %}
|
||||||
<dt>Role</dt>
|
<dt>NodeID</dt>
|
||||||
<dd>{{node.role}}</dd>
|
<dd>{{node.node_id|node_id_to_hex}}</dd>
|
||||||
</dl>
|
<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>
|
<a href="/top?node_id={{node.node_id}}" >Get node traffic totals</a>
|
||||||
{% include "node_graphs.html" %}
|
{% include "node_graphs.html" %}
|
||||||
</div>
|
</div>
|
||||||
@@ -63,11 +73,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col mb-3">
|
|
||||||
<!-- Map Container -->
|
|
||||||
<div id="map"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -85,6 +90,29 @@
|
|||||||
</div>
|
</div>
|
||||||
</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 %}
|
{% if trace %}
|
||||||
<script>
|
<script>
|
||||||
var trace = {{ trace | tojson }}; // Load trace data into JavaScript
|
var trace = {{ trace | tojson }}; // Load trace data into JavaScript
|
||||||
|
|||||||
+2
-2
@@ -191,7 +191,6 @@ def generate_response(request, body, raw_node_id="", node=None):
|
|||||||
raw_node_id=raw_node_id,
|
raw_node_id=raw_node_id,
|
||||||
node_html=Markup(body),
|
node_html=Markup(body),
|
||||||
node=node,
|
node=node,
|
||||||
site_config = await store.get_site_config(),
|
|
||||||
),
|
),
|
||||||
content_type="text/html",
|
content_type="text/html",
|
||||||
)
|
)
|
||||||
@@ -1190,7 +1189,7 @@ async def top(request):
|
|||||||
node_traffic = await store.get_node_traffic(int(node_id))
|
node_traffic = await store.get_node_traffic(int(node_id))
|
||||||
print(node_traffic)
|
print(node_traffic)
|
||||||
template = env.get_template("node_traffic.html") # Render a different template
|
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:
|
else:
|
||||||
# Otherwise, fetch top traffic nodes as usual
|
# Otherwise, fetch top traffic nodes as usual
|
||||||
top_nodes = await store.get_top_traffic_nodes()
|
top_nodes = await store.get_top_traffic_nodes()
|
||||||
@@ -1323,6 +1322,7 @@ async def nodegraph(request):
|
|||||||
text=template.render(
|
text=template.render(
|
||||||
nodes=nodes_with_edges,
|
nodes=nodes_with_edges,
|
||||||
edges=edges, # Pass edges with color info
|
edges=edges, # Pass edges with color info
|
||||||
|
site_config = await store.get_site_config(),
|
||||||
),
|
),
|
||||||
content_type="text/html",
|
content_type="text/html",
|
||||||
)
|
)
|
||||||
|
|||||||
+15
-1
@@ -4,6 +4,7 @@ import configparser
|
|||||||
from meshview import mqtt_reader
|
from meshview import mqtt_reader
|
||||||
from meshview import mqtt_database
|
from meshview import mqtt_database
|
||||||
from meshview import mqtt_store
|
from meshview import mqtt_store
|
||||||
|
from meshview import models
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
@@ -23,12 +24,25 @@ async def main(config):
|
|||||||
if config["mqtt"]["password"] != "":
|
if config["mqtt"]["password"] != "":
|
||||||
mqtt_passwd: str = config["mqtt"]["password"]
|
mqtt_passwd: str = config["mqtt"]["password"]
|
||||||
mqtt_topics = json.loads(config["mqtt"]["topics"])
|
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:
|
async with asyncio.TaskGroup() as tg:
|
||||||
tg.create_task(
|
tg.create_task(
|
||||||
load_database_from_mqtt(config["mqtt"]["server"], int(config["mqtt"]["port"]), mqtt_topics, mqtt_user, mqtt_passwd)
|
load_database_from_mqtt(config["mqtt"]["server"], int(config["mqtt"]["port"]), mqtt_topics, mqtt_user, mqtt_passwd)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_config(file_path):
|
def load_config(file_path):
|
||||||
"""Load configuration from an INI-style text file."""
|
"""Load configuration from an INI-style text file."""
|
||||||
|
|||||||
Reference in New Issue
Block a user