Close Menu
Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools

Get Free Tutorials & Discounts!

Subscribe for the latest IoT tutorials and exclusive KSP Electronics discount codes.

Instagram WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
Circuit of Things Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools
Hire us
Circuit of Things
Home » IoT Basics » What is MQTT? A Beginner’s Guide to the IoT Messaging Protocol
IoT Basics

What is MQTT? A Beginner’s Guide to the IoT Messaging Protocol

Sai Preetham KoyyalaBy Sai Preetham KoyyalaMay 26, 2026Updated:May 26, 2026No Comments7 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
circuitofthings
circuitofthings
Share
Facebook Twitter LinkedIn Pinterest Email

If you have been working with IoT projects involving ESP32, Arduino, or Raspberry Pi, you have almost certainly come across the term MQTT. It appears in tutorials on Home Assistant, Node-RED, and virtually every connected device project. Yet many beginners skip past it without fully understanding what it is or why it matters. This guide explains MQTT from the ground up — what it is, how it works, and how to use it in your own IoT projects.

Contents
  • Table of Contents
  • What is MQTT?
  • Why Use MQTT for IoT?
  • MQTT vs HTTP: What is the Difference?
  • How MQTT Works: Core Concepts
  • MQTT in Practice: A Real-World Example
  • Getting Started with MQTT on ESP32
  • MQTT Security Best Practices
  • Popular MQTT Tools and Clients
  • Conclusion
  • Further Reading and Official Resources
  • Related Guides

Table of Contents

What is MQTT?

MQTT (Message Queuing Telemetry Transport) is a lightweight, open-standard messaging protocol designed specifically for constrained devices and low-bandwidth, high-latency networks. It was originally developed by IBM in the late 1990s for monitoring oil pipelines via satellite and has since become the de facto standard for IoT communication.

MQTT operates on a publish-subscribe model, meaning devices do not communicate directly with each other. Instead, they send messages to a central server called a broker, which then distributes those messages to any device that has subscribed to receive them.

MQTT is to IoT what HTTP is to the web — a foundational communication protocol that makes everything else possible.

Why Use MQTT for IoT?

IoT devices such as sensors and microcontrollers operate under very different constraints compared to standard computers. They typically have limited processing power, small amounts of memory, and may run on battery power for extended periods. MQTT was designed with these constraints in mind:

  • Minimal bandwidth usage — MQTT headers are as small as 2 bytes, making it far more efficient than HTTP for frequent data transmissions.
  • Low power consumption — Devices can sleep between transmissions and reconnect quickly, extending battery life significantly.
  • Reliable delivery — MQTT supports three levels of Quality of Service to guarantee message delivery even on unreliable networks.
  • Scalable architecture — A single broker can handle thousands of connected devices simultaneously.
  • Persistent sessions — The broker can store messages for offline devices and deliver them when the device reconnects.

MQTT vs HTTP: What is the Difference?

FeatureMQTTHTTP
ArchitecturePublish-SubscribeRequest-Response
Header Size2 bytes minimumHundreds of bytes
ConnectionPersistentNew connection per request
Power UsageVery lowHigher
Best ForReal-time sensor data, IoT devicesWeb APIs, file transfers
Port1883 (standard), 8883 (TLS)80 (standard), 443 (HTTPS)

How MQTT Works: Core Concepts

The Broker

The MQTT broker is the central server that receives all messages and routes them to the appropriate subscribers. Popular brokers include:

  • Mosquitto — A lightweight, open-source broker ideal for self-hosting on a Raspberry Pi or local server.
  • HiveMQ — A cloud-based broker with a free tier, widely used in production IoT deployments.
  • EMQX — A high-performance, scalable broker suited to enterprise applications.
  • broker.hivemq.com — A free public broker useful for testing and development.

Publishers and Subscribers

Any MQTT client can act as a publisher, a subscriber, or both simultaneously.

  • A publisher sends a message to the broker on a specific topic. Example: an ESP32 publishes a temperature reading to home/livingroom/temperature.
  • A subscriber tells the broker which topics it wants to receive. Example: a mobile app subscribes to home/livingroom/temperature and receives every update the ESP32 sends.

