A minimal example demonstrating how to fetch OSD data from DJI drones via the DJI Cloud API, publish it over MQTT, and expose a FastAPI dashboard.
- Overview
- Features
- Prerequisites
- Installation
- Configuration
- Running EMQX (MQTT)
- Usage
- Sample Output
- Contributing
- License
- Contact
This project consists of two main components:
mqtt_client.py
: Connects to an MQTT broker, subscribes to DJI topics (sys/#
,thing/#
), parses JSON payloads, handlesupdate_topo
replies, and prints OSD telemetry.server.py
: Starts the MQTT client in the background and launches a FastAPI server to serve a static dashboard and expose configuration/health endpoints.
-
MQTT client with:
- Automatic subscription to
sys/#
andthing/#
topics. - Callbacks for status (
update_topo
) and OSD messages. - Clear logs prefixed with
[MQTT]
and[OSD]
. - Retry logic for DNS/connect errors.
- Automatic subscription to
-
FastAPI server with:
/api/config
endpoint returning DJI & MQTT settings./api/health
endpoint with server timestamp.- Static dashboard served at
/
frompublic/dashboard.html
. - Global error handlers for 404 and 500.
- Python 3.9 or higher
- Docker (for local EMQX broker)
- Your PC and DJI Smart Controller on the same local network
-
Clone the repository:
git clone https://github.com/OmerMersin/dji-cloud-platform-minimal.git cd dji-cloud-platform
-
(Optional) Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
Rename .env.example
to .env
and set the following variables:
DJI_APP_ID=<your_dji_app_id>
DJI_APP_KEY=<your_dji_app_key>
DJI_LICENSE=<your_dji_license>
HOST_ADDR=<your_broker_host_or_ip>
MQTT_USERNAME=<mqtt_username>
MQTT_PASSWORD=<mqtt_password>
Note: HOST_ADDR
is used by mqtt_client.py
to determine the broker address. The MQTT port defaults to 1883
.
To run a local EMQX broker via Docker:
docker run -d --name emqx \
-p 1883:1883 \
-p 8083:8083 \
-p 8084:8084 \
-p 8883:8883 \
-p 18083:18083 \
emqx:5.0.20
- Open the management console: http://localhost:18083/
- Default credentials:
admin
/public
- (Optional) Create additional users.
-
Ensure your DJI Smart Controller and PC are on the same network.
-
Run the server (which also starts the MQTT client):
python server.py
-
Access the dashboard at: http://localhost:3000/
-
Fetch configuration: GET http://localhost:3000/api/config
-
Check health: GET http://localhost:3000/api/health
[MQTT] Connecting to localhost:1883 ...
[MQTT] Connected to localhost:1883 with result code 0
[MQTT] Subscribed to topics: sys/#, thing/#
[MQTT] Received message on topic: thing/product/<sn>/osd
[OSD] Lat: 0, Lon: 0, Height: 16.16, Head: 10.4, Pitch: -0.4, Roll: 0.2
[OSD] Additional data:
{ '61-0-0': { 'gimbal_pitch': 0, 'gimbal_yaw': 117.8, ... },
'firmware_version': '03.31.0000',
... }
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature
. - Make your changes and commit:
git commit -m 'Add new feature'
. - Push to your branch:
git push origin feature/your-feature
. - Open a Pull Request.
This project is licensed under the MIT License. See LICENSE for details.
- Author: Omer Mersin (omermersin02@gmail.com)
- GitHub: https://github.com/OmerMersin/dji-cloud-platform-minimal