Ground-side Django application for the Humber Autonomous Surface Vehicle (ASV) project. It receives live telemetry from the vessel over MQTT, stores it in a local database, and displays everything on a real-time web dashboard.
| Layer | Technology |
|---|---|
| Web framework | Django 5 |
| MQTT client | paho-mqtt 2.x |
| MQTT Broker | Mosquitto |
| Database | SQLite (dev) / PostgreSQL (prod) |
| Video capture | OpenCV (planned) |
| Frontend | Vanilla JS + CSS (no build step) |
- MQTT Token model — securely stores broker credentials (host, port, username, password). Tokens are auto-generated with
secrets.token_urlsafe. - Telemetry model — one database row per MQTT message with fields for GPS, heading, speed, roll/pitch, battery voltage/%, and signal strength (RSSI).
- MQTT Receiver — Django management command that subscribes to ASV topics and persists every incoming message to the database.
- Web Dashboard — dark-themed GUI that auto-refreshes every 3 seconds, showing live KPI cards and a scrolling message log.
- REST-style JSON endpoints — polled by the dashboard JS; can also be consumed by other tools.
- Django Admin — full CRUD for tokens and telemetry rows.
Base-Station/
├── base_station/ # Django project settings & root URLs
│ ├── settings.py
│ └── urls.py
├── video_stream/ # Main Django app
│ ├── models.py # MQTTToken, TelemetryData
│ ├── views.py # Dashboard + JSON API views
│ ├── urls.py # App URL patterns
│ ├── admin.py # Admin registrations
│ ├── templates/
│ │ └── video_stream/
│ │ └── dashboard.html
│ └── management/
│ └── commands/
│ └── mqtt_receiver.py # MQTT listener command
├── mosquitto/ # Mosquitto MQTT files
├── manage.py
├── requirements.txt
└── dockerfile
pip install -r requirements.txtpython3 manage.py migratepython3 manage.py createsuperuserLog in to the admin panel at http://127.0.0.1:8000/admin/ and add an MQTT Token row with your broker's host, port, and credentials.
Or via the Django shell:
python3 manage.py shell
>>> from video_stream.models import MQTTToken
>>> MQTTToken.objects.create(label="ASV-1", broker_host="localhost", broker_port=1883)python3 manage.py mqtt_receiver
# Target a specific token by primary key:
python3 manage.py mqtt_receiver --token-id 1python3 manage.py runserverOpen http://127.0.0.1:8000/ to see the dashboard.
Because Loon-E's ROS node is not always available, a complete software mock environment is
included under tools/. It simulates the vessel and replaces the physical hardware entirely.
Run each command in its own terminal, from the Base-Station/ directory, in the order shown.
- Mosquitto installed (
brew install mosquittoon macOS /sudo apt install mosquittoon Ubuntu) - Python virtual environment activated (
source venv/bin/activate) - Database migrated (
python3 manage.py migrate)
Terminal 1 — Start the MQTT broker
python3 tools/mock_broker.pySpawns a local Mosquitto instance on 127.0.0.1:1883 with anonymous access.
Must be running before any MQTT publisher or subscriber is started.
Terminal 2 — Start the MQTT receiver
python3 manage.py mqtt_receiverSubscribes to all asv/* topics at QoS 1 and saves every message to the database.
| Flag | Default | Description |
|---|---|---|
--token-id <pk> |
first active token | Target a specific MQTT token by primary key |
--keepalive <s> |
60 | Broker keepalive interval in seconds |
# Example — pin to token 1
python3 manage.py mqtt_receiver --token-id 1Terminal 3 — Start the UDP receiver
python3 manage.py udp_receiverBinds a SOCK_DGRAM socket and saves incoming JSON datagrams to the database.
| Flag | Default | Description |
|---|---|---|
--host <ip> |
0.0.0.0 |
Interface to bind |
--port <n> |
5005 |
UDP port to listen on |
# Example — bind to a specific interface
python3 manage.py udp_receiver --host 127.0.0.1 --port 5005Terminal 4 — Start the mock ASV simulator
python3 tools/mock_asv.pySimulates Loon-E by publishing MQTT messages and UDP datagrams every 2 seconds. GPS follows a circular path centred on Humber College North Campus.
| Flag | Default | Description |
|---|---|---|
--interval <s> |
2 |
Seconds between transmission bursts |
--mqtt-only |
off | Skip UDP, send MQTT only |
--udp-only |
off | Skip MQTT, send UDP only |
# Example — fast tick, MQTT only
python3 tools/mock_asv.py --interval 1 --mqtt-onlyTerminal 5 — Start the video receiver
# Mock mode — uses the host machine's webcam (default when Loon-E is unavailable)
python3 manage.py video_receiver --mock
# Production mode — receives JPEG frames from Loon-E's ROS node over UDP
python3 manage.py video_receiver --udp
# Production mode on a custom port
python3 manage.py video_receiver --udp --port 5006Writes each frame atomically to /tmp/asv_frame.jpg, which the MJPEG view serves to
the browser.
Terminal 6 — Start the web server
python3 manage.py runserverOpen http://127.0.0.1:8000/ in a browser. The dashboard polls /api/telemetry/ every
3 seconds and updates KPI cards, the compass, and the video feed automatically.
Terminal 1 python3 tools/mock_broker.py # MQTT broker (Mosquitto)
Terminal 2 python3 manage.py mqtt_receiver # MQTT telemetry -> DB
Terminal 3 python3 manage.py udp_receiver # UDP telemetry -> DB
Terminal 4 python3 tools/mock_asv.py # Simulated Loon-E
Terminal 5 python3 manage.py video_receiver --mock # Webcam -> MJPEG stream
Terminal 6 python3 manage.py runserver # Web dashboard :8000
The receiver subscribes to the following topics (QoS 1):
| Topic | Data |
|---|---|
asv/gps |
lat, lon, alt |
asv/imu |
heading / yaw, roll, pitch, speed |
asv/system |
battery_voltage, battery_percent, rssi |
asv/sensor |
Generic sensor readings |
asv/telemetry |
Combined snapshot |
asv/log |
Logs |
All payloads are expected as JSON. Unknown fields are stored in the raw_payload column.
mosquitto_pub -t asv/gps -m '{"lat": 43.7, "lon": -79.5, "alt": 0.5, "speed": 1.2, "heading": 90, "battery": 82, "rssi": -65}'| URL | Method | Description |
|---|---|---|
/ |
GET | Web dashboard (HTML) |
/api/telemetry/ |
GET | Latest telemetry snapshot + last 20 rows (JSON) |
/api/tokens/ |
GET | Active MQTT tokens (JSON) |
/admin/ |
GET | Django admin |
| Variable | Default | Description |
|---|---|---|
DJANGO_SECRET_KEY |
dev-insecure-key-change-in-production |
Secret key for Django. Must be set to a strong random value in production |
DJANGO_DEBUG |
1 |
Enable debug mode (show errors). Set to 0 in production |
DJANGO_ALLOWED_HOSTS |
127.0.0.1,localhost |
Comma-separated list of allowed hosts |
MQTT_BROKER_HOST |
localhost |
MQTT broker hostname (mqtt when using Docker Compose) |
MQTT_BROKER_PORT |
1883 |
MQTT broker port |
MQTT_CLIENT_ID |
base_station_receiver |
MQTT client identifier |
UDP_HOST |
0.0.0.0 |
UDP listener host (0.0.0.0 = all interfaces) |
UDP_PORT |
5005 |
UDP listener port |
A dockerfile and compose.yml are included for containerised deployment.
Docker Compose automatically orchestrates all services: MQTT broker, Django web server, and MQTT receiver.
Prerequisites:
- Docker and Docker Compose installed
1. Create an environment file (optional but recommended)
cp .env.example .env # If .env.example exists, or create a new .env fileAdd any environment variables:
DJANGO_SECRET_KEY=your-secret-key-here
DJANGO_DEBUG=1
DJANGO_ALLOWED_HOSTS=127.0.0.1,localhost2. Start all services
docker-compose up -dThis starts three containers:
- mqtt — Eclipse Mosquitto broker on port 1883
- django-web — Django web server on port 8000
- mqtt-receiver — MQTT listener that persists messages to the database
3. Verify services are running
docker-compose ps4. Access the dashboard
Open http://localhost:8000/ in your browser.
5. Create a superuser (first time only)
docker-compose exec django-web python3 manage.py createsuperuserThen log in to the admin panel at http://localhost:8000/admin/ to add MQTT Token credentials.
6. Add an MQTT Token via admin or shell
docker-compose exec django-web python3 manage.py shell>>> from video_stream.models import MQTTToken
>>> MQTTToken.objects.create(label="ASV-1", broker_host="mqtt", broker_port=1883)
>>> exit()Note: Use mqtt as the hostname (the service name in compose.yml) instead of localhost.
# View logs from all services
docker-compose logs -f
# View logs from a specific service
docker-compose logs -f django-web
docker-compose logs -f mqtt-receiver
# Stop all services
docker-compose down
# Stop and remove volumes (WARNING: deletes database)
docker-compose down -v
# Restart a service
docker-compose restart django-web
# Run a management command
docker-compose exec django-web python3 manage.py migrate
# Test MQTT publishing (from host machine)
mosquitto_pub -h localhost -t asv/gps -m '{"lat": 43.7, "lon": -79.5, "alt": 0.5, "speed": 1.2, "heading": 90, "battery": 82, "rssi": -65}'- Port already in use: If port 8000 or 1883 is in use, edit
compose.ymland change the port mapping (e.g.,8001:8000). - Database locked: Remove the SQLite database and restart:
rm db.sqlite3 && docker-compose restart django-web - MQTT connection refused: Ensure the mqtt service is running:
docker-compose logs mqtt
- Live video stream via OpenCV + WebSocket
- Map view (Leaflet.js) with real-time vessel position
- Historical telemetry charts (Chart.js)
- WebSocket push instead of polling
- Multi-vessel support