Loading

All articles

Install an MQTT Broker on Ubuntu With Mosquitto for EEW Alerts

Terminal showing Mosquitto MQTT broker installation on Ubuntu for earthquake early warning messaging

Min

UPDATED ON

Install an MQTT Broker on Ubuntu With Mosquitto for EEW Alerts

Terminal showing Mosquitto MQTT broker installation on Ubuntu for earthquake early warning messaging

Engineering summary

Step-by-step Mosquitto setup on Ubuntu, from apt install to systemctl, remote listeners, pub/sub testing and password protection, as QuakeLogic uses it to drive IP-based earthquake sirens.

In short: To install an MQTT broker on Ubuntu, run sudo apt update, sudo apt install mosquitto mosquitto-clients, then sudo systemctl enable mosquitto and sudo systemctl start mosquitto. Mosquitto listens on port 1883 and allows anonymous clients by default; test it with mosquitto_sub and mosquitto_pub. For production, add a password file and TLS. QuakeLogic uses MQTT to deliver earthquake early warning messages to IP-based sirens.

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol designed for constrained devices and low-bandwidth, high-latency, or unreliable networks. It is widely used in IoT (Internet of Things) applications to facilitate communication between devices. In this guide, we will walk you through the steps to install and start an MQTT broker on Ubuntu using Mosquitto, a popular MQTT broker.

At QuakeLogic, we often use the MQTT service to deliver earthquake early warning messages, for example to activate the IP-based sirens that operate over the network.

Seismic monitoring instrumentation for "Why Every Facility Needs a Comprehensive Earthquake Early Warning Policy"

Step 1: Update Your System

Before installing any new software, it’s always a good idea to update your package list to ensure you have the latest version of all your installed packages.

sudo apt update

Step 2: Install Mosquitto and Mosquitto Clients

Mosquitto is a lightweight MQTT broker that is easy to install and configure. The Mosquitto clients package includes command-line tools to test your setup.

sudo apt install mosquitto mosquitto-clients

Step 3: Enable and Start the Mosquitto Service

Once installed, you need to enable the Mosquitto service to start on boot and then start the service.

  1. Enable the Mosquitto service: sudo systemctl enable mosquitto
  2. Start the Mosquitto service: sudo systemctl start mosquitto
  3. Check the status of the Mosquitto service: sudo systemctl status mosquitto You should see an output indicating that Mosquitto is active and running.

Step 4: Configure Mosquitto (Optional)

By default, Mosquitto is configured to allow anonymous connections on port 1883. For more advanced configurations, you can edit the Mosquitto configuration file located at /etc/mosquitto/mosquitto.conf.

  1. Open the configuration file: sudo nano /etc/mosquitto/mosquitto.conf
  2. Example configuration for allowing remote connections: listener 1883 allow_anonymous true
  3. Save and exit the file, then restart Mosquitto to apply changes: sudo systemctl restart mosquitto

Step 5: Test Mosquitto

To ensure Mosquitto is working correctly, you can use the Mosquitto clients to publish and subscribe to messages.

  1. Open two terminal windows.
  2. In the first terminal window, subscribe to a topic: mosquitto_sub -h localhost -t test/topic
  3. In the second terminal window, publish a message to the topic: mosquitto_pub -h localhost -t test/topic -m "Hello MQTT"

You should see the message “Hello MQTT” appear in the first terminal window.

Step 6: Secure Mosquitto (Optional)

For production environments, it is important to secure your MQTT broker. You can enable password protection and TLS/SSL encryption.

  1. Create a password file: sudo mosquitto_passwd -c /etc/mosquitto/passwd username
  2. Edit the Mosquitto configuration to use the password file: allow_anonymous false password_file /etc/mosquitto/passwd
  3. Restart Mosquitto: sudo systemctl restart mosquitto

For TLS/SSL encryption, you need to generate certificates and configure Mosquitto to use them. Detailed instructions can be found in the Mosquitto documentation.

Conclusion

By following these steps, you can easily set up an MQTT broker on your Ubuntu system using Mosquitto. This setup will allow you to facilitate communication between IoT devices efficiently. For more advanced configurations and security setups, refer to the Mosquitto documentation or reach out to the community for support.


About QuakeLogic

QuakeLogic is a leading provider of advanced seismic monitoring solutions, offering a range of products and services designed to enhance the accuracy and efficiency of seismic data acquisition and analysis. Our innovative technologies and expert support help organizations worldwide to better understand and mitigate the impacts of seismic events.

Contact Information

For more information about our products and services, please visit our website or contact our sales team. We are here to help you with all your seismic monitoring needs.


