EMQX MQTT Integration
Connect LINK485 devices to EMQX for scalable, enterprise-grade MQTT messaging
⏱️ Setup Time: 15-20 minutes | 📚 Prerequisites: EMQX broker installed, LINK485 gateway configured | 🔒 Security: TLS/SSL optional, Username/Password authentication
Overview
EMQX is a highly scalable, open-source MQTT broker that supports millions of concurrent connections. This guide demonstrates how to connect LINK485 gateways to EMQX for reliable industrial IoT data collection, supporting both cloud and on-premise deployments.
Why EMQX?
⚡ High Performance
Supports 5M+ concurrent connections and millions of messages per second
🔄 Clustering
Built-in clustering for high availability and horizontal scaling
🔐 Security
TLS/SSL, authentication plugins, ACL, and rate limiting
📊 Dashboard
Built-in web dashboard for monitoring, metrics, and client management
Architecture
Modbus Devices
MQTT Pub/Sub
SCADA, Databases, Analytics
LINK485 publishes Modbus data to EMQX via MQTT. EMQX handles message routing, persistence, and distribution to multiple subscribers including databases, analytics platforms, and custom applications.
Prerequisites
- EMQX Broker: Version 5.0+ installed and running (Download here)
- LINK485 Gateway: Firmware v2.0+ with MQTT support
- Network Access: LINK485 can reach EMQX on port 1883 (MQTT) or 8883 (MQTTS)
- EMQX Dashboard Access: Default at http://broker-ip:18083 (admin/public)
Step 1: Install EMQX (Optional)
If you don't have EMQX installed yet, here's a quick Docker setup:
docker pull emqx/emqx:5.3
# Run EMQX container
docker run -d --name emqx \
-p 1883:1883 \
-p 8883:8883 \
-p 8083:8083 \
-p 18083:18083 \
emqx/emqx:5.3
Ports:
- 1883: MQTT (unencrypted)
- 8883: MQTTS (TLS/SSL encrypted)
- 8083: WebSocket
- 18083: EMQX Dashboard (web UI)
💡 Production Tip: For production deployments, use docker-compose or Kubernetes for clustering and persistence.
Step 2: Configure EMQX Authentication (Optional)
For secure deployments, configure authentication in EMQX:
- Open EMQX Dashboard: http://broker-ip:18083 (login: admin/public)
- Navigate to: Authentication → Create
- Select Mechanism: Built-in Database (Username/Password)
- Add User: Create credentials for LINK485
- Username: link485_gateway
- Password: (create a strong password)
- Is Superuser: No
- Click "Create"
⚠️ Security Note: Always use authentication and TLS in production environments. Never use default credentials.
Step 3: Configure Access Control (ACL)
Restrict which topics LINK485 can publish to:
- In EMQX Dashboard: Go to Authorization → Create
- Select Type: Built-in Database
- Add ACL Rules:
- Username: link485_gateway
- Permission: Allow
- Action: Publish
- Topic: link485/data/${clientid}
- Add another rule for status messages with topic:
link485/status/${clientid}
This ensures each gateway can only publish to its own topics.
Step 4: Configure LINK485 Device via Mobile App
For Link485 Air (WiFi)
- Power on your Link485 Air device
- Download Link485 App:
- 📱 Android: Download from Play Store
- 🍎 iOS: Download from App Store
- Open App and Add Device: Tap "Add New Device"
- Enter WiFi Credentials:
- SSID: Your WiFi network name
- Password: Your WiFi password
- Choose Integration Type: Select "EMQX" from dropdown
- Enter EMQX Broker Details:
- Broker Address: Your EMQX broker IP or hostname
- Port: 1883 (or 8883 for TLS)
- Username: link485_gateway (if authentication enabled)
- Password: Your password (if authentication enabled)
- Use TLS: Toggle ON if using port 8883
- Tap "Connect" - Device will configure and connect automatically
For Link485 4G (Cellular)
- Power on your Link485 4G device with SIM card inserted
- Download Link485 App (same as above)
- Optional: Enter WiFi credentials if you want WiFi as backup connectivity
- Choose Integration Type: Select "EMQX"
- Enter EMQX Broker Details (same as above)
- Tap "Connect" - Device uses 4G for primary connection
💡 Pro Tip: The mobile app automatically handles QoS, keepalive, and reconnection settings. You just need to provide broker credentials!
Understanding Data Flow & Topics
1. Data FROM Device (Telemetry)
Device publishes Modbus data to:
Your application should subscribe to:
-t "link485/+/telemetry" \
-u link485_gateway -P your_password
2. Commands TO Device
Device subscribes to commands at:
Your application should publish commands to:
-t "link485/AA:BB:CC:DD:EE:FF/commands" \
-m '{"command":"read_holding_registers","address":0,"count":10}' \
-u link485_gateway -P your_password
📝 Note: Replace {device_mac} with your device's MAC address (visible in Link485 mobile app). The app configures these topics automatically during setup.
Step 5: Verify Connection in EMQX Dashboard
- Open EMQX Dashboard: http://broker-ip:18083
- Go to Monitoring → Clients: You should see your LINK485 gateway listed
- Check Connection Details:
- Client ID: link485-gateway-001
- Status: Connected (green)
- IP Address: Gateway's IP
- Monitor Messages: Go to Monitoring → Topic Metrics to see message rates
Expected Dashboard View:
| Client ID | Username | Status | IP Address |
|---|---|---|---|
| link485-gateway-001 | link485_gateway | ● Connected | 192.168.1.100 |
Step 6: Subscribe to Data with MQTT Client
Test receiving data using the EMQX WebSocket client or MQTT.fx:
Option A: EMQX WebSocket Client
- In EMQX Dashboard, go to Tools → WebSocket Client
- Keep default settings and click Connect
- In the Subscribe section, enter topic:
link485/data/# - Click Subscribe
- You should see JSON messages arriving with Modbus data
Option B: MQTT.fx or Mosquitto Client
mosquitto_sub -h broker-ip -p 1883 -t "link485/data/#" -u link485_gateway -P your_password
# Using MQTTX CLI
mqttx sub -h broker-ip -p 1883 -t "link485/data/#" -u link485_gateway -P your_password
Data Format
LINK485 publishes JSON-formatted messages to EMQX:
"device_id": "link485-gateway-001",
"timestamp": "2025-10-29T10:45:23Z",
"slaves": [
{
"slave_id": 1,
"name": "Energy Meter 1",
"type": "energy_meter",
"registers": {
"voltage": 230.5,
"current": 12.3,
"power": 2835.15,
"energy": 1234.56,
"frequency": 50.02
},
"quality": "good",
"last_poll": "2025-10-29T10:45:22Z"
},
{
"slave_id": 2,
"name": "VFD Pump",
"type": "vfd",
"registers": {
"speed": 45.6,
"current": 8.2,
"status": "running"
},
"quality": "good",
"last_poll": "2025-10-29T10:45:22Z"
}
],
"gateway_info": {
"uptime": 86400,
"rssi": -65,
"firmware": "2.1.4"
}
}
| Field | Type | Description |
|---|---|---|
device_id |
string | Unique gateway identifier (matches Client ID) |
timestamp |
ISO8601 | UTC timestamp when data was collected |
slaves |
array | Array of Modbus slave devices |
slaves[].slave_id |
integer | Modbus slave address (1-247) |
slaves[].name |
string | Human-readable device name |
slaves[].registers |
object | Key-value pairs of register data |
gateway_info |
object | Gateway health and status information |
Advanced: EMQX Rule Engine
EMQX Rule Engine allows real-time data processing, filtering, and forwarding:
Example 1: Forward High Power Readings to Webhook
SQL Rule:
device_id,
timestamp,
slaves[1].registers.power as power
FROM
"link485/data/#"
WHERE
slaves[1].registers.power > 5000
Action: Webhook → POST to https://alerts.example.com/high-power
Example 2: Store Data in TimescaleDB
SQL Rule:
*
FROM
"link485/data/#"
Action: TimescaleDB → Insert into timeseries table
Example 3: Republish to Separate Topics per Device Type
SQL Rule:
*
FROM
"link485/data/#"
Action: Republish → devices/${slaves[1].type}/${device_id}
Troubleshooting
❌ Connection Failed
- Verify EMQX broker is running:
docker psor check service status - Ensure firewall allows traffic on port 1883/8883
- Test connectivity:
telnet broker-ip 1883 - Check EMQX logs:
docker logs emqx
❌ Authentication Failed
- Verify username/password are correct in both EMQX and LINK485
- Check authentication is enabled in EMQX Dashboard
- Ensure user exists in EMQX authentication database
- Try connecting without authentication first to isolate issue
❌ Client Keeps Disconnecting
- Check for duplicate Client IDs (must be unique per connection)
- Verify network stability between LINK485 and EMQX
- Increase keepalive interval in LINK485 settings (default: 60s)
- Check EMQX max connections limit hasn't been reached
❌ Not Authorized to Publish
- Check ACL rules in EMQX Dashboard → Authorization
- Verify topic pattern matches what LINK485 is publishing to
- Ensure authorization is properly configured and enabled
- Try disabling ACL temporarily to isolate issue
❌ No Data in WebSocket Client
- Verify LINK485 shows "Connected" status in its dashboard
- Check Modbus slaves are configured and responding
- Ensure subscription topic includes wildcard correctly:
link485/data/# - Check EMQX dashboard for incoming message rates
Performance Tuning
For High-Volume Deployments
- Increase Max Connections: Edit
emqx.conf- setlisteners.tcp.default.max_connections = 100000 - Enable Clustering: Deploy multiple EMQX nodes for horizontal scaling
- Use Persistent Sessions: Enable session persistence for guaranteed delivery
- Message Batching: Configure LINK485 to batch messages if publishing frequently
- QoS Strategy: Use QoS 0 for non-critical telemetry, QoS 1 for important data
- Monitoring: Enable Prometheus metrics for production monitoring
Next Steps
📊 Integrate with InfluxDB
Use EMQX Rule Engine to forward data to InfluxDB for time-series storage
📈 Visualize with Grafana
Create real-time dashboards by connecting Grafana to your time-series database
🔄 Node-RED Integration
Subscribe to EMQX topics from Node-RED for visual workflow automation
☁️ EMQX Cloud
Use EMQX Cloud for fully managed, scalable MQTT service
Need Help with EMQX Integration?
Our team can help you design and deploy scalable MQTT architectures for industrial IoT applications