mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
Add a power graph.
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
<dt>hw model</dt>
|
||||
<dd>{{node.hw_model}}</dd>
|
||||
</dl>
|
||||
<a href="/graph/power/{{node_id}}"><img src="/graph/power/{{node_id}}" height="200em" width="200em"/></a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="card-body">
|
||||
@@ -50,7 +51,6 @@
|
||||
<div class="col mb-3">
|
||||
<div id="map"/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import io
|
||||
|
||||
from dataclasses import dataclass
|
||||
import datetime
|
||||
@@ -6,6 +7,8 @@ from aiohttp_sse import sse_response
|
||||
import ssl
|
||||
import re
|
||||
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
from aiohttp import web
|
||||
from markupsafe import Markup
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
@@ -400,6 +403,37 @@ async def packet(request):
|
||||
)
|
||||
|
||||
|
||||
@routes.get("/graph/power/{node_id}")
|
||||
async def graph_power(request):
|
||||
date = []
|
||||
battery = []
|
||||
voltage = []
|
||||
for p in await store.get_packets_from(int(request.match_info['node_id']), PortNum.TELEMETRY_APP):
|
||||
_, payload = decode_payload.decode(p)
|
||||
if not payload.HasField('device_metrics'):
|
||||
continue
|
||||
date.append(datetime.datetime.fromtimestamp(payload.time))
|
||||
battery.append(payload.device_metrics.battery_level)
|
||||
voltage.append(payload.device_metrics.voltage)
|
||||
|
||||
fig, ax1 = plt.subplots(figsize=(10, 10))
|
||||
ax1.set_xlabel('time')
|
||||
ax1.set_ylabel('battery level', color='tab:blue')
|
||||
ax2 = ax1.twinx()
|
||||
ax2.set_ylabel('voltage', color='tab:red')
|
||||
sns.lineplot(x=date, y=battery, ax=ax1, color='tab:blue')
|
||||
sns.lineplot(x=date, y=voltage, ax=ax2, color='tab:red')
|
||||
|
||||
png = io.BytesIO()
|
||||
plt.savefig(png, dpi=100)
|
||||
|
||||
return web.Response(
|
||||
body=png.getvalue(),
|
||||
content_type="image/png",
|
||||
)
|
||||
|
||||
|
||||
|
||||
async def run_server(bind, port, tls_cert):
|
||||
app = web.Application()
|
||||
app.add_routes(routes)
|
||||
|
||||
@@ -8,3 +8,4 @@ aiodns
|
||||
Jinja2
|
||||
aiohttp-sse
|
||||
asyncpg
|
||||
seaborn
|
||||
|
||||
Reference in New Issue
Block a user