Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4283aa2
feat: initial commit
LeoLTM Aug 10, 2026
087c755
fix: update package name from python3-esptool to esptool in installat…
LeoLTM Aug 10, 2026
efa4aef
fix: update install script for production bundle and enhance network …
LeoLTM Aug 10, 2026
25aaf7b
docs: update docs with installer script instructions
LeoLTM Aug 14, 2026
13baa35
Add headless scripts for deployment, cleanup, and installation on Ras…
LeoLTM Aug 14, 2026
936c4ec
feat: optimize camera streaming and network configuration for GigE Vi…
LeoLTM Aug 14, 2026
de7fac9
feat: add rust only impl
LeoLTM Aug 14, 2026
18011a8
feat: remove config.toml
LeoLTM Aug 14, 2026
42b2a78
feat: enhance pkg-config probing for Aravis and ensure proper linking…
LeoLTM Aug 14, 2026
40d3c42
feat: add frontend code to headless-rust
LeoLTM Aug 14, 2026
c8caee0
feat: add host option for HTTP server bind address in README
LeoLTM Aug 14, 2026
5a76382
feat: enhance AppConfig to support host override and add CORS headers…
LeoLTM Aug 14, 2026
ab466f2
feat: remove failed poc headless typescript implementation
LeoLTM Aug 14, 2026
20bd1cd
feat: migrate scripts to headless-rust
LeoLTM Aug 14, 2026
abd4f86
feat: update deployment and installation scripts for improved interne…
LeoLTM Aug 14, 2026
067e172
fix: Fix camera acquisition and serial port EOF lockup
LeoLTM Aug 14, 2026
0c3cfe2
feat: enhance serial status handling and integrate with application s…
LeoLTM Aug 14, 2026
f08e4eb
feat: add violation handling and notification to WebSocket RPC
LeoLTM Aug 14, 2026
93f43ba
fix: performance issues and blocking (hopefully)
LeoLTM Aug 14, 2026
081a291
fix: trigger pipeline bug, websocket blocking, camera status, pub sub…
LeoLTM Aug 14, 2026
7ddd960
fix: GenICam camera configuration
LeoLTM Aug 14, 2026
7d49ac4
fix: correct logic for handling failed feature application in GenICam…
LeoLTM Aug 14, 2026
abd925e
feat: enhance camera control with trigger management and pixel format…
LeoLTM Aug 15, 2026
9b6805e
fix: order camera configuration for triggered capture mode and strobe…
LeoLTM Aug 15, 2026
49520f0
fix: update arv_camera_set_frame_rate_enable documentation to reflect…
LeoLTM Aug 15, 2026
7b300cf
fix: enhance strobe and frame rate handling in triggered mode
LeoLTM Aug 15, 2026
644e315
fix: align with electronbun implementation
LeoLTM Aug 15, 2026
dfd9dd0
fix: adjust frame rate handling and burst frame count for triggered mode
LeoLTM Aug 15, 2026
da63583
fix: add tracing and related dependencies for improved logging
LeoLTM Aug 15, 2026
9810551
fix: replace println! with tracing! for improved logging consistency
LeoLTM Aug 15, 2026
2a7ef23
fix: update GigE Vision socket buffer optimizations to 128MB and adju…
LeoLTM Aug 15, 2026
13be116
fix: update strobe configuration for flash synchronization and improv…
LeoLTM Aug 16, 2026
1608dfd
fix: implement GenICam trigger mode configuration and ensure proper h…
LeoLTM Aug 16, 2026
d97d123
feat: add ConnectionIndicator component and integrate it into Navigat…
LeoLTM Aug 16, 2026
6d50b8d
fix: reorder network configuration steps and enhance Wi-Fi performanc…
LeoLTM Aug 16, 2026
929fc8b
fix: add HUP trap to prevent script termination on hangup
LeoLTM Aug 16, 2026
6faac4d
fix: add diagnostics output to .gitignore
LeoLTM Aug 16, 2026
7900cb5
feat: add diagnostic commands to package.json for enhanced troublesho…
LeoLTM Aug 16, 2026
4ba52f0
feat: Add diagnostic probes and scenarios for network stability and p…
LeoLTM Aug 16, 2026
44c68b4
feat: Add ping and heartbeat response handling in WebSocket RPC
LeoLTM Aug 16, 2026
7ed83f6
feat: Implement heartbeat mechanism for WebSocket connection stability
LeoLTM Aug 16, 2026
f0ea56d
feat: Enhance ConnectionIndicator with latency and degradation handling
LeoLTM Aug 16, 2026
def0027
feat: Optimize GigE Vision socket buffer settings and disable Wi-Fi p…
LeoLTM Aug 16, 2026
31d95d4
feat: Add Wi-Fi rescan before connection to ensure SSID visibility an…
LeoLTM Aug 16, 2026
76bcac6
feat: Refactor network setup script to modularize mode applications a…
LeoLTM Aug 16, 2026
02ba262
feat: Implement armed state management and WebSocket integration for …
LeoLTM Aug 16, 2026
1e5c79e
feat: Enhance lap and measurement slices with improved state handling…
LeoLTM Aug 16, 2026
495c309
refactor: migrate from Rocket to Axum and update dependencies
LeoLTM Aug 17, 2026
0d30494
feat: refactor WebSocket implementation to Socket.io
LeoLTM Aug 17, 2026
612ce89
feat: Enhance Socket.io client with lifecycle event handling and impr…
LeoLTM Aug 17, 2026
73ef306
feat: Add new dependencies for image processing and document features
LeoLTM Aug 17, 2026
0e8b086
feat: Optimize image loading with compressed thumbnails and full-reso…
LeoLTM Aug 17, 2026
76ab696
feat: Implement image compression and caching with new ImageCompresso…
LeoLTM Aug 17, 2026
13fbd81
feat: Update image styling in LastCapturedImage component
LeoLTM Aug 17, 2026
0cf871f
feat: Enhance network performance with socket buffer tuning and fq_co…
LeoLTM Aug 25, 2026
d5080f6
feat: Improve socket connection resilience and database query perform…
LeoLTM Aug 25, 2026
2ca0229
feat: Enhance network connectivity with DNS interception and captive …
LeoLTM Aug 25, 2026
4a8a088
feat: Enhance network mode management with Wi-Fi client support and s…
LeoLTM Aug 25, 2026
5f6b9c3
feat: Implement Wi-Fi client mode with network scanning and configura…
LeoLTM Aug 25, 2026
1791782
feat: Update README for headless-rust module with enhanced Wi-Fi oper…
LeoLTM Aug 25, 2026
2fcd855
feat: Update README with enhanced network operation modes and onboard…
LeoLTM Aug 25, 2026
4b16d46
feat: Add qrcode.react dependency for QR code generation support
LeoLTM Aug 25, 2026
cf0e1ac
feat: Enhance network modes and configurations
LeoLTM Aug 25, 2026
c37097c
feat: Enhance Open AP setup mode with background execution and improv…
LeoLTM Aug 25, 2026
f57147b
feat: Import useEffect for managing side effects in CameraTab component
LeoLTM Aug 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
# speedcamera

This repo contains three submodules:
An end-to-end vehicle speed measurement, GigE Vision camera capture, and remote management suite.

| Submodule | Description |
---

## Submodules & Modules

| Directory | Description |
| --------- | ----------- |
| [arduino](./arduino) | The firmware for an ESP8266 that reads two light barriers and measures the speed of passing vehicles. It sends the measurement data to the companion app using serial communication. |
| [electronbun](./electronbun) | A fast and improved rewrite of the speedcamera companion app made with electronbun. |
| [electron](./electron) | (LEGACY) The companion app made with Electron that displays the speed measurements, triggers the camera and provides a user interface for configuring the speed camera. |
| [**`headless-rust`**](./headless-rust) | **(Recommended)** High-performance single-binary headless daemon and responsive Web UI controller for Raspberry Pi 5 built with Rust (Axum 0.8, Socket.io, native Aravis C FFI, SQLite) and embedded React + Vite frontend. Features IoT-style open AP setup hotspot (`192.168.4.1`) with captive portal redirect, Client Wi-Fi operation mode with scannable connect QR codes, and a dedicated GigE Vision Camera LAN (`192.168.1.100`). |
| [**`arduino`**](./arduino) | Microcontroller firmware (ESP8266 / ESP32) reading dual optical light barriers to calculate vehicle speeds and transmit telemetry over Serial. |
| [**`electronbun`**](./electronbun) | Desktop companion application rewrite built with Electron and Bun. |
| [**`electron`**](./electron) | *(Legacy)* Desktop companion app made with classic Electron. |

---

## Quick Deployment Commands (Raspberry Pi 5)

All deployment and maintenance commands are executed from your development laptop over SSH. The scripts pull the repository and perform all frontend asset builds and native Rust compilation directly on the Raspberry Pi.