Topics

MQTT topics are hierarchical strings that act as message addresses, using forward slashes to create logical structure:

home/bedroom/temperature
home/bedroom/humidity
home/garage/door/status
factory/line1/machine3/rpm
farm/field2/soil/moisture

Subscribers can use wildcards to receive multiple topics at once. The + wildcard matches a single level (e.g. home/+/temperature), while # matches all levels below a point (e.g. home/# matches every topic starting with home/).

Quality of Service (QoS)

QoS LevelGuaranteeUse Case
QoS 0 — At most onceNo guarantee. Message may be lost.Regular sensor readings
QoS 1 — At least onceDelivered at least once, may duplicate.Alerts and commands
QoS 2 — Exactly onceDelivered exactly once, no duplicates.Critical actuator triggers

Retained Messages

When a publisher marks a message as retained, the broker stores it. Any new subscriber immediately receives that stored message upon connecting, rather than waiting for the next publish. This is useful for device status topics.

Last Will and Testament (LWT)

A client can define a Last Will and Testament message when connecting. If the client disconnects unexpectedly due to power loss or a network fault, the broker automatically publishes the LWT message, allowing other devices or dashboards to detect and respond to the disconnection.

MQTT in Practice: A Real-World Example

Consider a simple home monitoring system built with ESP32 boards:

  • An ESP32 in the living room reads temperature from a DHT22 sensor and publishes to home/livingroom/temperature every 30 seconds.
  • An ESP32 in the garage monitors a door sensor and publishes open or closed to home/garage/door on state change.
  • A Raspberry Pi running Mosquitto acts as the broker, receiving all messages.
  • Home Assistant subscribes to all home/# topics and displays live data on a dashboard.
  • A mobile app subscribes to home/garage/door and sends a push notification whenever the door opens.

All of this happens in real time, with minimal bandwidth, and the system continues to function reliably even if individual devices temporarily lose connectivity.

Getting Started with MQTT on ESP32

The most common way to use MQTT with an ESP32 is through the PubSubClient library in the Arduino IDE. Here is a minimal example that connects an ESP32 to a broker and publishes a sensor reading:

#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid     = "YourWiFiSSID";
const char* password = "YourWiFiPassword";
const char* broker   = "broker.hivemq.com";

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) delay(500);
    client.setServer(broker, 1883);
    client.connect("ESP32_Client");
}

void loop() {
    if (!client.connected()) client.connect("ESP32_Client");
    client.publish("home/livingroom/temperature", "24.5");
    delay(30000);
}

This sketch connects to Wi-Fi, establishes an MQTT connection to the HiveMQ public broker, and publishes a temperature value every 30 seconds.

MQTT Security Best Practices

A default MQTT setup transmits data in plain text with no authentication, which is acceptable for local development but unsuitable for any internet-facing deployment. Follow these practices when deploying MQTT in production:

  • Use TLS encryption — Connect on port 8883 with TLS to encrypt all traffic between clients and the broker.
  • Enable authentication — Configure the broker to require a username and password for all client connections.
  • Use access control lists (ACLs) — Restrict each client to only the topics it legitimately needs to access.
  • Self-host your broker — For sensitive data, run Mosquitto on a private server rather than using a public broker.
  • Rotate credentials regularly — Update passwords and certificates on a scheduled basis.

Popular MQTT Tools and Clients

  • MQTT Explorer — A desktop GUI client for browsing, publishing, and subscribing to topics. Excellent for debugging.
  • MQTTX — A modern, cross-platform MQTT desktop and CLI client with a clean interface.
  • Node-RED — A flow-based visual programming tool with built-in MQTT nodes, ideal for building IoT dashboards and automations.
  • Home Assistant — Integrates natively with MQTT for smart home device management.
  • Mosquitto CLI — Command-line tools for quick publishing and subscribing directly from a terminal.

Conclusion

