feat(desktop): v0.4.2 - Integrated sensing server with real WebSocket data

- Bundle sensing-server binary in app resources (bin/sensing-server)
- Add find_server_binary() for multi-path binary discovery
- Connect Sensing page to real WebSocket endpoint (ws://localhost:8765/ws/sensing)
- Add DataSource type and source config for data source selection
- Default to simulate mode when no ESP32 hardware present
- Add ADR-055: Integrated Sensing Server architecture
- Add ADR-056: Complete RuView Desktop Capabilities Reference

Closes integration of sensing server as single-package distribution.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
Reuven 2026-03-10 00:08:31 -04:00
parent 3b37aaf460
commit e12749bf68
9 changed files with 687 additions and 75 deletions

View file

@ -0,0 +1,119 @@
# ADR-055: Integrated Sensing Server in Desktop App
## Status
Accepted
## Context
The RuView Desktop application (ADR-054) requires the WiFi sensing server to provide real-time CSI data, activity detection, and vital signs monitoring. Currently, the sensing server is a separate binary (`wifi-densepose-sensing-server`) that must be installed separately and found in the system PATH.
This creates several problems:
1. **Distribution complexity**: Users must install two binaries
2. **Path issues**: Binary may not be in PATH, causing "No such file or directory" errors
3. **Version mismatch**: Server and desktop app versions may diverge
4. **Poor UX**: Error messages about missing binaries confuse users
## Decision
Bundle the sensing server binary inside the desktop application and provide intelligent binary discovery with clear fallback paths.
### Binary Discovery Order
The desktop app searches for the sensing server in this order:
1. **Custom path** from user settings (`server_path`)
2. **Bundled resources** (`Contents/Resources/bin/` on macOS)
3. **Next to executable** (same directory as the app binary)
4. **System PATH** (legacy fallback)
### Implementation
```rust
fn find_server_binary(app: &AppHandle, custom_path: Option<&str>) -> Result<String, String> {
// 1. Custom path from settings
if let Some(path) = custom_path {
if std::path::Path::new(path).exists() {
return Ok(path.to_string());
}
}
// 2. Bundled in resources
if let Ok(resource_dir) = app.path().resource_dir() {
let bundled = resource_dir.join("bin").join(DEFAULT_SERVER_BIN);
if bundled.exists() {
return Ok(bundled.to_string_lossy().to_string());
}
}
// 3. Next to executable
if let Ok(exe_path) = std::env::current_exe() {
if let Some(exe_dir) = exe_path.parent() {
let sibling = exe_dir.join(DEFAULT_SERVER_BIN);
if sibling.exists() {
return Ok(sibling.to_string_lossy().to_string());
}
}
}
// 4. System PATH
// ... which lookup ...
Err("Sensing server binary not found")
}
```
### Bundle Configuration
In `tauri.conf.json`:
```json
{
"bundle": {
"resources": [
{
"src": "../../target/release/wifi-densepose-sensing-server",
"target": "bin/wifi-densepose-sensing-server"
}
]
}
}
```
## Consequences
### Positive
- **Single package distribution**: Users download one DMG/MSI/EXE
- **Version alignment**: Server and UI always match
- **Better UX**: No PATH configuration required
- **Offline capable**: Works without network access to download server
### Negative
- **Larger bundle size**: ~10-15MB additional for server binary
- **Build complexity**: Must build server before bundling desktop
- **Platform-specific**: Need separate server binaries per platform
### Neutral
- CI/CD workflow updated to build server before desktop
- GitHub Actions builds all platforms (macOS arm64/x64, Windows x64)
## WebSocket Integration
The Sensing page connects to the bundled server's WebSocket endpoint:
- `ws://127.0.0.1:{ws_port}/ws/sensing` - Real-time CSI data stream
- `ws://127.0.0.1:{ws_port}/ws/pose` - Pose estimation stream
Message format:
```typescript
interface WsSensingUpdate {
type: string;
timestamp: number;
source: string;
tick: number;
nodes: WsNodeInfo[];
classification: { motion_level: string; presence: boolean; confidence: number };
vital_signs?: { breathing_rate_hz?: number; heart_rate_bpm?: number };
}
```
## Security Considerations
- Server binary signed with same certificate as desktop app
- Communication over localhost only (127.0.0.1)
- No external network access by default
- Process spawned as child of desktop app (inherits permissions)
## Related ADRs
- ADR-054: Desktop Full Implementation
- ADR-053: UI Design System
- ADR-052: Tauri Desktop Frontend

View file

@ -0,0 +1,251 @@
# ADR-056: RuView Desktop Complete Capabilities Reference
## Status
Accepted
## Context
RuView Desktop is a comprehensive WiFi-based sensing platform that combines hardware management, real-time signal processing, neural network inference, and intelligent monitoring. This ADR documents all integrated capabilities across the desktop application and underlying crates.
## Decision
The RuView Desktop application consolidates all WiFi-DensePose functionality into a single, unified interface with the following capabilities.
---
## 1. Hardware Management
### 1.1 Node Discovery
- **mDNS discovery**: Automatic detection of ESP32 nodes via Bonjour/Avahi
- **UDP probe**: Direct UDP broadcast discovery on port 5005
- **HTTP sweep**: Sequential IP scanning with health checks
- **Manual registration**: User-defined node configuration
### 1.2 Firmware Flashing
- **Serial flashing**: Direct USB flash via espflash integration
- **Chip detection**: Automatic ESP32/S2/S3/C3/C6 identification
- **Progress monitoring**: Real-time progress with speed metrics
- **Verification**: Post-flash integrity verification
### 1.3 OTA Updates
- **Single-node OTA**: HTTP-based firmware push to individual nodes
- **Batch OTA**: Coordinated multi-node updates with strategies:
- `sequential`: One node at a time
- `tdm_safe`: Respects TDM slot timing
- `parallel`: Concurrent updates with throttling
- **Rollback support**: Automatic rollback on verification failure
- **Version tracking**: Pre/post version comparison
### 1.4 Node Configuration
- **NVS provisioning**: WiFi credentials, node ID, TDM slot assignment
- **Mesh configuration**: Coordinator/node/aggregator role assignment
- **TDM scheduling**: Time-division multiplexing slot allocation
---
## 2. Sensing Server
### 2.1 Data Sources
- **ESP32 CSI**: Real UDP frames from ESP32 hardware (port 5005)
- **Windows WiFi**: Native Windows RSSI monitoring via netsh
- **Simulation**: Synthetic data generation for demo/testing
- **Auto**: Automatic source detection based on available hardware
### 2.2 Real-Time Processing
- **CSI pipeline**: 56-subcarrier amplitude/phase extraction
- **FFT analysis**: Spectral decomposition for motion detection
- **Vital signs**: Breathing rate (0.1-0.5 Hz), heart rate (0.8-2.0 Hz)
- **Motion classification**: still/walking/running/exercising
- **Presence detection**: Binary presence with confidence score
### 2.3 WebSocket Streaming
- **Sensing endpoint**: `ws://localhost:8765/ws/sensing`
- **Pose endpoint**: `ws://localhost:8765/ws/pose`
- **Real-time broadcast**: 10-100 Hz update rate
- **Multi-client support**: Concurrent WebSocket connections
### 2.4 REST API
- **Health check**: `GET /health`
- **Status**: `GET /api/status`
- **Recording control**: `POST /api/recording/start|stop`
- **Model management**: `GET/POST /api/models`
---
## 3. Neural Network Inference
### 3.1 Model Formats
- **RVF (RuVector Format)**: Proprietary binary container with:
- Model weights (quantized f32/f16/i8)
- Vital sign configuration
- SONA environment profiles
- Training provenance
- Cryptographic attestation
### 3.2 Inference Capabilities
- **Pose estimation**: 17 COCO keypoints from WiFi CSI
- **Activity recognition**: Multi-class classification
- **Vital signs**: Breathing and heart rate extraction
- **Multi-person detection**: Up to 3 simultaneous subjects
### 3.3 Self-Learning (SONA)
- **Environment adaptation**: LoRA-based fine-tuning to room geometry
- **Profile switching**: Multiple learned environment profiles
- **Online learning**: Continuous adaptation during runtime
- **Transfer learning**: Profile export/import between deployments
---
## 4. WASM Edge Modules
### 4.1 Module Management
- **Upload**: Deploy WASM modules to ESP32 nodes
- **Start/Stop**: Runtime control of edge processing
- **Status monitoring**: CPU, memory, execution count
- **Hot reload**: Update modules without node reboot
### 4.2 Supported Operations
- **Local filtering**: On-device noise reduction
- **Feature extraction**: Pre-compute features at edge
- **Compression**: Reduce data before transmission
- **Custom logic**: User-defined processing pipelines
---
## 5. Mesh Visualization
### 5.1 Network Topology
- **Live mesh view**: Real-time node connectivity graph
- **Signal quality**: RSSI/SNR visualization per link
- **Latency monitoring**: Round-trip time measurement
- **Packet loss**: Delivery success rate tracking
### 5.2 CSI Visualization
- **Amplitude heatmap**: Per-subcarrier amplitude display
- **Phase unwrapping**: Continuous phase visualization
- **Spectrogram**: Time-frequency representation
- **Signal field**: 3D voxel grid of RF perturbations
---
## 6. Training & Export
### 6.1 Dataset Management
- **Recording**: Capture CSI frames with annotations
- **Labeling**: Activity and pose ground truth
- **Augmentation**: Synthetic data generation
- **Export**: Standard formats (JSON, CSV, NumPy)
### 6.2 Training Pipeline (ADR-023)
- **Contrastive pretraining**: Self-supervised feature learning
- **Supervised fine-tuning**: Labeled pose estimation
- **SONA adaptation**: Environment-specific tuning
- **Validation**: Cross-environment testing
### 6.3 Export Formats
- **RVF container**: Production deployment format
- **ONNX**: Interoperability with external tools
- **PyTorch**: Research and experimentation
- **Candle**: Rust-native inference
---
## 7. Security Features
### 7.1 Network Security
- **OTA PSK**: Pre-shared key for firmware updates
- **Node authentication**: MAC-based node verification
- **Encrypted transport**: Optional TLS for API endpoints
### 7.2 Code Signing
- **Firmware verification**: Hash-based integrity checks
- **WASM attestation**: Module signature validation
- **Model provenance**: Training lineage tracking
---
## 8. Configuration & Settings
### 8.1 Server Configuration
- **Ports**: HTTP (8080), WebSocket (8765), UDP (5005)
- **Bind address**: Localhost or network-wide
- **Data source**: auto/wifi/esp32/simulate
- **Log level**: debug/info/warn/error
### 8.2 Application Settings
- **Theme**: Dark/light mode
- **Auto-discovery**: Periodic node scanning
- **Discovery interval**: Configurable scan frequency
- **UI customization**: Responsive layout options
---
## 9. Crate Architecture
| Crate | Capabilities |
|-------|-------------|
| `wifi-densepose-core` | CSI frame primitives, traits, error types |
| `wifi-densepose-signal` | FFT, phase unwrapping, vital signs, RuvSense |
| `wifi-densepose-nn` | ONNX/PyTorch/Candle inference backends |
| `wifi-densepose-train` | Training pipeline, dataset, metrics |
| `wifi-densepose-mat` | Mass casualty assessment tool |
| `wifi-densepose-hardware` | ESP32 protocol, TDM, channel hopping |
| `wifi-densepose-ruvector` | Cross-viewpoint fusion, attention |
| `wifi-densepose-api` | REST API (Axum) |
| `wifi-densepose-db` | Postgres/SQLite/Redis persistence |
| `wifi-densepose-config` | Configuration management |
| `wifi-densepose-wasm` | Browser WASM bindings |
| `wifi-densepose-cli` | Command-line interface |
| `wifi-densepose-sensing-server` | Real-time sensing server |
| `wifi-densepose-wifiscan` | Multi-BSSID scanning |
| `wifi-densepose-vitals` | Vital sign extraction |
| `wifi-densepose-desktop` | Tauri desktop application |
---
## 10. UI Design System (ADR-053)
### 10.1 Pages
- **Dashboard**: Overview, node status, quick actions
- **Discovery**: Network scanning interface
- **Nodes**: Node management and configuration
- **Flash**: Serial firmware flashing
- **OTA**: Over-the-air update management
- **Edge Modules**: WASM deployment
- **Sensing**: Real-time monitoring with server control
- **Mesh View**: Network topology visualization
- **Settings**: Application configuration
### 10.2 Components
- **StatusBadge**: Health indicator
- **NodeCard**: Node information display
- **LogViewer**: Real-time log streaming
- **ActivityFeed**: Sensing data visualization
- **ProgressBar**: Operation progress
- **ConfigForm**: Settings input
---
## Consequences
### Positive
- **Unified interface**: All capabilities in one application
- **Bundled deployment**: Single package with server included
- **Real-time feedback**: WebSocket-based live updates
- **Cross-platform**: macOS, Windows, Linux support
- **Extensible**: WASM modules, custom models, API access
### Negative
- **Larger bundle**: ~6MB app + ~2.6MB server
- **Complexity**: Many features require learning curve
- **Hardware dependency**: Full functionality requires ESP32 nodes
### Neutral
- Documentation required for all features
- Training materials needed for advanced capabilities
- Community contributions welcome
## Related ADRs
- ADR-053: UI Design System
- ADR-054: Desktop Full Implementation
- ADR-055: Integrated Sensing Server
- ADR-023: 8-Phase Training Pipeline
- ADR-016: RuVector Integration

View file

@ -2,21 +2,77 @@ use std::process::{Command, Stdio};
use serde::{Deserialize, Serialize};
use sysinfo::{Pid, ProcessesToUpdate, System};
use tauri::State;
use tauri::{AppHandle, Manager, State};
use crate::state::AppState;
/// Default path to the sensing server binary (relative to resources).
const DEFAULT_SERVER_BIN: &str = "wifi-densepose-sensing-server";
/// Default binary name for the sensing server.
const DEFAULT_SERVER_BIN: &str = "sensing-server";
/// Find the sensing server binary path.
///
/// Search order:
/// 1. Custom path from config.server_path
/// 2. Bundled in app resources (macOS: Contents/Resources/bin/)
/// 3. Next to the app executable
/// 4. System PATH
fn find_server_binary(app: &AppHandle, custom_path: Option<&str>) -> Result<String, String> {
// 1. Custom path from settings
if let Some(path) = custom_path {
if std::path::Path::new(path).exists() {
return Ok(path.to_string());
}
}
// 2. Bundled in resources (Tauri bundles to Contents/Resources/)
if let Ok(resource_dir) = app.path().resource_dir() {
let bundled = resource_dir.join("bin").join(DEFAULT_SERVER_BIN);
if bundled.exists() {
return Ok(bundled.to_string_lossy().to_string());
}
// Also check directly in resources
let direct = resource_dir.join(DEFAULT_SERVER_BIN);
if direct.exists() {
return Ok(direct.to_string_lossy().to_string());
}
}
// 3. Next to the executable
if let Ok(exe_path) = std::env::current_exe() {
if let Some(exe_dir) = exe_path.parent() {
let sibling = exe_dir.join(DEFAULT_SERVER_BIN);
if sibling.exists() {
return Ok(sibling.to_string_lossy().to_string());
}
}
}
// 4. Check if it's in PATH
if let Ok(output) = Command::new("which").arg(DEFAULT_SERVER_BIN).output() {
if output.status.success() {
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
if !path.is_empty() {
return Ok(path);
}
}
}
Err(format!(
"Sensing server binary '{}' not found. Please build it with: cargo build --release -p wifi-densepose-sensing-server",
DEFAULT_SERVER_BIN
))
}
/// Start the sensing server as a managed child process.
///
/// The server binary is looked up in the following order:
/// 1. Settings `server_path` if set
/// 2. Bundled resource path
/// 3. System PATH
/// 3. Next to executable
/// 4. System PATH
#[tauri::command]
pub async fn start_server(
app: AppHandle,
config: ServerConfig,
state: State<'_, AppState>,
) -> Result<ServerStartResult, String> {
@ -28,10 +84,10 @@ pub async fn start_server(
}
}
// Determine server binary path
let server_path = config.server_path
.clone()
.unwrap_or_else(|| DEFAULT_SERVER_BIN.to_string());
// Find server binary
let server_path = find_server_binary(&app, config.server_path.as_deref())?;
tracing::info!("Starting sensing server from: {}", server_path);
// Build command with configuration
let mut cmd = Command::new(&server_path);
@ -52,6 +108,10 @@ pub async fn start_server(
cmd.args(["--log-level", log_level]);
}
// Set data source (default to "simulate" if not specified for demo mode)
let source = config.source.as_deref().unwrap_or("simulate");
cmd.args(["--source", source]);
// Redirect stdout/stderr to pipes for monitoring
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());
@ -207,6 +267,7 @@ pub async fn server_status(state: State<'_, AppState>) -> Result<ServerStatusRes
/// Restart the sensing server with the same or new configuration.
#[tauri::command]
pub async fn restart_server(
app: AppHandle,
config: Option<ServerConfig>,
state: State<'_, AppState>,
) -> Result<ServerStartResult, String> {
@ -222,6 +283,7 @@ pub async fn restart_server(
log_level: None,
bind_address: None,
server_path: None,
source: None, // Use default (simulate)
}
};
@ -232,7 +294,7 @@ pub async fn restart_server(
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
// Start with new config
start_server(restart_config, state).await
start_server(app, restart_config, state).await
}
/// Get server logs (last N lines from stdout/stderr).
@ -260,6 +322,8 @@ pub struct ServerConfig {
pub log_level: Option<String>,
pub bind_address: Option<String>,
pub server_path: Option<String>,
/// Data source: "auto", "wifi", "esp32", "simulate"
pub source: Option<String>,
}
#[derive(Debug, Clone, Serialize)]

View file

@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-config-schema/schema.json",
"productName": "RuView Desktop",
"version": "0.4.1",
"version": "0.4.2",
"identifier": "net.ruv.ruview",
"build": {
"frontendDist": "ui/dist",
@ -30,6 +30,9 @@
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
],
"resources": {
"../../target/release/sensing-server": "bin/sensing-server"
}
}
}

View file

@ -1,7 +1,7 @@
{
"name": "ruview-desktop-ui",
"private": true,
"version": "0.4.1",
"version": "0.4.2",
"type": "module",
"scripts": {
"dev": "vite",

View file

@ -9,6 +9,7 @@ const DEFAULT_CONFIG: ServerConfig = {
static_dir: null,
model_dir: null,
log_level: "info",
source: "simulate",
};
interface UseServerOptions {

View file

@ -17,34 +17,58 @@ interface LogEntry {
}
// ---------------------------------------------------------------------------
// Mock data generators
// WebSocket message types from sensing server
// ---------------------------------------------------------------------------
const MOCK_LOG_TEMPLATES: { level: LogLevel; source: string; message: string }[] = [
{ level: "INFO", source: "sensing-server", message: "HTTP listening on 127.0.0.1:8080" },
{ level: "INFO", source: "udp_receiver", message: "CSI frame from 192.168.1.42" },
{ level: "WARN", source: "vital_signs", message: "Low signal quality on node 2" },
{ level: "INFO", source: "pose_engine", message: "Activity: walking (confidence: 0.87)" },
{ level: "ERROR", source: "ws_session", message: "Client disconnected unexpectedly" },
{ level: "INFO", source: "udp_receiver", message: "CSI frame from 192.168.1.15" },
{ level: "INFO", source: "pose_engine", message: "Activity: sitting (confidence: 0.93)" },
{ level: "INFO", source: "sensing-server", message: "WebSocket client connected from 127.0.0.1" },
{ level: "WARN", source: "mesh_sync", message: "Node 4 heartbeat delayed by 1200ms" },
{ level: "INFO", source: "pose_engine", message: "Activity: standing (confidence: 0.91)" },
{ level: "INFO", source: "udp_receiver", message: "CSI frame from 192.168.1.78" },
{ level: "ERROR", source: "udp_receiver", message: "Malformed CSI payload (len=0)" },
{ level: "INFO", source: "csi_pipeline", message: "Subcarrier FFT complete (52 bins)" },
{ level: "WARN", source: "vital_signs", message: "Breathing rate out of range on node 5" },
{ level: "INFO", source: "pose_engine", message: "Activity: sleeping (confidence: 0.78)" },
];
interface WsNodeInfo {
node_id: number;
rssi_dbm: number;
position: [number, number, number];
amplitude: number[];
subcarrier_count: number;
}
const MOCK_ACTIVITIES = [
{ activity: "walking", confidence: 0.87 },
{ activity: "sitting", confidence: 0.93 },
{ activity: "standing", confidence: 0.91 },
{ activity: "sleeping", confidence: 0.78 },
{ activity: "exercising", confidence: 0.65 },
];
interface WsClassification {
motion_level: string;
presence: boolean;
confidence: number;
}
interface WsFeatures {
mean_rssi: number;
variance: number;
motion_band_power: number;
breathing_band_power: number;
dominant_freq_hz: number;
change_points: number;
spectral_power: number;
}
interface WsVitalSigns {
breathing_rate_hz?: number;
heart_rate_bpm?: number;
confidence?: number;
}
interface WsSensingUpdate {
type: string;
timestamp: number;
source: string;
tick: number;
nodes: WsNodeInfo[];
features: WsFeatures;
classification: WsClassification;
vital_signs?: WsVitalSigns;
posture?: string;
signal_quality_score?: number;
quality_verdict?: string;
bssid_count?: number;
estimated_persons?: number;
}
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function formatTimestamp(d: Date): string {
const hh = String(d.getHours()).padStart(2, "0");
@ -56,26 +80,71 @@ function formatTimestamp(d: Date): string {
let nextLogId = 1;
function createMockLogEntry(): LogEntry {
const template = MOCK_LOG_TEMPLATES[Math.floor(Math.random() * MOCK_LOG_TEMPLATES.length)];
return {
id: nextLogId++,
timestamp: formatTimestamp(new Date()),
level: template.level,
source: template.source,
message: template.message,
};
function createLogFromWsUpdate(update: WsSensingUpdate): LogEntry[] {
const entries: LogEntry[] = [];
const ts = formatTimestamp(new Date(update.timestamp * 1000));
// Log each node's CSI data
for (const node of update.nodes) {
entries.push({
id: nextLogId++,
timestamp: ts,
level: "INFO",
source: "csi_receiver",
message: `Node ${node.node_id}: RSSI ${node.rssi_dbm.toFixed(1)} dBm, ${node.subcarrier_count} subcarriers`,
});
}
// Log classification
if (update.classification) {
const level: LogLevel = update.classification.confidence < 0.5 ? "WARN" : "INFO";
entries.push({
id: nextLogId++,
timestamp: ts,
level,
source: "classifier",
message: `Motion: ${update.classification.motion_level} (presence=${update.classification.presence}, conf=${(update.classification.confidence * 100).toFixed(0)}%)`,
});
}
// Log vital signs if present
if (update.vital_signs) {
const vs = update.vital_signs;
const level: LogLevel = (vs.confidence ?? 0) < 0.5 ? "WARN" : "INFO";
entries.push({
id: nextLogId++,
timestamp: ts,
level,
source: "vital_signs",
message: `Breathing: ${vs.breathing_rate_hz?.toFixed(2) ?? "--"} Hz, HR: ${vs.heart_rate_bpm?.toFixed(0) ?? "--"} bpm`,
});
}
// Log quality verdict if present
if (update.quality_verdict && update.quality_verdict !== "Permit") {
entries.push({
id: nextLogId++,
timestamp: ts,
level: update.quality_verdict === "Deny" ? "ERROR" : "WARN",
source: "quality_gate",
message: `Signal quality: ${update.quality_verdict} (score=${(update.signal_quality_score ?? 0).toFixed(2)})`,
});
}
return entries;
}
function createMockSensingUpdate(): SensingUpdate {
const act = MOCK_ACTIVITIES[Math.floor(Math.random() * MOCK_ACTIVITIES.length)];
function createActivityFromWsUpdate(update: WsSensingUpdate): SensingUpdate | null {
if (!update.classification) return null;
const node = update.nodes[0];
return {
timestamp: new Date().toISOString(),
node_id: Math.floor(Math.random() * 6) + 1,
subcarrier_count: 52,
rssi: -(Math.floor(Math.random() * 40) + 30),
activity: act.activity,
confidence: parseFloat((act.confidence + (Math.random() * 0.1 - 0.05)).toFixed(2)),
timestamp: new Date(update.timestamp * 1000).toISOString(),
node_id: node?.node_id ?? 1,
subcarrier_count: node?.subcarrier_count ?? 52,
rssi: node?.rssi_dbm ?? -50,
activity: update.posture ?? update.classification.motion_level,
confidence: update.classification.confidence,
};
}
@ -84,7 +153,7 @@ function createMockSensingUpdate(): SensingUpdate {
// ---------------------------------------------------------------------------
const MAX_LOG_ENTRIES = 200;
const LOG_INTERVAL_MS = 2000;
const WS_RECONNECT_DELAY_MS = 3000;
// ---------------------------------------------------------------------------
// LogViewer component (ADR-053)
@ -241,28 +310,119 @@ export const Sensing: React.FC = () => {
// Activity feed state
const [activities, setActivities] = useState<SensingUpdate[]>([]);
// Simulated log feed
// WebSocket connection state
const [wsConnected, setWsConnected] = useState(false);
const wsRef = useRef<WebSocket | null>(null);
const reconnectTimeoutRef = useRef<number | null>(null);
// Connect to real WebSocket when server is running
useEffect(() => {
const interval = setInterval(() => {
if (pausedRef.current) return;
const entry = createMockLogEntry();
setLogEntries((prev) => {
const next = [...prev, entry];
return next.length > MAX_LOG_ENTRIES ? next.slice(next.length - MAX_LOG_ENTRIES) : next;
});
// Also push an activity update every ~3rd tick
if (Math.random() < 0.35) {
setActivities((prev) => {
const update = createMockSensingUpdate();
const next = [update, ...prev];
return next.slice(0, 5);
});
if (!isRunning || !status?.ws_port) {
// Server not running, disconnect if connected
if (wsRef.current) {
wsRef.current.close();
wsRef.current = null;
setWsConnected(false);
}
}, LOG_INTERVAL_MS);
return;
}
return () => clearInterval(interval);
}, []);
const connect = () => {
const wsUrl = `ws://127.0.0.1:${status.ws_port}/ws/sensing`;
const ws = new WebSocket(wsUrl);
ws.onopen = () => {
setWsConnected(true);
setLogEntries((prev) => [
...prev,
{
id: nextLogId++,
timestamp: formatTimestamp(new Date()),
level: "INFO",
source: "desktop",
message: `WebSocket connected to ${wsUrl}`,
},
]);
};
ws.onmessage = (event) => {
if (pausedRef.current) return;
try {
const update = JSON.parse(event.data) as WsSensingUpdate;
// Create log entries from the update
const entries = createLogFromWsUpdate(update);
if (entries.length > 0) {
setLogEntries((prev) => {
const next = [...prev, ...entries];
return next.length > MAX_LOG_ENTRIES ? next.slice(next.length - MAX_LOG_ENTRIES) : next;
});
}
// Create activity update
const activity = createActivityFromWsUpdate(update);
if (activity) {
setActivities((prev) => {
const next = [activity, ...prev];
return next.slice(0, 5);
});
}
} catch (err) {
console.error("Failed to parse WebSocket message:", err);
}
};
ws.onclose = () => {
setWsConnected(false);
wsRef.current = null;
// Only add disconnect log if server is still supposed to be running
if (isRunning) {
setLogEntries((prev) => [
...prev,
{
id: nextLogId++,
timestamp: formatTimestamp(new Date()),
level: "WARN",
source: "desktop",
message: "WebSocket disconnected, reconnecting...",
},
]);
// Attempt reconnect
reconnectTimeoutRef.current = window.setTimeout(connect, WS_RECONNECT_DELAY_MS);
}
};
ws.onerror = () => {
setLogEntries((prev) => [
...prev,
{
id: nextLogId++,
timestamp: formatTimestamp(new Date()),
level: "ERROR",
source: "desktop",
message: "WebSocket connection error",
},
]);
};
wsRef.current = ws;
};
connect();
return () => {
if (reconnectTimeoutRef.current) {
clearTimeout(reconnectTimeoutRef.current);
}
if (wsRef.current) {
wsRef.current.close();
wsRef.current = null;
}
};
}, [isRunning, status?.ws_port]);
const handleClearLog = useCallback(() => setLogEntries([]), []);
const handleTogglePause = useCallback(() => setPaused((p) => !p), []);
@ -349,6 +509,17 @@ export const Sensing: React.FC = () => {
{status.pid != null && <span>PID {status.pid}</span>}
{status.http_port != null && <span>HTTP :{status.http_port}</span>}
{status.ws_port != null && <span>WS :{status.ws_port}</span>}
<span style={{ display: "flex", alignItems: "center", gap: 4 }}>
<span
style={{
width: 6,
height: 6,
borderRadius: "50%",
background: wsConnected ? "var(--status-online)" : "var(--status-warning)",
}}
/>
{wsConnected ? "Live" : "Connecting..."}
</span>
</div>
)}
</div>

View file

@ -170,6 +170,8 @@ export interface WasmModule {
// Sensing Server
// ---------------------------------------------------------------------------
export type DataSource = "auto" | "wifi" | "esp32" | "simulate";
export interface ServerConfig {
http_port: number;
ws_port: number;
@ -177,6 +179,7 @@ export interface ServerConfig {
static_dir: string | null;
model_dir: string | null;
log_level: string;
source: DataSource;
}
export interface ServerStatus {

View file

@ -1,2 +1,2 @@
// Application version - single source of truth
export const APP_VERSION = "0.4.1";
export const APP_VERSION = "0.4.2";