```bash
cd headless-rust

# 1. Fresh Pi Setup (Pi connected to Home LAN/Wi-Fi with DHCP)
bun run install:pi pi@raspberrypi.local

# 2. Upgrade Existing Pi (in Client Wi-Fi Mode or Home LAN)
bun run deploy:pi pi@raspberrypi.local
# or when connected to Pi Wi-Fi hotspot during setup:
bun run deploy:pi pi@192.168.4.1

# 3. Complete Cleanup & Reset Network to DHCP
bun run cleanup:pi pi@raspberrypi.local
```

For full documentation on architecture, network onboarding flow, offline/client operation, dependencies, migration guide, and local mock testing, see the [**Headless Rust Documentation**](./headless-rust/README.md).
193 changes: 168 additions & 25 deletions electronbun/src/bun/industrial-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,88 @@ function notifyStatus() {
}
}

// ─────────────────────────────────────────────────────────────────────────────
// GENICAM TRIGGER CONFIGURATION QUIRKS (CRITICAL)
//
// 1. Independent Trigger Modes: GenICam cameras maintain independent TriggerMode
// states for EACH TriggerSelector (FrameStart, FrameBurstStart, AcquisitionStart).
// 2. Hardware Quirks: Some Hikrobot cameras ONLY support "FrameBurstStart" and
// will silently reject/ignore attempts to configure "FrameStart".
// 3. Fallback Logic: We must dynamically probe which selector the camera supports,
// explicitly disable TriggerMode on all OTHER selectors (to prevent them from
// causing free-run behavior), and only enable it on the supported selector.
// 4. Burst Count: When using FrameBurstStart, AcquisitionBurstFrameCount MUST be 1.
// 5. Frame Rate Limiter: AcquisitionFrameRateEnable MUST be false. Enabling it forces
// the internal clock to generate frames, silently overriding the software trigger
// and causing the flash to strobe continuously.
// ─────────────────────────────────────────────────────────────────────────────
function configureTriggerMode(cam: Camera, mode: "On" | "Off") {
console.log(`[industrial-camera] configureTriggerMode: Attempting to set mode '${mode}'`);
if (!cam.isFeatureAvailable("TriggerMode")) {
console.log("[industrial-camera] configureTriggerMode: TriggerMode feature is NOT available on this camera.");
return;
}

const selectors = ["FrameStart", "FrameBurstStart", "AcquisitionStart"];
let active: string | null = null;
for (const sel of selectors) {
try {
cam.setStringFeature("TriggerSelector", sel);
console.log(`[industrial-camera] configureTriggerMode: Successfully selected TriggerSelector = '${sel}'`);
active = sel;
break;
} catch (e) {
console.log(`[industrial-camera] configureTriggerMode: Failed to select TriggerSelector = '${sel}' - ${e}`);
}
}

if (!active) {
console.log("[industrial-camera] configureTriggerMode: Could not select ANY known TriggerSelector!");
return;
}

if (mode === "On") {
// Disable all other selectors explicitly to prevent free-run strobing
for (const sel of selectors) {
if (sel !== active) {
try {
cam.setStringFeature("TriggerSelector", sel);
cam.setStringFeature("TriggerMode", "Off");
console.log(`[industrial-camera] configureTriggerMode: Disabled TriggerMode on alternate selector '${sel}'`);
} catch (e) {
console.log(`[industrial-camera] configureTriggerMode: Failed to disable TriggerMode on alternate selector '${sel}' - ${e}`);
}
}
}
// Enable on active selector
try {
cam.setStringFeature("TriggerSelector", active);
cam.setStringFeature("TriggerMode", "On");
console.log(`[industrial-camera] configureTriggerMode: Enabled TriggerMode on active selector '${active}'`);

try {
cam.setStringFeature("TriggerSource", "Software");
console.log(`[industrial-camera] configureTriggerMode: Set TriggerSource = 'Software' on '${active}'`);
} catch (e) {
console.log(`[industrial-camera] configureTriggerMode: Failed to set TriggerSource = 'Software' - ${e}`);
}
} catch (e) {
console.log(`[industrial-camera] configureTriggerMode: Failed to enable TriggerMode on active selector '${active}' - ${e}`);
}
} else {
// Disable on ALL selectors to ensure full free-run (or complete trigger disablement)
for (const sel of selectors) {
try {
cam.setStringFeature("TriggerSelector", sel);
cam.setStringFeature("TriggerMode", "Off");
console.log(`[industrial-camera] configureTriggerMode: Disabled TriggerMode on selector '${sel}'`);
} catch (e) {
console.log(`[industrial-camera] configureTriggerMode: Failed to disable TriggerMode on selector '${sel}' - ${e}`);
}
}
}
}

