This project is a FastAPI-based server for managing drones. It integrates with MongoDB for data storage and Mosquitto as the MQTT broker for communication.
- Drone Management: Manage drone statuses such as
flying,landed, andreturning. - MQTT Integration: Communicate with drones using MQTT protocol.
- MongoDB Integration: Store and retrieve drone data from MongoDB.
- RESTful API: Expose endpoints for interacting with drones.
- Docker: Ensure Docker is installed on your system.
- Docker Compose: Ensure Docker Compose is installed.
-
Clone the Repository:
git clone <https://gitlab.com/devops5995501/drone_api_server.git> cd drone_api_server
-
Environment Variables: Update the
docker-compose.yamlfile with the correct environment variables:MONGODB_URI: MongoDB connection string.MQTT_BROKER: MQTT broker connection string.
-
Build and Start Services: Use Docker Compose to build and start the services:
docker-compose up --build
-
Access the API:
- API Base URL:
http://localhost:8000 - Swagger UI:
http://localhost:8000/docs
- API Base URL:
.
├── Dockerfile # Docker configuration for the API
├── docker-compose.yaml # Docker Compose configuration
├── main.py # Entry point for the FastAPI application
├── domain/ # Domain logic for drones
│ ├── drone.py # Drone and DroneStatus classes
├── infrastructure/ # Infrastructure-related code
│ ├── mqtt_handler.py # MQTT handler for communication
│ ├── repository/ # Repository for MongoDB interactions
│ ├── drone_repository.py
├── tests/ # Unit tests for the application
│ ├── test_drone.py
├── requirements.txt # Python dependencies
└── README.md # Project documentation
-
Get Drone Status:
-
GET /drones/{drone_id}/status -
Response:
{
"drone_id": "drone-001",
"status": "flying",
"last_updated": "2025-04-05T13:28:28"
}
-
-
Send Command to Drone:
-
POST /drones/{drone_id}/command -
Payload:
{
"command": "takeoff"
}
-
- Command Topic:
drone/command- Used to send commands to drones.
- Status Topic:
drone/status- Used to receive status updates from drones.
-
Install Dependencies:
pip install -r requirements.txt
-
Run Locally:
uvicorn main:app --reload
-
Run Tests:
pytest
-
Connection Refused: Ensure MongoDB and Mosquitto are running and accessible.
-
Docker Issues: Rebuild the Docker images:
docker-compose build --no-cache
This project is licensed under the MIT License. See the LICENSE file for details.