Thank you for choosing QuakeLogic. We look forward to assisting you with your seismic monitoring projects. Stay tuned to our blog for more tips and guides on using seismic monitoring tools and other technological solutions!

Key Takeaways

  • Install with sudo apt update followed by sudo apt install mosquitto mosquitto-clients.
  • Enable at boot and start: sudo systemctl enable mosquitto, sudo systemctl start mosquitto; verify with systemctl status.
  • Default config allows anonymous connections on port 1883; edit /etc/mosquitto/mosquitto.conf and add listener 1883 for remote clients.
  • Test with mosquitto_sub -h localhost -t test/topic in one terminal and mosquitto_pub -t test/topic -m 'Hello MQTT' in another.
  • Secure production brokers with mosquitto_passwd, allow_anonymous false and TLS certificates.

Frequently Asked Questions

How do I install Mosquitto on Ubuntu?

Update the package list with sudo apt update, then install the broker and command-line tools with sudo apt install mosquitto mosquitto-clients. Enable the service to start at boot using sudo systemctl enable mosquitto, start it with sudo systemctl start mosquitto, and confirm it is active with sudo systemctl status mosquitto. The broker is then listening on port 1883.

How do I test that the MQTT broker is working?

Open two terminals. In the first, subscribe to a topic with mosquitto_sub -h localhost -t test/topic. In the second, publish with mosquitto_pub -h localhost -t test/topic -m "Hello MQTT". If the message appears in the first terminal, the Mosquitto broker is routing messages correctly between clients and the installation is complete.

How do I allow remote connections to Mosquitto?

Edit /etc/mosquitto/mosquitto.conf with sudo nano and add listener 1883 together with allow_anonymous true for an open test broker, then restart with sudo systemctl restart mosquitto. Also make sure port 1883 is open in any firewall. For anything beyond a lab test, replace anonymous access with a password file and TLS encryption.

How do I secure a Mosquitto MQTT broker?

Create a password file with sudo mosquitto_passwd -c /etc/mosquitto/passwd username, then set allow_anonymous false and password_file /etc/mosquitto/passwd in the configuration and restart Mosquitto. For encryption, generate certificates and configure a TLS listener as described in the Mosquitto documentation. Password protection plus TLS is the minimum for a production broker.

Why is MQTT used for earthquake early warning?

MQTT is a lightweight publish/subscribe protocol built for constrained devices and low-bandwidth or unreliable networks, which makes it well suited to pushing time-critical alerts to many endpoints at once. QuakeLogic uses an MQTT broker to deliver earthquake early warning messages, for example to activate IP-based sirens across a network the moment a warning is issued.

Need help with a project? QuakeLogic designs and supplies seismic monitoring, earthquake early warning, structural health monitoring, infrasound, and shake table systems. Browse QuakeLogic products or contact our engineering team with your site, structure, or test requirements.


Discover more from QuakeLogic

Subscribe to get the latest posts sent to your email.

Reviewed by

QuakeLogic

Published by QuakeLogic engineers and seismic monitoring specialists. QuakeLogic designs earthquake early warning, structural health monitoring, infrasound, vibration monitoring, and shake table testing systems for infrastructure, research, public safety, and industrial engineering teams.

Topic cluster

Related engineering knowledge areas

Definitions and references

Terms, standards, and source cues

  • SHM: related to Structural Health Monitoring in this QuakeLogic knowledge cluster.
  • damage detection: related to Structural Health Monitoring in this QuakeLogic knowledge cluster.
  • earthquake early warning: related to Earthquake Early Warning in this QuakeLogic knowledge cluster.
  • seismic switch: related to Earthquake Early Warning in this QuakeLogic knowledge cluster.
  • infrasound sensors: related to Infrasound Monitoring in this QuakeLogic knowledge cluster.
  • low-frequency noise: related to Infrasound Monitoring in this QuakeLogic knowledge cluster.
  • shake tables: related to Shake Tables in this QuakeLogic knowledge cluster.
  • AC156: related to Shake Tables in this QuakeLogic knowledge cluster.

Need project support?

Talk with QuakeLogic about monitoring, testing, or warning systems.

Get engineering guidance for seismic monitoring, structural health monitoring, infrasound, vibration, earthquake early warning, and shake table applications.

Contact QuakeLogic

Author

SUBSCRIBE TO OUR NEWSLETTER

By subscribing to the newsletter, you agree to receive marketing emails from Quakelogic.

2008 Opportunity Dr. Suite 130,
Roseville, CA 95678, USA

Discover more from QuakeLogic

Subscribe now to keep reading and get access to the full archive.

Continue reading