Are you finding the limitations of Mosquitto MQTT broker too restrictive for your IoT projects? You’re not alone! In this guide, we’ll dive deep into setting up EMQX MQTT broker—an advanced MQTT broker—on a Raspberry Pi, exploring its powerful dashboard, testing its functionality, and comparing it directly with Mosquitto to help you decide which broker fits your needs.
Mosquitto or EMQX MQTT broker
MQTT (Message Queuing Telemetry Transport) is the communication backbone of IoT systems. It’s lightweight, efficient, and ideal for low-bandwidth environments. Over the years, Mosquitto has been a popular choice for deploying MQTT brokers. Many users, including us, have utilized it in various projects, from Raspberry Pi to Android and PC-based IoT setups.
However, scalability and advanced features become crucial as IoT networks become more complex. That’s where EMQX steps in.
What is EMQX?
EMQX is an open-source MQTT broker designed to handle large-scale IoT networks. It boasts features such as:
- Scalability: Capable of supporting millions of connections.
- High Performance: Built for industrial-grade workloads.
- Dashboard Support: A user-friendly web interface for managing and monitoring your IoT setup.
If Mosquitto is the lightweight contender, EMQX is its powerful, feature-rich big brother. Let’s get started with setting it up!
Video Tutorial
Setting Up EMQX on a Raspberry Pi
1. Preparing Your Raspberry Pi
Start by connecting to your Raspberry Pi via SSH. Update the system packages with the following commands:
sudo apt update && sudo apt upgrade -y
2. Installing EMQX
Run the following commands to install EMQX:
curl -s https://assets.emqx.com/scripts/install-emqx-deb.sh | sudo bash
sudo apt-get install emqx
sudo systemctl start emqx
sudo systemctl enable emqx
Once installed, EMQX will run as a service, meaning it will automatically start on boot.
If you are using another OS, you can find the steps on the EMQX download page.
Exploring the EMQX Dashboard
One of EMQX’s standout features is its web-based management portal. You can access it by navigating to hostname.local:18083
in your browser (replace hostname
with your Raspberry Pi’s hostname).
- Default Username:
admin
- Default Password:
public
Configuring Password-Based Authentication
Before connecting MQTT clients to EMQX, you’ll need to enable password-based authentication:
- Create an Authenticator:
- Navigate to the Authentication page in the dashboard.
- Click + Create.
- Choose Password-Based authentication and select the Built-in Database option.
- Add Users:
- Under the Actions column for the authenticator, click Users.
- Add usernames and passwords for the clients that will connect to the broker.
Connecting a Client to EMQX with MQTT Explorer
MQTT Explorer is a free tool to test connections, publish messages, and subscribe to topics.
- Download and install MQTT Explorer.
- Create a new connection:
- Provide a connection name.
- Use the username/password created earlier.
- Set the hostname to match your Raspberry Pi’s configuration.
- Connect, publish messages, and subscribe to topics for testing.
EMQX dashboard features
The EMQX Dashboard offers a variety of features to monitor and manage MQTT traffic. To access it, navigate to the Home Assistant URL and click the “Web UI” button for the EMQX add-on.
Dashboard Features
The dashboard provides key insights into the MQTT broker’s activity, including:
- Incoming/Outgoing Message Rate: Displays the rate of messages being sent and received.
- Connections: Shows the number of active connections to the broker.
- Topics: Indicates the total number of topics in use.
- Subscriptions: Displays the number of active subscriptions.
- Node Information: Offers details such as the node name and uptime (useful for clusters).
- Metrics: Provides performance insights for the broker.
Nodes
This section displays details about the nodes in an EMQX cluster. If only one node is active, its information is shown.
Metrics
Visualize broker metrics like connection rates, message rates, and subscription counts. These graphs help identify performance bottlenecks or unusual activity.
Clients
Lists all connected clients and provides details such as:
- Status: Current connection status.
- Username: Used for authentication.
- IP Address: Client’s IP address.
- Keep Alive: Keep-alive interval set by the client.
- Connection Time: Timestamp when the client connected.
You can also disconnect problematic devices directly from this section.
Subscriptions
Offers an overview of all active subscriptions, showing which clients are subscribed to specific topics.
Topics
Lists all topics currently in use and displays topic-specific metrics:
- Incoming Messages: Number of messages received.
- Outgoing Messages: Number of messages sent.
- Dropped Messages: Messages that were dropped.
These metrics can be visualized graphically to aid in debugging and performance analysis.
Diagnose
Enable “Slow Subscriptions” to identify delays or performance issues in subscriptions.
Access Control
Manage client access with options to:
- Blacklist Clients: Block specific clients from connecting.
- Set Blacklist Duration: Define how long a client remains blacklisted.
- Add Notes: Record reasons for blacklisting.
Data Integration
Provides options to integrate EMQX with external systems for advanced functionality. These features may exceed the needs of typical Home Assistant users.
Rules Engine
Define custom logic and actions based on incoming messages to create powerful automation.
Flows
An advanced feature for defining workflows, often used alongside the rules engine.
Configuration
Allows configuration of broker settings, including:
- Listeners: Enable/disable listeners for protocols (SSL, TCP, WebSocket) and modify port settings to resolve conflicts.
- MQTT Settings: Adjust idle timeouts, session handling, and retained message settings.
- Log Settings: Configure log levels, handling, and file locations.
- Monitoring: Set up monitoring using Prometheus or Statsd.
Extensions
EMQX supports extensions such as Gateway Extensions, enabling additional integrations and features.
EMQX vs. Mosquitto: A Head-to-Head Comparison
Here’s how EMQX stacks up against Mosquitto:
Feature | EMQX | Mosquitto |
---|---|---|
Scalability | Excellent | Moderate |
Dashboard | Yes | No |
Performance | Industrial-Grade | Lightweight |
Simplicity | Moderate | Very Easy |
Verdict:
- Choose EMQX for large-scale IoT networks, advanced analytics, and a user-friendly dashboard.
- Stick with Mosquitto for smaller setups, resource-constrained devices, or when simplicity is key.
Conclusion
EMQX is a game-changer for those needing a robust and scalable MQTT broker, while Mosquitto remains a solid option for simpler projects. The choice ultimately depends on your project’s size and complexity.
Which MQTT broker will you use for your next IoT venture? Let us know in the comments below!
Don’t forget to share this post and subscribe for more IoT tutorials. Happy building!