Skip to content

TeslaUSB v2.0 — Core Requirements & Implementation Plan #42

@mphacker

Description

@mphacker

TeslaUSB v2.0 — Core Requirements & Implementation Plan

Comprehensive plan addressing boot performance, UI consistency, video management, cloud sync, WiFi reliability, and crash protection for the TeslaUSB Raspberry Pi Zero 2 W USB gadget.

Supersedes #35 (cloud-only scope expanded to full platform requirements).


Core Principles

  1. USB presentation is Refactored #1 boot priority — Tesla sees the drive within ~3 seconds
  2. Power-loss resilient — atomic writes, fsynced state, SQLite WAL mode everywhere
  3. Memory-efficient — 512MB RAM budget, no thumbnails, one-file-at-a-time sync
  4. Always connected — WiFi reconnects aggressively, AP fallback, SSH always available
  5. Never lose data — IMG files protected, RecentClips archived every 5 minutes

Phase 1: Safety & Stability Foundation

  • SSH Safety Guard — systemd drop-in prevents sshd from being stopped; safe-mode boot detection (3+ reboots in 10min → skip TeslaUSB services, start SSH + AP only)
  • IMG File Protectionis_protected_file() guard in all delete/cleanup paths; refuse deletion of *.img files in GADGET_DIR
  • Service Restart Limits — Audit all systemd services for StartLimitBurst/StartLimitIntervalSec; ensure gadget_web never takes down SSH

Phase 2: Boot Optimization (CRITICAL)

  • Restructure Boot Sequencepresent_usb_on_boot.service calls present_usb.sh directly (no cleanup wrapper); create teslausb-deferred-tasks.service for background cleanup/chime/index/sync
  • Optimize present_usb.sh — Move RO mounts after UDC bind, reduce sleeps, target <3s to UDC bind
  • Boot fsck Optimization — Parallelize fsck for all images; async if >2s

Phase 3: UI/UX Consistency

  • Remove Legacy Videos Page — Delete videos.html, redirect /videos to map page, keep stream/download/delete APIs
  • Remove Thumbnail System — Remove generation code, API endpoints, client-side queue JS, cache dirs (saves RAM + complexity)
  • Template Audit — All templates: emoji→Lucide SVG, hex→CSS tokens, button consistency, touch targets (44px), dark mode
  • Button Component Standardization — Shared CSS button classes (primary/secondary/danger/ghost) applied across all templates

Phase 4: Video Panel Redesign (Map Integration)

  • Recent Events Slide-out Panel — Panel on map page with "Recent Events" tab: trips with events (no play btn, show on map), sentry clips (with play btn). All sources: USB + ArchivedClips
  • All Clips Tab — Unified list of every clip; geo-aware play button logic (map if location, list button if not); infinite scroll; search/filter
  • Map Panel Integration — Trip routes with event bubbles, clicking bubble opens player at timestamp, ArchivedClips included
  • Video Panel API Endpoints — New /api/recent-events, /api/all-clips; enhance /api/trips with event summaries

Phase 5: Indexing & Archive Improvements

  • Index All Sources on WiFirefresh_cloud_token.py indexes ArchivedClips + all USB folders; add mapping.archive_indexing config
  • Tighter RecentClips Timer — Change to 5-minute interval; run regardless of WiFi state; memory pressure checks
  • inotify File Watcherfile_watcher_service.py using watchdog library; monitor USB RO mount + ArchivedClips; queue new files for index + sync; fallback to 5-min polling

Phase 6: Cloud Sync Overhaul

  • Queue-Based Continuous Sync — Persistent SQLite queue; sync worker thread processes items one at a time; wakes on new items; pauses on WiFi disconnect
  • Configurable Sync Priority — event.json + SEI scoring; default: oldest events → oldest geo-trips → opt-in non-event. Config: cloud_archive.sync_non_event_videos: false
  • Synced File Tracking & Resume — Mark synced only after rclone confirm + fsync; detect partial uploads; resume or overwrite
  • Low-Impact Sync Enforcementnice -n 19 + ionice -c3; bandwidth limit; one file at a time; inter-file sleep; web UI stays responsive
  • Enhanced Sync Status Display — Current file, files remaining, bytes, ETA, queue status, archive-to-cloud position
  • Continuous Sync Until Done — Idle only when queue empty + no new files from inotify; resume after WiFi reconnect

Phase 7: WiFi Reliability

  • Always-Connect WiFi — Adaptive check interval (20s searching, 60s connected); explicit nmcli connection up after failures; verify concurrent AP+STA
  • WiFi Configuration Persistence — Verify NetworkManager picks up WiFi from OS install and web UI; survives power cycles
  • WiFi Connect Triggers — Verify dispatcher fires reliably; re-trigger sync on reconnect

Requirement Traceability

# Requirement Phase
1 USB drives presented ASAP during boot 2
2 UI/UX consistency across application 3
3 Optimized memory/CPU usage 1-7
4 Handle power cuts (vehicle environment) 1, 6
5 Stable, deterministic behavior 1, 2, 7
6 WiFi always connects to configured SSID 7
7 Auto-index on WiFi connect (all sources) 5
8 Recent events panel (trips on map, sentry with play) 4
9 All clips tab (geo-aware play buttons) 4
10 Auto cloud sync on WiFi connect 6
11 Sync status on cloud page 6
12 Archive-to-cloud queuing 6
13 Low-impact syncing (bandwidth/CPU/memory) 6
14 Keep syncing until queue empty 6
15 Configurable sync priority order 6
16 Track synced videos (no re-upload) 6
17 Resume partial uploads 6
18 Never overwrite/delete IMG files 1
19 Always keep trying WiFi 7
20 Never crash/reboot loop preventing SSH 1
21 Tighter RecentClips preservation (5-min) 5

Key Design Decisions

  • No standalone Videos page — all video browsing in map page slide-out panel
  • No thumbnail system — removed to save RAM and complexity
  • inotify + polling fallback for file watching (low memory, real-time detection)
  • event.json + SEI telemetry for sync priority scoring
  • ArchivedClips fully integrated — indexed, browsable, syncable
  • SSH always accessible — systemd protection + safe-mode boot detection
  • IMG files never deleted — software guards in all code paths

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions