firmware-ota (#2)

Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2026-03-03 22:47:03 -05:00
parent 9bce74e027
commit 0ec7f7f08a
21 changed files with 1065 additions and 255 deletions

View File

@@ -1,5 +1,5 @@
<script>
import { getSystemInfo, reboot } from "./lib/api.js";
import { getSystemInfo, reboot, getOTAStatus } from "./lib/api.js";
import OTAUpdate from "./lib/OTAUpdate.svelte";
/** @type {'loading' | 'ok' | 'error' | 'rebooting'} */
@@ -16,6 +16,12 @@
connection: "—",
});
let otaStatus = $state({
partitions: [],
active_partition: "—",
running_firmware_label: "—"
});
/** Format uptime seconds into human-readable string */
function formatUptime(seconds) {
const d = Math.floor(seconds / 86400);
@@ -37,9 +43,11 @@
return `${bytes} B`;
}
async function fetchInfo() {
async function fetchAll() {
try {
systemInfo = await getSystemInfo();
const [sys, ota] = await Promise.all([getSystemInfo(), getOTAStatus()]);
systemInfo = sys;
otaStatus = ota;
status = "ok";
errorMsg = "";
} catch (e) {
@@ -62,7 +70,10 @@
}
$effect(() => {
fetchInfo();
fetchAll();
// Poll for status updates every 5 seconds
const interval = setInterval(fetchAll, 5000);
return () => clearInterval(interval);
});
// Resilient recovery polling: Only poll when we are waiting for a reboot
@@ -93,120 +104,156 @@
]);
</script>
<main class="min-h-screen bg-bg-primary flex items-center justify-center p-4">
<div class="w-full max-w-xl space-y-4">
<main class="min-h-screen bg-bg-primary p-4 md:p-8 flex flex-col items-center">
<div class="w-full max-w-6xl space-y-8">
<!-- Header -->
<div class="text-center mb-6">
<h1 class="text-2xl font-bold text-accent">Calendink Provider 🚀</h1>
<div class="text-center">
<h1 class="text-2xl font-bold text-accent">Calendink Provider 🚀🚀👑</h1>
<p class="text-text-secondary text-sm">ESP32-S3 System Dashboard v{__APP_VERSION__}</p>
</div>
<!-- Status Badge -->
<div class="flex justify-center">
{#if status === "loading"}
<div
class="inline-flex items-center gap-2 bg-accent/10 border border-accent/20 rounded-full px-4 py-2 text-sm text-accent"
>
<span class="w-2 h-2 rounded-full bg-accent animate-pulse"></span>
<span>Connecting to ESP32...</span>
</div>
{:else if status === "ok"}
<div
class="inline-flex items-center gap-2 bg-success/10 border border-success/20 rounded-full px-4 py-2 text-sm text-success"
>
<span class="w-2 h-2 rounded-full bg-success animate-pulse"></span>
<span>Connected</span>
</div>
{:else if status === "rebooting"}
<div
class="inline-flex items-center gap-2 bg-amber-500/10 border border-amber-500/20 rounded-full px-4 py-2 text-sm text-amber-400"
>
<span class="w-2 h-2 rounded-full bg-amber-400 animate-pulse"></span>
<span>Rebooting...</span>
</div>
{:else}
<div
class="inline-flex items-center gap-2 bg-danger/10 border border-danger/20 rounded-full px-4 py-2 text-sm text-danger"
>
<span class="w-2 h-2 rounded-full bg-danger"></span>
<span>Offline — {errorMsg}</span>
</div>
{/if}
</div>
<!-- System Info Card -->
<div class="bg-bg-card border border-border rounded-xl overflow-hidden">
<div class="px-5 py-3 border-b border-border">
<h2
class="text-sm font-semibold text-text-primary uppercase tracking-wider"
>
System Info
</h2>
</div>
<div class="divide-y divide-border">
{#each infoItems as item}
<div
class="flex items-center justify-between px-5 py-3 hover:bg-bg-card-hover transition-colors"
>
<div class="flex items-center gap-3">
<span class="text-base">{item.icon}</span>
<span class="text-sm text-text-secondary">{item.label}</span>
</div>
<span class="text-sm font-mono text-text-primary">
{#if status === "loading"}
<span
class="inline-block w-16 h-4 bg-border rounded animate-pulse"
></span>
{:else}
{item.value}
{/if}
</span>
<!-- Status Badge -->
<div class="flex justify-center mt-4">
{#if status === "loading"}
<div class="inline-flex items-center gap-2 bg-accent/10 border border-accent/20 rounded-full px-4 py-1.5 text-xs text-accent">
<span class="w-2 h-2 rounded-full bg-accent animate-pulse"></span>
<span>Connecting...</span>
</div>
{/each}
{:else if status === "ok"}
<div class="inline-flex items-center gap-2 bg-success/10 border border-success/20 rounded-full px-4 py-1.5 text-xs text-success">
<span class="w-2 h-2 rounded-full bg-success animate-pulse"></span>
<span>Connected</span>
</div>
{:else if status === "rebooting"}
<div class="inline-flex items-center gap-2 bg-amber-500/10 border border-amber-500/20 rounded-full px-4 py-1.5 text-xs text-amber-400">
<span class="w-2 h-2 rounded-full bg-amber-400 animate-pulse"></span>
<span>Rebooting...</span>
</div>
{:else}
<div class="inline-flex items-center gap-2 bg-danger/10 border border-danger/20 rounded-full px-4 py-1.5 text-xs text-danger">
<span class="w-2 h-2 rounded-full bg-danger"></span>
<span>Offline — {errorMsg}</span>
</div>
{/if}
</div>
</div>
<!-- Device Control Section (Reboot) -->
<div class="bg-bg-card border border-border rounded-xl p-5">
<div class="flex items-center justify-between">
<div>
<h2 class="text-sm font-semibold text-text-primary uppercase tracking-wider">
Device Control
</h2>
<p class="text-xs text-text-secondary mt-1">
Restart the ESP32 microcontroller
</p>
<!-- 2-Column Grid Layout -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-8 items-start">
<!-- Left Column: System Info & Partition Table -->
<div class="space-y-8">
<!-- System Info Card -->
<div class="bg-bg-card border border-border rounded-xl overflow-hidden shadow-xl">
<div class="px-5 py-3 border-b border-border">
<h2 class="text-sm font-semibold text-text-primary uppercase tracking-wider">
System Info
</h2>
</div>
<div class="divide-y divide-border">
{#each infoItems as item}
<div class="flex items-center justify-between px-5 py-3 hover:bg-bg-card-hover transition-colors">
<div class="flex items-center gap-3">
<span class="text-base">{item.icon}</span>
<span class="text-sm text-text-secondary">{item.label}</span>
</div>
<span class="text-sm font-mono text-text-primary">
{#if status === "loading"}
<span class="inline-block w-16 h-4 bg-border rounded animate-pulse"></span>
{:else}
{item.value}
{/if}
</span>
</div>
{/each}
</div>
</div>
<button
onclick={() => (showRebootConfirm = true)}
disabled={status === "rebooting" || status === "loading"}
class="px-4 py-2 text-sm font-medium rounded-lg transition-colors
bg-danger/10 text-danger border border-danger/20
hover:bg-danger/20 hover:border-danger/30
disabled:opacity-40 disabled:cursor-not-allowed"
>
Reboot
</button>
</div>
</div>
<!-- Frontend Info & OTA Section -->
<OTAUpdate onReboot={() => (status = "rebooting")} />
<!-- Partition Table Card -->
<div class="bg-bg-card border border-border rounded-xl overflow-hidden shadow-xl">
<div class="px-5 py-3 border-b border-border flex items-center justify-between">
<h2 class="text-sm font-semibold text-text-primary uppercase tracking-wider">
Partition Table
</h2>
<span class="text-[10px] text-text-secondary font-mono">Flash: 16MB</span>
</div>
<div class="divide-y divide-border">
{#if status === "loading"}
<div class="p-5 text-center text-xs text-text-secondary animate-pulse">Loading memory layout...</div>
{:else}
{#each otaStatus.partitions as part}
<div class="px-5 py-2.5 flex items-center justify-between hover:bg-bg-card-hover transition-colors">
<div class="flex flex-col">
<div class="flex items-center gap-2">
<span class="text-[11px] font-mono font-bold {part.label === otaStatus.active_partition || part.label === otaStatus.running_firmware_label ? 'text-accent' : 'text-text-primary'}">
{part.label}
</span>
{#if part.label === otaStatus.active_partition || part.label === otaStatus.running_firmware_label}
<span class="text-[8px] bg-accent/20 text-accent px-1 rounded uppercase tracking-tighter">Active</span>
{/if}
</div>
<span class="text-[9px] text-text-secondary uppercase">
Type {part.type} / Sub {part.subtype}
</span>
</div>
<div class="text-right flex flex-col items-end">
<div class="text-[11px] font-mono text-text-primary">{formatBytes(part.size)}</div>
<div class="flex items-center gap-1.5 mt-0.5">
{#if part.app_version}
<span class="text-[9px] text-accent font-bold">v{part.app_version}</span>
{/if}
{#if part.free !== undefined}
<span class="text-[9px] {part.free > 1024 ? 'text-success' : 'text-text-secondary'} font-bold">
{formatBytes(part.free)} free
</span>
{/if}
</div>
</div>
</div>
{/each}
{/if}
</div>
</div>
</div>
<!-- Right Column: Device Control & OTA Updates -->
<div class="space-y-8">
<!-- Device Control Card -->
<div class="bg-bg-card border border-border rounded-xl p-5 shadow-xl">
<div class="flex items-center justify-between">
<div>
<h2 class="text-sm font-semibold text-text-primary uppercase tracking-wider">
Device Control
</h2>
<p class="text-xs text-text-secondary mt-1">
Restart the ESP32 microcontroller
</p>
</div>
<button
onclick={() => (showRebootConfirm = true)}
disabled={status === "rebooting" || status === "loading"}
class="px-4 py-2 text-sm font-medium rounded-lg transition-colors
bg-danger/10 text-danger border border-danger/20
hover:bg-danger/20 hover:border-danger/30
disabled:opacity-40 disabled:cursor-not-allowed"
>
Reboot
</button>
</div>
</div>
<!-- Updates & Maintenance Card -->
<OTAUpdate onReboot={() => { status = "rebooting"; isRecovering = true; }} />
</div>
</div>
<!-- Reboot Confirmation Modal -->
{#if showRebootConfirm}
<div
class="fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4"
>
<div
class="bg-bg-card border border-border rounded-xl p-6 max-w-sm w-full space-y-4"
>
<h3 class="text-lg font-semibold text-text-primary">
Confirm Reboot
</h3>
<div class="fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4 backdrop-blur-sm">
<div class="bg-bg-card border border-border rounded-xl p-6 max-w-sm w-full space-y-4 shadow-2xl">
<h3 class="text-lg font-semibold text-text-primary">Confirm Reboot</h3>
<p class="text-sm text-text-secondary">
Are you sure you want to reboot the ESP32? The device will be
temporarily unavailable.
Are you sure you want to reboot the ESP32? The device will be temporarily unavailable.
</p>
<div class="flex gap-3 justify-end">
<button
@@ -217,7 +264,7 @@
</button>
<button
onclick={handleReboot}
class="px-4 py-2 text-sm font-medium rounded-lg bg-danger text-white hover:bg-danger-hover transition-colors"
class="px-4 py-2 text-sm font-medium rounded-lg bg-danger text-white hover:bg-danger-hover transition-colors shadow-lg shadow-danger/20"
>
Reboot Now
</button>