Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Fix MQTT implementation, align with DStarGateway, and add documentation#85

Open
MW0MWZ wants to merge 1 commit intog4klx:masterfrom
MW0MWZ:MQTT_Fix
Open

Fix MQTT implementation, align with DStarGateway, and add documentation#85
MW0MWZ wants to merge 1 commit intog4klx:masterfrom
MW0MWZ:MQTT_Fix

Conversation

@MW0MWZ
Copy link

@MW0MWZ MW0MWZ commented Mar 8, 2026

Summary

This fixes and completes the existing MQTT support in ircDDBGateway, aligning it with the conventions established in DStarGateway and MMDVMHost. It also adds comprehensive documentation and example configuration files.

This is the first pass at these improvements; there may be follow-up commits required once validated on live hardware.

What's included

  • MQTT shutdown safety — added mosquitto_loop_stop() before mosquitto_destroy() to prevent a background thread zombie/use-after-free on exit, and MQTTLogFinalise() calls in both daemon and GUI shutdown paths to ensure clean disconnection
  • DStarGateway JSON compatibility — link status JSON events now use the same field names as DStarGateway (repeater, reflector, protocol, reason, action) so the same dashboard code works for both gateways
  • MQTT authentication — added mqttAuth, mqttUsername, mqttPassword config keys for broker authentication
  • Configurable client name — added mqttName config key, used as both the MQTT client name and topic prefix
  • PID-based client IDs — avoids the time_t truncation issue on 32-bit ARM (same fix as DStarGateway/MMDVMHost)
  • std::string MQTT interface — no wxString in the MQTT layer, cleaner separation of concerns
  • Config parser bug fix — added empty-line crash guard (str.IsEmpty() check before GetChar()) in IRCDDBGatewayConfig, TimerControlConfig, and TimeServerConfig parsers
  • DocumentationMQTT.md (config, topic structure, JSON examples, troubleshooting), CONFIGURATION.md (full reference for every config setting across all programs), BUILD.md (build parameters and dependencies), modernised README.md with feature list and DStarGateway recommendation
  • Example configslinux/ircddbgateway.example, linux/timeserver.example, linux/timercontrol.example with correct defaults

MQTT is always compiled in

Unlike DStarRepeater (which uses make MQTT=1), ircDDBGateway's Makefile unconditionally links -lmosquitto. MQTT code is always present in the binary. To disable MQTT at runtime, leave mqttAddress empty in the config file.

JSON link events

All ~30 WriteJSON call sites across DPlus, DExtra, DCS, and CCS protocol handlers have been updated to use the new DStarGateway-compatible signatures:

{"link":{"timestamp":"2025-03-08T14:23:15Z","repeater":"GB7XX  B","action":"linking","reason":"network","reflector":"REF001 C","protocol":"dextra"}}

Files changed

Area Files
MQTT connection + shutdown fix Common/MQTTConnection.cpp, Common/MQTTConnection.h
MQTT log + JSON events Common/MQTTLog.cpp, Common/MQTTLog.h
Config parsing + MQTT keys Common/IRCDDBGatewayConfig.cpp, Common/IRCDDBGatewayConfig.h
JSON event call sites Common/CCSHandler.cpp, Common/DCSHandler.cpp, Common/DExtraHandler.cpp, Common/DPlusHandler.cpp
App lifecycle (shutdown cleanup) ircDDBGateway/IRCDDBGatewayApp.cpp, ircDDBGateway/IRCDDBGatewayAppD.cpp
Status delegation ircDDBGateway/IRCDDBGatewayThread.cpp
Config parser bug fix TimeServer/TimeServerConfig.cpp, TimerControl/TimerControlConfig.cpp
Documentation README.md, BUILD.md, MQTT.md, CONFIGURATION.md
Example configs linux/ircddbgateway.example, linux/timeserver.example, linux/timercontrol.example

MQTT Implementation (aligned with DStarGateway / MMDVMHost):
- Rewrite MQTTConnection with mosquitto_loop_stop() fix to prevent
  background thread zombies on shutdown
- Add MQTT authentication support (mqttAuth, mqttUsername, mqttPassword)
- Add configurable client name (mqttName) used as topic prefix
- Use PID-based client IDs (avoids time_t truncation on 32-bit ARM)
- Use std::string interface throughout (no wxString in MQTT layer)
- Align JSON link status fields with DStarGateway (repeater/reflector/
  protocol/reason/action) for dashboard compatibility

Shutdown Safety:
- Add MQTTLogFinalise() calls to both daemon (IRCDDBGatewayAppD::run)
  and GUI (IRCDDBGatewayApp::OnExit) shutdown paths to ensure clean
  MQTT disconnection and thread cleanup before process exit

JSON Status Events:
- Update all ~30 WriteJSON call sites across DPlus, DExtra, DCS, and
  CCS protocol handlers to use new function signatures
- Simplify IRCDDBGatewayThread::writeJSONStatus to delegate to
  WriteJSONStatus

Config Parser Hardening:
- Add empty-line crash guard to IRCDDBGatewayConfig, TimerControlConfig,
  and TimeServerConfig parsers (str.IsEmpty() check before GetChar)

Documentation:
- Add MQTT.md with topic structure, JSON examples, and troubleshooting
- Add CONFIGURATION.md with full reference for all config files
- Add BUILD.md with build parameters and dependency information
- Add linux/ example configs for ircddbgateway, timeserver, timercontrol
- Modernise README.md with feature list and DStarGateway recommendation
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant