End-to-end toolbox to log, replay, relay, and visualize ship data over MQTT.
This repository contains:
- mqtt-tcp-relay — Read Kafka-like MQTT topics and relay selected data as NMEA sentences over a TCP socket for client apps (e.g., navigation tools).
- mqtt-logger-gui — Simple Tkinter GUI to record MQTT streams into SQLite and play them back to a broker.
- mqtt-broker — A ready-to-run Eclipse Mosquitto broker configuration (Docker) for local playback/testing.
- mqtt-voyage-plotter — Utility to extract positions from recorded NMEA messages in a DB into a CSV.
You can run the stack with Docker, or run each tool with Python directly.
- compose.yml — Top-level Compose that includes service Compose files
- mqtt-broker/ — Mosquitto broker config + Compose
- mqtt-tcp-relay/ — MQTT→TCP relay script, config.toml, Dockerfile, Compose
- mqtt-logger-gui/ — Tk GUI app to record/play MQTT logs
- mqtt-voyage-plotter/ — Script to export positions from DB to CSV
- data/ — Example data files
- Docker with Docker Compose v2.20+ (for compose include) or specify multiple compose files manually
- Python 3.10+ (recommended 3.11+) if running tools directly
- Git (required because mqtt-logger-gui installs a Git-based dependency)
The top-level compose.yml includes the broker and the MQTT→TCP relay. This brings up:
- Mosquitto broker on localhost:1883 (and 9001 for websockets)
- TCP relay on localhost:2947, subscribing to configured MQTT topics and broadcasting NMEA sentences to any TCP clients
Steps:
- Ensure configuration is correct
- Edit
mqtt-tcp-relay/config.tomlif needed:mqtt.broker_addressdefault points atmqtt.gunnerus.it.ntnu.no. For local playback with the bundled broker, set it tolocalhost.mqtt.topicslists all topics to subscribe. Defaults are tailored for Gunnerus data.tcp.hostandtcp.portdefine where the relay listens (default0.0.0.0:2947).
- Start services
If your Docker Compose supports include: in compose files (v2.20+):
docker compose up --buildIf your Compose version doesn't support include:, run with multiple compose files:
docker compose -f mqtt-broker/compose.yml -f mqtt-tcp-relay/compose.yml up --build- Verify
- MQTT broker: Use an MQTT client to publish/subscribe on
localhost:1883. - TCP relay: Connect a TCP client and observe NMEA lines, e.g. with netcat:
# Requires netcat (nc). On some systems the command is `ncat`.
nc localhost 2947Stop with Ctrl+C. To run detached, add -d to the compose command.
The GUI records MQTT messages into a SQLite database and can play them back to an MQTT broker at adjustable speed.
- Install dependencies
python -m venv .venv
# Activate the virtualenv
# macOS/Linux
source .venv/bin/activate
# Windows PowerShell
# .\.venv\Scripts\Activate.ps1
pip install -r mqtt-logger-gui/requirements.txtNotes:
- This installs
mqtt-loggerfrom GitHub; ensure Git is installed and on PATH. - Tkinter (Tcl/Tk) may need to be installed depending on your platform:
- Windows/macOS (python.org installers) typically include Tcl/Tk.
- Linux may require installing
python3-tk(e.g.,apt-get install python3-tk).
- Configure
The GUI reads mqtt-logger-gui/config.toml by default:
[recorder]
broker_address = "localhost"
topics = ["#"]
output_dir = "data"
[player]
broker_address = "localhost"
topics = ["#/NMEA/#", "#/SeapathMRU/#"]- Set
recorder.broker_addressto your live broker (e.g.,mqtt.gunnerus.it.ntnu.no) for recording. - Set
player.broker_addressto the broker you want to publish playback to (often your local Mosquitto atlocalhost). output_diris where new DB files will be written during recording.
You can also select a different TOML file at runtime via the Configure button.
- Run the GUI
python mqtt-logger-gui/logger.pyActions inside the GUI:
- Record: creates
data/MQTT_log_YYYY-mm-dd-HH-MM-SS.dbunderoutput_dirand starts logging the configured topics. - Play: choose a
.dbfile and it will publish messages to the configured broker. UI shows "playing" while active. - Stop: stops recording or playback gracefully.
You can also run the relay without Docker.
- Install dependencies
python -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows PowerShell
# .\.venv\Scripts\Activate.ps1
pip install -r mqtt-tcp-relay/requirements.txt
pip install python-dateutil # required by the relay but not pinned in the file- Configure
Edit mqtt-tcp-relay/config.toml as described above.
- Run
python mqtt-tcp-relay/mqtt-tcp-relay.py --config mqtt-tcp-relay/config.toml- Test with a TCP client
nc localhost 2947Run just the broker (useful for GUI playback tests):
docker compose -f mqtt-broker/compose.yml up --buildPorts exposed:
- 1883/tcp (MQTT)
- 9001/tcp (WebSocket MQTT)
Anonymous access is enabled by default in mqtt-broker/config/mosquitto.conf; for production, harden the config (users/passwords, ACLs, TLS, etc.).
The utility in mqtt-voyage-plotter/voyage_plot.py reads logged DBs and writes a CSV with timestamp, latitude, longitude by parsing NMEA messages.
- Install dependency
pip install pynmea2- Run
python mqtt-voyage-plotter/voyage_plot.py <path to log>/MQTT_log.db <path to output>/output.csvCSV will be appended to if it already exists.
See license.txt. Copyright © NTNU.