FelizCoder / crewstand.backend

Backend for the CREW test stand control
MIT License
0 stars 0 forks source link

Implement WebSocket Route to Publish Sensor Readings #47

Open FelizCoder opened 3 days ago

FelizCoder commented 3 days ago

Description: As part of the CrewStand project, to enhance real-time monitoring capabilities, we need to implement a WebSocket route on the backend. This route will publish each sensor reading as soon as it is received, allowing clients to subscribe and receive updates in real-time.

Requirements:

  1. WebSocket Endpoint:

    • Implement a WebSocket endpoint (e.g., /ws/sensors) that clients can connect to in order to receive real-time sensor readings.
  2. Publish Sensor Readings:

    • Ensure that each sensor reading received by the /v1/sensors/flowmeters/{id}/reading endpoint is published to all connected WebSocket clients.
    • The data published should conform to the SensorReading schema.
  3. Client Management:

    • Manage client connections, ensuring that new clients can connect and subscribe to sensor updates.
    • Handle client disconnections gracefully, ensuring server stability.
  4. Error Handling:

    • Implement robust error handling, ensuring any issues with client connections or data publishing are handled gracefully.
    • Ensure server logs provide meaningful information for any errors encountered.
  5. Testing:

    • Write unit and integration tests to ensure the WebSocket route works correctly.
    • Test client connections, data publishing, and disconnections to ensure robustness.

Example WebSocket Message: The messages sent over the WebSocket should follow the SensorReading schema:

{
  "value": 0.42,
  "timestamp_ns": 1730906908814683100
}

Acceptance Criteria:


Additional Information:

FelizCoder commented 3 days ago

followup #43