@@ -49,6 +49,56 @@ daq-radio/
4949- Transmits data to base station
5050- Supports both real CAN hardware and CSV simulation
5151
52+ ### WebSocket Service Architecture
53+
54+ The frontend uses a ** centralized WebSocket service** that runs independently of any component, ensuring continuous data flow across all pages.
55+
56+ #### Location
57+ ```
58+ pecan/Frontend/pecan-live-dashboard/src/
59+ ├── services/
60+ │ └── WebSocketService.ts # WebSocket connection manager
61+ ├── App.tsx # Service initialization
62+ └── pages/
63+ └── Dashboard.tsx # Displays data from DataStore
64+ ```
65+
66+ #### How It Works
67+
68+ ** 1. Service Initialization (App.tsx)**
69+ - WebSocketService starts when the app mounts
70+ - Connects to ESP32 WebSocket server
71+ - Initializes CAN processor with DBC file
72+ - Stays active during entire app session
73+
74+ ** 2. Message Processing (WebSocketService.ts)**
75+ ```
76+ WebSocket Message → CAN Processor → DataStore → React Components
77+ ```
78+
79+ ** 3. Automatic Reconnection**
80+ - Up to 5 reconnection attempts on disconnect
81+ - Linear backoff delay (2s, 4s, 6s, 8s, 10s) TODO: maybe change to exponential
82+ - Seamless recovery from network issues
83+
84+ ** 4. Component Updates**
85+ - Components use DataStore hooks to access data
86+ - No WebSocket logic in display components
87+ - Clean separation of concerns
88+
89+ #### Benefits
90+ - ** Persistent Connection** : WebSocket stays alive across page navigation
91+ - ** Centralized Management** : Single point of control for all telemetry data
92+ - ** Automatic Recovery** : Handles disconnections gracefully
93+ - ** Simpler Components** : Pages focus on display, not data fetching
94+ - ** Scalability** : Multiple pages can show live data without multiple connections
95+
96+ #### Development URL
97+ ```
98+ Development: ws://localhost:8080/ws
99+ Production: ws://192.168.4.1:8080/ws (ESP32 Access Point)
100+ ```
101+
52102### SavvyCAN Integration
53103- Real-time CAN monitoring and analysis
54104- UDP forwarding on port 12347
0 commit comments