This is a Flask application that collects sensor data and provides endpoints to retrieve, analyze, and manage the data. The application can be run locally or in a Docker container.
- Docker
- Docker Compose (optional, but recommended for managing multi-container applications)
-
Clone the repository:
git clone <repository-url> cd project
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Initialize the database:
python init_db.py
-
Populate the database with test data:
python test_populate.py
-
Run the Flask application:
python run.py
The application should now be running on
http://127.0.0.1:5000
.
-
Clone the repository:
git clone <repository-url> cd project
-
Build the Docker image:
docker build -t flask-sensor-app .
-
Run the Docker container:
docker run -p 5000:5000 flask-sensor-app
The application should now be running on
http://localhost:5000
. -
Initialize and populate the database with test data:
To initialize and populate the database with test data in Docker, follow these steps:
-
Run the container in interactive mode:
docker run -it --entrypoint /bin/sh flask-sensor-app
-
Inside the container, initialize the database:
python init_db.py
-
Populate the database with test data:
python test_populate.py
-
Exit the container:
exit
-
-
Run the Docker container normally:
docker run -p 5000:5000 flask-sensor-app
-
POST /data: Send data to the server.
curl -X POST http://127.0.0.1:5000/data -H "Content-Type: application/json" -d '{"device_id": "device1", "location": "office", "dust": 12.3, "gas": 45.6, "corrected_gas": 78.9, "temperature": 23.4, "humidity": 56.7}'
-
GET /data: Retrieve all data.
curl http://127.0.0.1:5000/data
-
GET /data/<device_id>: Retrieve data for a specific device.
curl http://127.0.0.1:5000/data/device1
-
GET /analyze/<device_id>: Analyze data for a specific device.
curl http://127.0.0.1:5000/analyze/device1
-
GET /devices: Retrieve all device IDs and their locations.
curl http://127.0.0.1:5000/devices
This project is licensed under the MIT License.