export function initCamera() {
if (isConnected) return;
try {
Expand Down Expand Up @@ -59,10 +141,7 @@ export function initCamera() {
if (camera.isFeatureAvailable("AcquisitionMode")) {
camera.setStringFeature("AcquisitionMode", "Continuous");
}
if (camera.isFeatureAvailable("TriggerMode")) {
camera.setStringFeature("TriggerMode", "On");
camera.setStringFeature("TriggerSource", "Software");
}
configureTriggerMode(camera, "On");

if (camera.isFeatureAvailable("LineSelector")) {
try {
Expand All @@ -78,7 +157,7 @@ export function initCamera() {
}

try {
camera.setStringFeature("LineSource", "ExposureActive");
camera.setStringFeature("LineSource", "ExposureStartActive");
} catch {
/* ignore */
}
Expand Down Expand Up @@ -115,15 +194,18 @@ export function initCamera() {
/* ignore */
}

// additional features based on DB
if (settings.frameRate) {
try {
camera.setBooleanFeature("AcquisitionFrameRateEnable", true);
camera.setFrameRate(Number(settings.frameRate));
} catch {
/* ignore */
}
}
try {
camera.setIntegerFeature("AcquisitionBurstFrameCount", 1);
console.log("[industrial-camera] initCamera: Set AcquisitionBurstFrameCount = 1");
} catch { /* ignore */ }

// Frame rate limit must be disabled in triggered mode on Hikrobot cameras.
// Enabling it forces the camera's internal frame generator to run,
// which breaks TriggerMode and causes the flash to fire continuously!
try {
camera.setBooleanFeature("AcquisitionFrameRateEnable", false);
console.log("[industrial-camera] initCamera: Disabled AcquisitionFrameRateEnable");
} catch { /* ignore */ }
if (settings.cameraWidth) {
try { camera.setIntegerFeature("Width", Number(settings.cameraWidth)); } catch { /* ignore */ }
}
Expand All @@ -148,8 +230,19 @@ export function initCamera() {
}

export function disconnectCamera() {
setupStreamLoopActive = false;
if (stream) {
try { stream.stopAcquisition(); } catch { /* ignore */ }
}
// Restore safe camera state before disposing so the camera's volatile
// memory is never left with TriggerMode=Off (which causes free-run strobing).
if (camera) {
configureTriggerMode(camera, "On");
try { camera.setBooleanFeature("StrobeEnable", false); } catch {
try { camera.setIntegerFeature("StrobeEnable", 0); } catch { /* ignore */ }
}
}
if (stream) {
try { stream.dispose(); } catch { /* ignore */ }
stream = null;
}
Expand Down Expand Up @@ -206,7 +299,15 @@ export async function captureFrame(): Promise<string | null> {
camera.executeCommand("TriggerSoftware");
}

const buffer = stream.timeoutPopBuffer(2_000_000);
// Non-blocking wait loop with deadline to prevent freezing the Bun event loop
const deadline = Date.now() + 2000;
let buffer = null;
while (Date.now() < deadline) {
buffer = stream.tryPopBuffer();
if (buffer) break;
await new Promise((r) => setTimeout(r, 10));
}

if (!buffer || !buffer.isSuccess) {
if (buffer) stream.pushBuffer(buffer);
console.error("[industrial-camera] Capture timeout or error");
Expand Down Expand Up @@ -260,10 +361,16 @@ export async function startSetupStream(pushFrame: (base64: string) => void) {
try { stream.stopAcquisition(); } catch { /* ignore */ }

try { camera.setIntegerFeature("StrobeEnable", 0); } catch { /* ignore */ }
try { camera.setStringFeature("TriggerMode", "Off"); } catch { /* ignore */ }
configureTriggerMode(camera, "Off");
try { camera.setStringFeature("GainAuto", "Continuous"); } catch { /* ignore */ }
try { camera.setStringFeature("ExposureAuto", "Continuous"); } catch { /* ignore */ }

// Cap camera frame rate during setup preview to 10 FPS to prevent GigE network flood
try {
camera.setBooleanFeature("AcquisitionFrameRateEnable", true);
camera.setFrameRate(10);
} catch { /* ignore */ }

// Disable strobe properly by turning off StrobeEnable and unlinking LineSource
try { camera.setBooleanFeature("StrobeEnable", false); } catch {
try { camera.setIntegerFeature("StrobeEnable", 0); } catch { /* ignore */ }
Expand All @@ -284,15 +391,30 @@ export async function startSetupStream(pushFrame: (base64: string) => void) {
}

async function pumpSetupFrames(pushFrame: (base64: string) => void) {
let isProcessing = false;

while (setupStreamLoopActive && stream && camera) {
try {
const buffer = stream.timeoutPopBuffer(500_000);
if (!buffer || !buffer.isSuccess) {
if (buffer) stream.pushBuffer(buffer);
await new Promise(r => setTimeout(r, 10));
// Non-blocking tryPopBuffer ensures Bun event loop is never frozen by C FFI
const buffer = stream.tryPopBuffer();
if (!buffer) {
await new Promise((r) => setTimeout(r, 20));
continue;
}

if (!buffer.isSuccess) {
stream.pushBuffer(buffer);
await new Promise((r) => setTimeout(r, 20));
continue;
}

// If previous frame encoding/sending is still running, drop this frame to prevent buffer lag
if (isProcessing) {
stream.pushBuffer(buffer);
continue;
}

isProcessing = true;
const w = buffer.width;
const h = buffer.height;
const fmt = buffer.pixelFormatName;
Expand All @@ -308,12 +430,22 @@ async function pumpSetupFrames(pushFrame: (base64: string) => void) {
sharpInst = sharp(data, { raw: { width: w, height: h, channels: 1 } });
}

// Encode as JPEG for live stream performance
const jpegBuffer = await sharpInst.jpeg({ quality: 80 }).toBuffer();
// Downscale setup preview frame to max 800px width and compress to 60% quality JPEG
// to avoid CPU saturation on Pi and avoid saturating Wi-Fi AP bandwidth
const jpegBuffer = await sharpInst
.resize(800, null, { fit: "inside", withoutEnlargement: true })
.jpeg({ quality: 60 })
.toBuffer();

pushFrame(jpegBuffer.toString("base64"));
isProcessing = false;

// Throttle preview delivery to ~10 FPS
await new Promise((r) => setTimeout(r, 50));
} catch (e) {
isProcessing = false;
console.error("Setup stream pump error", e);
await new Promise(r => setTimeout(r, 100));
await new Promise((r) => setTimeout(r, 100));
}
}
}
Expand All @@ -324,10 +456,13 @@ export function stopSetupStream() {

try { stream.stopAcquisition(); } catch { /* ignore */ }

// CRITICAL: Restore TriggerMode FIRST to stop free-running acquisition
// before re-enabling strobe output, preventing any flash-strobing window.
configureTriggerMode(camera, "On");

// Restore settings to those saved in DB
const settings = getSettings();
try { camera.setIntegerFeature("StrobeEnable", 1); } catch { /* ignore */ }
try { camera.setStringFeature("TriggerMode", "On"); } catch { /* ignore */ }
const exposureAuto = settings.exposureAuto || "Off";
const gainAuto = settings.gainAuto || "Off";
try { camera.setStringFeature("GainAuto", gainAuto); } catch { /* ignore */ }
Expand All @@ -340,7 +475,7 @@ export function stopSetupStream() {

if (camera.isFeatureAvailable("LineSelector")) {
try { camera.setStringFeature("LineSelector", "Line1"); } catch { /* ignore */ }
try { camera.setStringFeature("LineSource", "ExposureActive"); } catch { /* ignore */ }
try { camera.setStringFeature("LineSource", "ExposureStartActive"); } catch { /* ignore */ }
}

if (gainAuto === "Off") {
Expand All @@ -350,6 +485,14 @@ export function stopSetupStream() {
try { camera.setExposureTime(Number(settings.cameraExposure) || 5000); } catch { /* ignore */ }
}

// Frame rate limit must be disabled in triggered mode.
// Enabling it forces the camera's internal frame generator to run,
// which causes the flash to fire continuously!
try {
camera.setBooleanFeature("AcquisitionFrameRateEnable", false);
console.log("[industrial-camera] stopSetupStream: Disabled AcquisitionFrameRateEnable");
} catch { /* ignore */ }

try { stream.startAcquisition(); } catch { /* ignore */ }
}

Expand Down
2 changes: 1 addition & 1 deletion electronbun/src/components/LastCapturedImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function LastCapturedImage() {
<img
src={imageSrc}
alt="Last capture"
className="max-w-full max-h-full object-contain animate-in fade-in duration-500"
className="h-full w-auto max-w-none object-contain animate-in fade-in duration-500"
/>
) : (
<div className="flex flex-col items-center text-muted-foreground/50">
Expand Down
Loading