MQTT is one of the most important MQTT IoT protocols in the ecosystem. Understanding it opens the door to building robust, scalable, and efficient connected systems. Whether you are building a simple home sensor network or a multi-device industrial monitoring platform, MQTT provides the reliable and lightweight communication layer your project needs.

Once you are comfortable with the basics covered in this guide, the natural next steps are setting up your own Mosquitto broker on a Raspberry Pi, integrating MQTT with Node-RED for visual automation, and connecting your ESP32 projects to Home Assistant for a fully featured smart home dashboard.

Further Reading and Official Resources

  • MQTT.org — The official MQTT protocol specification and FAQ.
  • Eclipse Mosquitto — Official documentation for the open-source Mosquitto MQTT broker.
  • HiveMQ MQTT Essentials — A comprehensive series covering every aspect of the MQTT protocol in depth.
  • Node-RED — Official documentation for the flow-based IoT automation platform.

Related Guides

  • What is IoT? A Beginner’s Guide to the Internet of Things
  • Arduino for Beginners: A Complete Getting Started Guide
  • ESP32 Getting Started Guide: Setup, Pinout and First Projects
  • Top 5 Development Boards for IoT Projects in 2026
  • ESP32 MQTT Tutorial: Publish and Subscribe with HiveMQ
  • ESP32 Firebase Realtime Database Tutorial
esp32 Home Assistant IoT Mosquitto MQTT Node-RED Raspberry Pi
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleWhat is IoT? A Beginner’s Guide to the Internet of Things
Next Article Arduino for Beginners: A Complete Getting Started Guide
Sai Preetham Koyyala
  • Website
  • Facebook
  • X (Twitter)
  • Instagram
  • LinkedIn

Hello, I am Sai Preetham Koyyala. I'm an electronics engineer by profession, a DIY enthusiast by passion. ESP32 and Arduino are the main topics of my work.

Related Posts

ESP32 Projects

ESP32 Getting Started Guide: Setup, Pinout and First Projects

May 26, 2026
Arduino Projects

Arduino for Beginners: A Complete Getting Started Guide

May 26, 2026
IoT Basics

What is IoT? A Beginner’s Guide to the Internet of Things

May 26, 2026
Add A Comment
Leave A Reply Cancel Reply


⚡

Circuit of Things

Free IoT tutorials & electronics projects — powered by KSP Electronics.

📸 Instagram 💬 Community
✓ Official Partner Store

Everything for Your
Next IoT Build

Boards, sensors, modules & kits — fast delivery across India.

ESP32 Arduino Sensors Raspberry Pi 3D Print
🛒 Shop KSP Electronics →
Top Posts

Raspberry Pi: How to Control a DC Motor with L298N and PWN on a Web Server

July 14, 2023

ESP32 Getting Started Guide: Setup, Pinout and First Projects

May 26, 2026

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Available for Projects

Hire Us for IoT Development

End-to-end solutions for your needs:

  • → ESP32 & Embedded Systems
  • → LoRaWAN & Cloud Dashboards
  • → Custom Hardware Design
  • → IoT Product Prototyping
View Services →

Get Free Tutorials & Discounts!

Subscribe to get the latest IoT tutorials and exclusive hardware discount codes for KSP Electronics delivered directly to your inbox.

Follow Us
  • Instagram
  • Telegram
About Circuit of Things

We are a community-driven engineering platform dedicated to IoT, Robotics, and DIY electronics tutorials.

Proudly partnered with KSP Electronics.

Quick Links
  • Home
  • ESP32 Projects
  • Arduino Projects
  • IoT Tutorials
  • Sensors & Modules
  • Shop on KSP Electronics
  • Electro Calc
Legal & Support
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
📩

Get Free Tutorials & Discounts!

Subscribe for IoT tutorials and exclusive KSP discount codes.

Subscription Form


By subscribing, you agree to our Privacy Policy. No spam, ever.

X (Twitter) Instagram YouTube WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
© 2026 Circuit of Things. Designed by Sai Preetham Koyyala.

Type above and press Enter to search. Press Esc to cancel.