How wirenboard/wb-mqtt-iec104 works
Main Components
• Gateway Core (Main Process): This is the heart of the application (src/main.cpp). It initializes the application, reads the configuration file (wb-mqtt-iec104.conf) and ties all the key modules together.
• Configuration Parser: Modules such as src/config_parser.cpp/h parse and validate the configuration with details like IEC104 settings, MQTT broker settings, and groups of channels. This component is responsible for auto-generating the /etc/wb-mqtt-iec104.conf on startup if needed.
• IEC 60870-5-104 Server: Implemented in src/IEC104Server.cpp/h, it listens on the specified host and port to accept incoming IEC 104 TCP/IP connections and handles the ASDU packets.
• MQTT Client: Although not in a single source file, the gateway (src/gateway.cpp/h) establishes a connection to the MQTT broker, subscribes to topics, and manages the message exchange between MQTT and IEC104.
• Logger: Modules (src/log.cpp/h) provide logging capabilities, which are essential for debugging and monitoring both the MQTT and IEC104 message flows.
• Exception Handling: Files like src/iec104_exception.cpp/h capture protocol or runtime errors ensuring system robustness.
• Build/Integration and Testing: The presence of a Jenkinsfile, Makefile, Debian packaging (debian/ folder) and test suite (test/ directory) indicates an established CI/CD pipeline and rigorous testing, even though these aren’t drawn as runtime components, they are part of the overall ecosystem.
Relationships and Data Flow
• The Gateway Core uses the Configuration Parser to load the settings (including MQTT broker details and IEC104 parameters) at startup.
• The MQTT Client (part of the gateway component) establishes a connection with the external MQTT broker, subscribes to the configured topics, and sends/receives messages.
• The IEC104 Server accepts incoming TCP/IP connections from external IEC104-compliant systems, acting as the controlled station.
• Trade of Data:
• Outbound: The gateway captures MQTT messages (from configured topics) and converts them into IEC104 ASDUs, sending them over the TCP/IP connection.
• Inbound: For commands (and potentially general interrogation messages), the IEC104 Server receives the ASDU, checks for a matching enabled channel in the configuration, and translates it into MQTT messages.
• The Logger captures significant events across both message flows, aiding in debugging and operational monitoring.
Architectural Patterns and Design Principles
• Modular Design: Each core functionality (config parsing, MQTT handling, and IEC104 communication) is separated into its own module to ensure maintainability.
• Decoupled Communication: The design clearly differentiates the incoming data streams (MQTT and IEC104) while having a central dispatcher (gateway) that handles message translation.
• Configuration-Driven Behavior: The gateway’s operation is heavily influenced by the configuration file, allowing dynamic control over which channels are enabled and how messages are routed.
• Robust Error Handling: Use of dedicated exception modules shows an emphasis on robust error management.