When testing locally, the UI couldn't connect because:
- Device (telemetry sender) connects to server
- Device sends telemetry messages
- UI client connects
- Server says "No systems available"
- UI client disconnects
When a device connected with type=device&SystemId=TEST-SYSTEM-001, the server:
- ✅ Stored the SystemId
- ✅ Set it in the state aggregator
- ❌ Did NOT register it as an available system
This meant UI clients couldn't find any systems to watch.
Updated server/fastify-server.js to:
- Register device as a system when it connects
- Connect waiting clients to the new system automatically
- Broadcast systems list so UI knows the system is available
When a device connects with a SystemId:
// Register this device as an available system
if (!connectedSystems.has(deviceSystemId)) {
connectedSystems.set(deviceSystemId, new Set());
}
// Connect any waiting clients to this new system
if (waitingClients.size > 0) {
waitingClients.forEach(client => {
if (client.readyState === 1) {
connectClientToSystem(client, deviceSystemId);
}
});
waitingClients.clear();
}Stop the current server (Ctrl+C) and restart:
node server/fastify-server.jsnode server/send-sample-telemetry.jsYou should now see in the server logs:
Device registered as system: TEST-SYSTEM-001
Connecting X waiting clients to TEST-SYSTEM-001
The UI should now connect successfully and display data!
Before Fix ❌:
[New WebSocket Connection] (device)
[New WebSocket Connection] (UI client)
No systems available, client added to waiting list
Client disconnected
After Fix ✅:
[New WebSocket Connection] (device)
Device registered as system: TEST-SYSTEM-001
[New WebSocket Connection] (UI client)
Connecting 1 waiting clients to TEST-SYSTEM-001
✓ UI receives telemetry data
server/fastify-server.js- Added device registration logic
After restarting the server:
- Telemetry sender connects
- Server logs: "Device registered as system: TEST-SYSTEM-001"
- UI connects successfully
- Server logs: "Connecting X waiting clients..."
- UI displays telemetry data
- No "Client disconnected" messages
The fix ensures that when a device connects, it's immediately registered as an available system, and any waiting UI clients are automatically connected to it. This solves the connection issue you were experiencing.