Site icon High Voltages

Set Up EMQX MQTT Broker on Raspberry Pi | Better Than Mosquitto?

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.

EMQX MQTT broker on Raspberry pi
EMQX MQTT broker on Raspberry pi

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:

If Mosquitto is the lightweight contender, EMQX is its powerful, feature-rich big brother. Let’s get started with setting it up!

Video Tutorial

Setup EMQX MQTT broker on raspberry pi | is it better than Mosquitto ?

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).

Configuring Password-Based Authentication

Before connecting MQTT clients to EMQX, you’ll need to enable password-based authentication:

  1. Create an Authenticator:
    • Navigate to the Authentication page in the dashboard.
    • Click + Create.
    • Choose Password-Based authentication and select the Built-in Database option.
  2. 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.

  1. Download and install MQTT Explorer.
  2. Create a new connection:
    • Provide a connection name.
    • Use the username/password created earlier.
    • Set the hostname to match your Raspberry Pi’s configuration.
  3. 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:

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:

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:

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:

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:

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:

FeatureEMQXMosquitto
ScalabilityExcellentModerate
DashboardYesNo
PerformanceIndustrial-GradeLightweight
SimplicityModerateVery Easy

Verdict:

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!

Exit mobile version