When testing the UI locally, the WebSocket connection was failing with:
WebSocket connection to 'ws://localhost:3000/?email=...' failed:
WebSocket is closed before the connection is established.
Server logs showed:
No systems available, client added to waiting list
Client disconnected
Problem: The Dashboard was constructing the WebSocket URL without the /ws path:
- Incorrect:
ws://localhost:3000?email=... - Correct:
ws://localhost:3000/ws?email=...
Location: src/pages/dashboard/Dashboard.jsx line ~170
Original Code:
const wsHost = import.meta.env.DEV ? 'localhost:3000' : 'realheartremote.live/ws';
const wsUrl = `${wsProtocol}//${wsHost}${params.toString() ? '?' + params.toString() : ''}`;Fixed Code:
const wsHost = import.meta.env.DEV ? 'localhost:3000' : 'realheartremote.live';
const wsPath = '/ws';
const wsUrl = `${wsProtocol}//${wsHost}${wsPath}${params.toString() ? '?' + params.toString() : ''}`;Problem: The UI was trying to connect before any device (telemetry source) was connected.
Explanation:
- The server tracks connected "systems" (devices sending telemetry)
- When a UI client connects, it needs to watch a specific system
- If no systems are available, the client is added to a waiting list
- The connection then closes because there's nothing to watch
Solution: Start the telemetry sender before connecting with the UI.
Change: Added /ws path to WebSocket URL construction
Impact:
- ✅ WebSocket now connects to the correct endpoint
- ✅ Server can properly handle the connection
- ✅ UI receives telemetry data
Windows:
start-test.batThis automatically starts:
- Fastify server
- Telemetry sender
- Frontend dev server
Terminal 1 - Server:
node server/fastify-server.jsTerminal 2 - Telemetry Sender:
node server/send-sample-telemetry.jsTerminal 3 - Frontend:
npm run devThen open browser to http://localhost:5173
Browser Console:
[Connecting to WebSocket]: ws://localhost:3000/ws?email=bruce.wedding@realheart.se
[WebSocket Connected]
Server Logs:
[New WebSocket Connection]
Connection Query Params: { systemToWatch: 'TEST-SYSTEM-001', url: '/ws?email=...' }
✓ Device connected
✓ UI client connected
Dashboard Display:
- Heart Rate: 100 bpm
- Cardiac Output: 80 L/min (left), 8.5 L/min (right)
- Temperature: 43.0°C
- Voltage: 16.9V
- CPU Load: 20%
- Accelerometer: 1.40g
Browser Console:
WebSocket connection to 'ws://localhost:3000/?email=...' failed
Server Logs:
No systems available, client added to waiting list
Client disconnected
Correct Order ✅:
- Start server
- Start telemetry sender (device)
- Start frontend
- Open browser
Incorrect Order ❌:
- Start server
- Start frontend
- Open browser
- (No device connected → "No systems available")
- start-test.bat - Windows batch file to start all services
- start-test-environment.md - Detailed testing guide
- WEBSOCKET-CONNECTION-FIX.md - This document
server/send-sample-telemetry.js- Simulates a device sending telemetryserver/test-ui-connection.js- Automated test for connection flowserver/e2e-test.js- Full end-to-end test
✅ Fix Applied: Added /ws path to WebSocket URL in Dashboard.jsx
✅ Testing Guide: Created start-test.bat and documentation
✅ Verification: Connection now works correctly when services are started in the right order
The WebSocket connection issue is resolved. Follow the testing guide in start-test-environment.md for the correct startup sequence.