DEV Community

Shams Pathan
Shams Pathan

Posted on

How Working with Mosquitto Helped Me Grow as a Developer - A Journey into IoT Communication

A Journey into IoT Communication, MQTT, and Secure Messaging

When I first stumbled upon Mosquitto, I didn’t expect it would take me so deep into the world of IoT systems, real-time communication, and developer growth. What started as an experiment with lightweight messaging evolved into a journey of architectural insight and security design.


🌐 Why I Chose Mosquitto

Any IoT system depends on efficient communication—small packets, low latency, and resilience across unreliable networks.

That’s exactly where MQTT (Message Queuing Telemetry Transport) comes in. It’s a lightweight pub/sub protocol designed for constrained devices. And Mosquitto? It's a fast, open-source MQTT broker with a strong community—perfect for learning and deploying real-world systems.


🛠️ Setting Up Mosquitto

On my Debian Linux setup, getting started was as simple as:

sudo apt update
sudo apt install mosquitto mosquitto-clients
sudo systemctl start mosquitto
Enter fullscreen mode Exit fullscreen mode

Boom. The broker was running, ready to handle device messages.


🔄 Connecting IoT Devices via MQTT

One of the most powerful aspects of MQTT is its publish/subscribe model. Instead of tightly coupling devices, they communicate via topics.

Example use-case:

  • A temperature sensor publishes to: home/livingroom/temperature
  • A mobile app subscribes to that topic to display live data
  • A smart fan also subscribes and activates when temperature exceeds a threshold

Using CLI tools:

mosquitto_pub -t home/livingroom/temperature -m "27.3"
mosquitto_sub -t home/livingroom/temperature
Enter fullscreen mode Exit fullscreen mode

Just like that—I could see real-time messages flow. 💡


🔐 Securing It with mosquitto-go-auth

As things scaled, I needed authentication and access control. That’s when I discovered mosquitto-go-auth, a flexible plugin that integrates with various backends to manage users and ACLs.

✅ Supported Backends:

  • MySQL / PostgreSQL
  • Redis
  • MongoDB
  • JWT
  • HTTP
  • YAML/JSON files

I went with MySQL. Here's what I did:


🔧 Integration Steps

1. Enable Plugin in mosquitto.conf:

auth_plugin /etc/mosquitto/go-auth/go-auth.so
auth_plugin_opt_backends mysql
auth_plugin_opt_mysql_host localhost
auth_plugin_opt_mysql_port 3306
auth_plugin_opt_mysql_user mqtt_user
auth_plugin_opt_mysql_password mqtt_pass
auth_plugin_opt_mysql_db mqtt
Enter fullscreen mode Exit fullscreen mode

2. MySQL Tables for Users and ACL:

CREATE TABLE mqtt_user (
  username VARCHAR(100),
  password VARCHAR(100),
  salt VARCHAR(100)
);

CREATE TABLE mqtt_acl (
  username VARCHAR(100),
  topic VARCHAR(100),
  acc INT
);
Enter fullscreen mode Exit fullscreen mode

3. Sample ACLs:

-- Write access for sensor
INSERT INTO mqtt_acl (username, topic, acc) VALUES ('sensor1', 'home/sensor1/data', 2);

-- Read access for dashboard
INSERT INTO mqtt_acl (username, topic, acc) VALUES ('dashboard', 'home/+/data', 1);
Enter fullscreen mode Exit fullscreen mode

Access flags:

  • 1 → Read
  • 2 → Write
  • 3 → Read + Write

🧠 Lessons Learned

  • 🌟 Pub/Sub over HTTP: MQTT’s decoupled model is more powerful than I imagined.
  • 🔐 Security is non-optional: Real deployments need real auth.
  • 📊 Observability is key: Real-time debugging and logs matter.
  • 🧱 Protocols matter: Understanding low-level data flow makes you a better developer.

🧩 Final Thoughts

From quick tests to full-featured secure deployments, working with Mosquitto and mosquitto-go-auth taught me a lot about:

  • Event-driven systems
  • Lightweight protocol design
  • Practical backend integration

If you're building IoT, real-time systems, or even internal service communication—start with Mosquitto. Learn MQTT. Understand how auth works. You’ll grow as a developer, trust me.


🛠️ Bonus

Want config samples or a GitHub repo?

Drop a comment or message me—I’d love to share what I’ve built.


Top comments (0)