docs: add project description and server setup instructions to README
This commit is contained in:
85
server/templates/base.html
Normal file
85
server/templates/base.html
Normal file
@@ -0,0 +1,85 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Demeter IoT{% endblock %}</title>
|
||||
<!-- Tailwind CSS + DaisyUI -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.12.14/dist/full.min.css" rel="stylesheet" type="text/css" />
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
</head>
|
||||
<body class="min-h-screen bg-base-200">
|
||||
|
||||
<!-- Navbar -->
|
||||
<div class="navbar bg-base-100 shadow-lg">
|
||||
<div class="flex-1">
|
||||
<a href="/dashboard" class="btn btn-ghost text-xl">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z" />
|
||||
</svg>
|
||||
Demeter
|
||||
</a>
|
||||
</div>
|
||||
<div class="flex-none gap-2">
|
||||
<a href="/dashboard" class="btn btn-ghost btn-sm">Dashboard</a>
|
||||
<a href="/api/status" class="btn btn-ghost btn-sm">Status</a>
|
||||
<a href="/docs" class="btn btn-ghost btn-sm">API Docs</a>
|
||||
|
||||
<!-- Theme toggle -->
|
||||
<label class="swap swap-rotate btn btn-ghost btn-circle">
|
||||
<input type="checkbox" id="themeToggle" />
|
||||
<!-- Sun icon -->
|
||||
<svg class="swap-off h-5 w-5 fill-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path d="M5.64,17l-.71.71a1,1,0,0,0,0,1.41,1,1,0,0,0,1.41,0l.71-.71A1,1,0,0,0,5.64,17ZM5,12a1,1,0,0,0-1-1H3a1,1,0,0,0,0,2H4A1,1,0,0,0,5,12Zm7-7a1,1,0,0,0,1-1V3a1,1,0,0,0-2,0V4A1,1,0,0,0,12,5ZM5.64,7.05a1,1,0,0,0,.7.29,1,1,0,0,0,.71-.29,1,1,0,0,0,0-1.41l-.71-.71A1,1,0,0,0,4.93,6.34Zm12,.29a1,1,0,0,0,.7-.29l.71-.71a1,1,0,1,0-1.41-1.41L17,5.64a1,1,0,0,0,0,1.41A1,1,0,0,0,17.66,7.34ZM21,11H20a1,1,0,0,0,0,2h1a1,1,0,0,0,0-2Zm-9,8a1,1,0,0,0-1,1v1a1,1,0,0,0,2,0V20A1,1,0,0,0,12,19ZM18.36,17A1,1,0,0,0,17,18.36l.71.71a1,1,0,0,0,1.41,0,1,1,0,0,0,0-1.41ZM12,6.5A5.5,5.5,0,1,0,17.5,12,5.51,5.51,0,0,0,12,6.5Zm0,9A3.5,3.5,0,1,1,15.5,12,3.5,3.5,0,0,1,12,15.5Z"/>
|
||||
</svg>
|
||||
<!-- Moon icon -->
|
||||
<svg class="swap-on h-5 w-5 fill-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path d="M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Z"/>
|
||||
</svg>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main content -->
|
||||
<main class="container mx-auto p-4 max-w-7xl">
|
||||
{% if error %}
|
||||
<div class="alert alert-error mb-4">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
<span>{{ error }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="footer footer-center p-4 bg-base-100 text-base-content mt-8">
|
||||
<div>
|
||||
<p>Demeter IoT Server v{{ server_version }} — CoAP + FastAPI</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Theme toggle script -->
|
||||
<script>
|
||||
const toggle = document.getElementById('themeToggle');
|
||||
const html = document.documentElement;
|
||||
|
||||
// Load saved theme
|
||||
const saved = localStorage.getItem('demeter-theme');
|
||||
if (saved === 'light') {
|
||||
html.setAttribute('data-theme', 'light');
|
||||
toggle.checked = true;
|
||||
}
|
||||
|
||||
toggle.addEventListener('change', () => {
|
||||
const theme = toggle.checked ? 'light' : 'dark';
|
||||
html.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('demeter-theme', theme);
|
||||
});
|
||||
</script>
|
||||
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
141
server/templates/dashboard.html
Normal file
141
server/templates/dashboard.html
Normal file
@@ -0,0 +1,141 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Dashboard — Demeter IoT{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- Stats bar -->
|
||||
<div class="stats shadow w-full mb-6 bg-base-100">
|
||||
<div class="stat">
|
||||
<div class="stat-title">Devices</div>
|
||||
<div class="stat-value" id="stat-total">{{ devices|length }}</div>
|
||||
<div class="stat-desc">Registered</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-title">Online</div>
|
||||
<div class="stat-value text-success" id="stat-online">{{ devices|selectattr('online')|list|length }}</div>
|
||||
<div class="stat-desc">Connected via CoAP</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-title">Subscriptions</div>
|
||||
<div class="stat-value text-info" id="stat-subs">{{ active_subscriptions }}</div>
|
||||
<div class="stat-desc">Active Observe</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Device cards grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4" id="devices-grid">
|
||||
{% for device in devices %}
|
||||
<div class="card bg-base-100 shadow-xl" id="card-{{ device.config.id }}">
|
||||
<div class="card-body">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="card-title text-lg">{{ device.config.name }}</h2>
|
||||
{% if device.online %}
|
||||
<div class="badge badge-success gap-1">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="currentColor" viewBox="0 0 24 24">
|
||||
<circle cx="12" cy="12" r="10"/>
|
||||
</svg>
|
||||
Online
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="badge badge-error gap-1">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="currentColor" viewBox="0 0 24 24">
|
||||
<circle cx="12" cy="12" r="10"/>
|
||||
</svg>
|
||||
Offline
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<p class="text-sm opacity-60">{{ device.config.ip }}:{{ device.config.port }} · {{ device.config.id }}</p>
|
||||
|
||||
<div class="divider my-1"></div>
|
||||
|
||||
<!-- Sensor readings -->
|
||||
{% if device.readings %}
|
||||
{% for uri, reading in device.readings.items() %}
|
||||
<div class="flex justify-between items-center py-1">
|
||||
<span class="text-sm font-medium">
|
||||
{% if 'soil_moisture' in uri %}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline text-success" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707" /></svg>
|
||||
Soil Moisture
|
||||
{% elif 'temperature' in uri %}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline text-warning" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" /></svg>
|
||||
Temperature
|
||||
{% elif 'water_level' in uri %}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline text-info" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z" /></svg>
|
||||
Water Level
|
||||
{% elif 'trigger' in uri %}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline text-error" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" /></svg>
|
||||
Trigger
|
||||
{% else %}
|
||||
{{ uri }}
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="font-mono text-lg {% if reading.stale %}opacity-40{% endif %}">
|
||||
{% if reading.value is not none %}
|
||||
{{ reading.value }}
|
||||
<span class="text-xs opacity-60">{{ reading.unit }}</span>
|
||||
{% else %}
|
||||
<span class="opacity-40">—</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{% if 'soil_moisture' in uri or 'water_level' in uri %}
|
||||
<progress
|
||||
class="progress {% if 'soil_moisture' in uri %}progress-success{% else %}progress-info{% endif %} w-full h-2"
|
||||
value="{{ reading.value or 0 }}"
|
||||
max="100">
|
||||
</progress>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="text-sm opacity-40 italic">No readings yet</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- Card actions -->
|
||||
<div class="card-actions justify-end mt-2">
|
||||
<a href="/dashboard/devices/{{ device.config.id }}" class="btn btn-sm btn-outline">Details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% if not devices %}
|
||||
<div class="col-span-full">
|
||||
<div class="alert alert-info">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current shrink-0 w-6 h-6">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
<span>No devices configured. Edit <code>config/devices.yaml</code> and restart the server.</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// Auto-refresh readings every 5 seconds
|
||||
setInterval(async () => {
|
||||
try {
|
||||
const resp = await fetch('/dashboard/api/readings');
|
||||
const data = await resp.json();
|
||||
|
||||
// Update online count
|
||||
let online = 0;
|
||||
for (const [id, dev] of Object.entries(data.devices)) {
|
||||
if (dev.online) online++;
|
||||
|
||||
// Update readings in each card
|
||||
// (Full re-render would be more robust, but this is POC)
|
||||
}
|
||||
|
||||
const statOnline = document.getElementById('stat-online');
|
||||
if (statOnline) statOnline.textContent = online;
|
||||
} catch (e) {
|
||||
console.warn('Auto-refresh failed:', e);
|
||||
}
|
||||
}, 5000);
|
||||
</script>
|
||||
{% endblock %}
|
||||
164
server/templates/device_detail.html
Normal file
164
server/templates/device_detail.html
Normal file
@@ -0,0 +1,164 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ device.config.name }} — Demeter IoT{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- Breadcrumb -->
|
||||
<div class="breadcrumbs text-sm mb-4">
|
||||
<ul>
|
||||
<li><a href="/dashboard">Dashboard</a></li>
|
||||
<li>{{ device.config.name }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Device header -->
|
||||
<div class="flex items-center gap-4 mb-6">
|
||||
<h1 class="text-3xl font-bold">{{ device.config.name }}</h1>
|
||||
{% if device.online %}
|
||||
<div class="badge badge-success badge-lg">Online</div>
|
||||
{% else %}
|
||||
<div class="badge badge-error badge-lg">Offline</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<!-- Device info card -->
|
||||
<div class="card bg-base-100 shadow-xl">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">Device Information</h2>
|
||||
<table class="table table-sm">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="font-medium opacity-60">Device ID</td>
|
||||
<td class="font-mono">{{ device.config.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-medium opacity-60">IP Address</td>
|
||||
<td class="font-mono">{{ device.config.ip }}:{{ device.config.port }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-medium opacity-60">Status</td>
|
||||
<td>
|
||||
{% if device.online %}
|
||||
<span class="text-success">Connected</span>
|
||||
{% else %}
|
||||
<span class="text-error">Disconnected</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-medium opacity-60">Resources</td>
|
||||
<td>{{ device.config.resources|length }} configured</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CoAP Bridge card -->
|
||||
<div class="card bg-base-100 shadow-xl">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">CoAP Bridge</h2>
|
||||
<p class="text-sm opacity-60 mb-2">Query the device directly via the HTTP-to-CoAP proxy.</p>
|
||||
|
||||
<div class="space-y-2">
|
||||
{% for resource in device.config.resources %}
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="font-mono text-sm">{{ resource.uri }}</span>
|
||||
<button class="btn btn-xs btn-outline"
|
||||
onclick="coapGet('{{ device.config.id }}', '{{ resource.uri }}')">
|
||||
GET
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="font-mono text-sm">device/info</span>
|
||||
<button class="btn btn-xs btn-outline"
|
||||
onclick="coapGet('{{ device.config.id }}', 'device/info')">
|
||||
GET
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Response display -->
|
||||
<div class="mt-4">
|
||||
<pre id="coap-response" class="bg-base-200 p-3 rounded-lg text-sm font-mono overflow-x-auto min-h-[60px] opacity-60">
|
||||
Click GET to query a resource...</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sensor readings -->
|
||||
<div class="card bg-base-100 shadow-xl mt-6">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">Sensor Readings</h2>
|
||||
|
||||
{% if device.readings %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Resource</th>
|
||||
<th>Value</th>
|
||||
<th>Unit</th>
|
||||
<th>Age</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for uri, reading in device.readings.items() %}
|
||||
<tr>
|
||||
<td class="font-mono text-sm">{{ uri }}</td>
|
||||
<td class="font-mono text-lg">
|
||||
{% if reading.value is not none %}
|
||||
{{ reading.value }}
|
||||
{% else %}
|
||||
<span class="opacity-40">—</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ reading.unit }}</td>
|
||||
<td>{{ reading.age_seconds()|round(0)|int }}s ago</td>
|
||||
<td>
|
||||
{% if reading.stale %}
|
||||
<div class="badge badge-warning badge-sm">Stale</div>
|
||||
{% else %}
|
||||
<div class="badge badge-success badge-sm">Fresh</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-sm opacity-40 italic">No readings received yet. The device may be offline or not yet subscribed.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
async function coapGet(deviceId, resource) {
|
||||
const pre = document.getElementById('coap-response');
|
||||
pre.textContent = 'Fetching...';
|
||||
pre.classList.remove('opacity-60');
|
||||
|
||||
try {
|
||||
const resp = await fetch(`/api/devices/${deviceId}/coap/${resource}`);
|
||||
const data = await resp.json();
|
||||
pre.textContent = JSON.stringify(data, null, 2);
|
||||
|
||||
if (!resp.ok) {
|
||||
pre.classList.add('text-error');
|
||||
} else {
|
||||
pre.classList.remove('text-error');
|
||||
}
|
||||
} catch (e) {
|
||||
pre.textContent = `Error: ${e.message}`;
|
||||
pre.classList.add('text-error');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user