Closed arilloid closed 2 days ago
I have built a server that can process HTTP POST and GET requests with the sensor data, as well as store the data in the in-memory database (sensor_data.csv file), as per the acceptance criteria. The server application was built using JavaScript, Node.js, Express.js.
Updated the code and issue description to support WebSocket functionality, which was added to push the newly received Raspberry Pi data to the frontend in real time, instead of polling the data from the server every time the in-memory database gets new entries.
Basic Server Setup
User Story
As a backend developer, I want to set up a server that will be able to process HTTP POST requests from Raspberry Pi and HTTP GET requests from the frontend application. The newly received data should be broadcasted to the frontend in real time using WebSocket connection.
Description
This use case involves setting up a basic JavaScript server that can process HTTP POST requests for storing sensor data (temperature, humidity, and moisture) sent from a Raspberry Pi device and HTTP GET requests for sending the data to the frontend for display purposes.
Sensor data collected by a Raspberry Pi device needs to be sent to a server via HTTP for further processing and storage. The server should be capable of validating and storing this data in the in-memory database. in addition to this, the server should be able to process the GET requests for data retrieval. After the initial retrieval of the data, the data should be broadcasted to the frontend application in real time using WebSocket connection.
Acceptance Criteria
Testing
Normal Flow of Events
The server receives the HTTP POST request with sensor data from Raspberry Pi. The server validates the incoming data. The server stores the data in the in-memory database. The server responds with a success message (HTTP 200 OK).
The frontend application sends an HTTP GET request to the server endpoint to retrieve the stored sensor data. The server processes the GET request, retrieves the data from the database, and responds with the data in JSON format. The frontend application receives the data and displays it to the user.
When the server receives new sensor data it gets broadcasted to the frontend application in real time using WebSocket connection.
Alternate/Exceptional Flows:
S-1: Internal server error
The server encounters an unexpected error while processing the requests. The server responds with HTTP 500 Internal Server Error. The error is logged for debugging purposes
S-2: Invalid data format
The server rejects the data due to invalid formatting (e.g., missing fields), and responds with HTTP 400 Bad Request and a relevant error message. The error is logged for debugging purposes.