This project implements a robust, cross-platform Edge Gateway designed to bridge industrial protocols with a centralized cloud infrastructure. It leverages a hybrid asynchronous architecture using Boost.Asio for scheduled I/O, a decoupled multi-threaded ZeroMQ (ZMQ) pipeline for internal data routing, and a Paho MQTT Client for a secure, firewall-friendly cloud uplink.
- Hybrid Asynchronous Core: Combines a fixed-size Boost.Asio Thread Pool for efficient, non-blocking I/O and scheduled tasks (timers) with dedicated worker threads for core services.
- Decoupled Data Pipeline (V3): The architecture is built on a high-performance ZMQ PUB/SUB proxy. This design separates data flow into independent, lock-free paths:
- Hot Path (Uplink): Real-time telemetry streaming to the Central Broker via MQTT.
- Cold Path (Visualization): Throttled, low-priority updates to the local ImGui UI.
- Command Path (RPC): Isolated, routing-based command execution from Cloud/UI to Device.
- Hub-Broker-Client Topology: The Hub acts strictly as an Edge Client, connecting outbound to a central MQTT Broker. This eliminates the need for open inbound ports, solving NAT/Firewall traversal issues.
- Multiprotocol Support: Abstracted via the
IProtocolAdapterinterface, allowing for seamless integration of various industrial and messaging protocols (Modbus, OPC-UA, MQTT, ZMQ). - Integrated ImGui UI: A real-time user interface for device configuration, status monitoring, and live data logging, built directly into the application.
The architecture is built upon a decoupled, multi-threaded pipeline that separates data ingestion, processing, and transmission.
| Component | Responsibility | Technologies |
|---|---|---|
| 1. Main Thread | Executes the application's render and input loop (Local View). | Dear ImGui, GLFW/OpenGL |
| 2. Asio Thread Pool | A fixed-size pool running io_context.run(). Executes all posted non-blocking I/O and scheduled work for polling adapters (Modbus, OPC-UA). |
Boost.Asio |
| 3. Core Hub Threads | A set of dedicated threads forming the V3 data pipeline. | ZMQ (inproc) / Paho MQTT |
| └── RunDataProxy | The "heart" of the data plane. Runs a high-speed ZMQ PULL-to-PUB proxy to multiplex all incoming device data to the internal bus. | ZMQ PULL -> PUB |
| └── RunCloudLink | The "Hot Path" (Uplink). 1. Connects outbound to Central Broker (TCP/SSL). 2. Subscribes to internal ZMQ bus. 3. Publishes "Wrapped" telemetry to Cloud. 4. Receives RPC commands from Cloud. |
Paho MQTT Client (C++) |
| └── RunAggregator | The "Cold Path". Subscribes to the proxy on a slow, 100ms timer to update the local ImGui device map without blocking the uplink. | ZMQ SUB |
| └── RunCommandBridge | The "Command Path". A ZMQ ROUTER that routes commands from the Cloud Link (or local UI) to the correct protocol adapter using "Target & Strip" logic. | ZMQ ROUTER |
As a result of refactoring, the project follows a Model-View-Controller (MVC) pattern, separating the codebase into three logical components.
| Component | Files | Responsibilities |
|---|---|---|
| Bootstrap | main.cpp |
Initializes GLFW, ImGui, and the GatewayHub. Runs the main render loop. |
| View | GatewayUI.hGatewayUI.cpp |
Contains all Dear ImGui drawing logic. Declares and implements DrawGatewayUI(). Holds all UI-specific state and buffers. |
| Model | GatewayHub.hGatewayHub.cpp |
The application "engine." Contains all backend logic, global variables, adapter implementations, and the core threading model. |
The IProtocolAdapter defines a service manager responsible for a group of devices. The architecture allows for two distinct I/O models based on the protocol requirements:
| Adapter Type | I/O Model | Implementation Approach | Key Technologies |
|---|---|---|---|
| Polling (e.g., Modbus, OPC-UA) | Asynchronous / Task-Based | Uses boost::asio::steady_timer to schedule poll intervals. The blocking I/O operation is posted as a task to the Asio Thread Pool. No dedicated threads are created by the adapter. |
Boost.Asio |
| Event-Based (e.g., MQTT, ZMQ) | Thread-Per-Device | Uses a dedicated worker thread (std::thread) per device/connection. This thread blocks efficiently on network events (e.g., recv or message callbacks), which is a scalable approach for event-driven protocols. |
C++ std::thread |
This project uses CMake with CPM (C++ Package Manager) to automatically download and build all dependencies. The following libraries are managed automatically:
- Core: Boost (Asio, System)
- Messaging: ZMQ (libzmq, cppzmq), Paho MQTT C
- UI: Dear ImGui (local copy), GLFW3, GLEW
- Protocols: libmodbus, open62541, ....
- Utilities: simdjson
Linux:
- CMake 3.20 or higher
- C++17 compatible compiler (GCC 7+, Clang 5+)
- OpenGL development libraries
- OpenSSL development libraries
- Build tools (make, g++, etc.)
Install on Ubuntu/Debian:
sudo apt-get update
sudo apt-get install -y build-essential cmake libgl1-mesa-dev libssl-devInstall on Arch Linux:
sudo pacman -S base-devel cmake mesa opensslmacOS:
- CMake 3.20 or higher
- Xcode Command Line Tools
- Homebrew (optional, for OpenSSL)
Windows:
- CMake 3.20 or higher
- Visual Studio 2019 or later with C++ support (MSVC compiler)
- Git for Windows (for cloning dependencies)
- OpenSSL development libraries
- OpenGL support (usually included with graphics drivers)
Install using one of these methods:
Option 1: Using Chocolatey (Recommended)
# Install Chocolatey first (run PowerShell as Administrator)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Install dependencies
choco install cmake git visualstudio2022buildtools -yOption 2: Manual Installation
- Download and install CMake (Windows x64 Installer)
- Download and install Visual Studio 2022 with "Desktop development with C++" workload
- Download and install Git for Windows
- Download OpenSSL from Win32/Win64 OpenSSL or use vcpkg (see below)
Method 1: Using Visual Studio (Recommended)
-
Open Developer Command Prompt:
- Press
Win + Xand select "Developer Command Prompt for VS 2022" - Or open "x64 Native Tools Command Prompt for VS 2022" from Start Menu
- Press
-
Navigate to project directory:
cd C:\path\to\Factory-HUB -
Create build directory and configure:
mkdir build cd build cmake .. -G "Visual Studio 17 2022" -A x64
-
Build the project:
cmake --build . --config Release
-
Run the application:
.\bin\Release\Factory-HUB.exe
Method 2: Using CMake GUI
- Open CMake GUI
- Set "Where is the source code:" to your project directory
- Set "Where to build the binaries:" to
buildsubdirectory - Click "Configure" and select "Visual Studio 17 2022" as generator
- Click "Generate"
- Open the generated
Factory-HUB.slnin Visual Studio - Build the solution (F7 or Build > Build Solution)
- Run from Visual Studio (F5) or find the executable in
build\bin\Release\
Method 3: Using PowerShell/Terminal
# Navigate to project
cd C:\path\to\Factory-HUB
# Create build directory
mkdir build
cd build
# Configure (using Ninja for faster builds, optional)
cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release
# Or use Visual Studio generator
cmake .. -G "Visual Studio 17 2022" -A x64
# Build
cmake --build . --config Release
# Run
.\bin\Release\Factory-HUB.exeInstalling OpenSSL on Windows (if needed):
If CMake fails to find OpenSSL, you have two options:
Option A: Using vcpkg (Recommended for Windows)
# Clone vcpkg (one-time setup)
git clone https://github.com/microsoft/vcpkg.git C:\vcpkg
cd C:\vcpkg
.\bootstrap-vcpkg.bat
# Install OpenSSL
.\vcpkg install openssl:x64-windows
# Integrate with Visual Studio (optional but recommended)
.\vcpkg integrate install
# When configuring CMake, specify vcpkg toolchain:
cmake .. -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmakeOption B: Manual OpenSSL Installation
- Download OpenSSL from Win32/Win64 OpenSSL
- Install to
C:\OpenSSL-Win64(or your preferred location) - Configure CMake with:
cmake .. -DOPENSSL_ROOT_DIR=C:\OpenSSL-Win64
- Install system dependencies (if not already installed):
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y build-essential cmake libgl1-mesa-dev libssl-dev libmodbus-dev libglew-dev
# Arch Linux
sudo pacman -S base-devel cmake mesa openssl libmodbus glew-
Clone the repository:
git clone https://github.com/your-username/Factory-HUB.git cd Factory-HUB -
Create build directory and configure:
mkdir build cd build cmake .. -
Build the project:
cmake --build . -j$(nproc)
-
Run the application:
./bin/Factory-HUB
-
Install dependencies:
# Install Homebrew if not already installed /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Install required packages brew install cmake openssl
-
Build the project:
mkdir build && cd build cmake .. -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl cmake --build . -j$(sysctl -n hw.ncpu) ./bin/Factory-HUB