Close Menu
    What's Hot

    How to Auto Start a Program on Raspberry Pi? (4 Ways)

    8 September، 2024

    List of Best Hacking Software For Windows, Linux, and Mac OS X

    7 September، 2024

    The rpm command

    20 December، 2022

    Copy virtual machine to the new host

    20 December، 2022
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    keepuptechnologykeepuptechnology
    • Home
      • Linux
      • Network
      • raspberry pi
      • mqtt
      • esp8266
    • Linux

      List of Best Hacking Software For Windows, Linux, and Mac OS X

      7 September، 2024

      The rpm command

      20 December، 2022

      Copy virtual machine to the new host

      20 December، 2022

      Remove password from Virtual Machine Manager on Linux

      20 December، 2022

      How to create FAT32 USB drive on Linux

      20 December، 2022
    • Network

      Wifi Pineapple Mark V on TP-Link MR3020

      10 September، 2022
    • IOT
      • esp8266
      • mqtt
      • raspberry pi
    • All
      1. IOT
      2. raspberry pi
      3. Linux
      4. View All

      How to Auto Start a Program on Raspberry Pi? (4 Ways)

      8 September، 2024

      How to Install VMWare ESXi on a Raspberry Pi? (Step by step)

      20 December، 2022

      Getting started with Proxmox on Raspberry Pi (Virtualization server)

      20 December، 2022

      How To Create USB Rubber Ducky With Raspberry Pi Pico

      24 November، 2022

      How to Auto Start a Program on Raspberry Pi? (4 Ways)

      8 September، 2024

      How to Install VMWare ESXi on a Raspberry Pi? (Step by step)

      20 December، 2022

      Getting started with Proxmox on Raspberry Pi (Virtualization server)

      20 December، 2022

      How To Create USB Rubber Ducky With Raspberry Pi Pico

      24 November، 2022

      List of Best Hacking Software For Windows, Linux, and Mac OS X

      7 September، 2024

      The rpm command

      20 December، 2022

      Copy virtual machine to the new host

      20 December، 2022

      Remove password from Virtual Machine Manager on Linux

      20 December، 2022
    • Contact Us
    Subscribe
    keepuptechnologykeepuptechnology
    Home » What is MQTT and How It Works

    What is MQTT and How It Works

    0
    By admin on 18 September، 2022 mqtt
    Share
    Facebook Twitter LinkedIn Pinterest Email

    This article is an introduction to the MQTT protocol. MQTT stands for Message Queuing Telemetry Transport, a simple messaging protocol suitable for communication between IoT devices.

    What is MQTT?

    MQTT stands for Message Queuing Telemetry Transport. MQTT is a simple messaging protocol, designed for constrained devices with low bandwidth. So, it’s the perfect solution to exchange data between multiple IoT devices.

    MQTT communication works as a publish and subscribe system. Devices publish messages on a specific topic. All devices that are subscribed to that topic receive the message.

    MQTT Publish Subscribe

    Its main applications include sending messages to control outputs, read and publish data from sensor nodes and much more.

    MQTT Basic Concepts

    In MQTT there are a few basic concepts that you need to understand:

    • Publish/Subscribe
    • Messages
    • Topics
    • Broker

    MQTT – Publish/Subscribe

    The first concept is the publish and subscribe system. In a publish and subscribe system, a device can publish a message on a topic, or it can be subscribed to a particular topic to receive messages

    Publish Subscribe Topic MQTT
    • For example Device 1 publishes on a topic.
    • Device 2 is subscribed to the same topic that device 1 is publishing in.
    • So, device 2 receives the message.

    MQTT – Messages

    Messages are the information that you want to exchange between your devices. It can be a message like a command or data like sensor readings, for example.

    MQTT – Topics

    Another important concept is the topics. Topics are the way you register interest for incoming messages or how you specify where you want to publish the message.

    Topics are represented with strings separated by a forward slash. Each forward slash indicates a topic level. Here’s an example of how you would create a topic for a lamp in your home office:

    Note: topics are case-sensitive, which makes these two topics different:

    If you would like to turn on a lamp in your home office using MQTT you can imagine the following scenario:

    MQTT Publish Subscribe Example
    1. A device publishes “on” and “off” messages on the home/office/lamp topic.
    2. You have a device that controls a lamp (it can be an ESP32, ESP8266, or any other board or device). The ESP32 that controls your lamp, is subscribed to that same topic: home/office/lamp.
    3. So, when a new message is published on that topic, the ESP32 receives the “on” or “off” messages and turns the lamp on or off.

    The device that is publishing the messages can be an ESP32, an ESP8266, or an Home Automation controller platform with MQTT support like Node-RED, Home Assistant, Domoticz, or OpenHAB, for example.

    mqtt-device

    MQTT – Broker

    Finally, another important concept is the broker.

    The MQTT broker is responsible for receiving all messages, filtering the messages, deciding who is interested in them, and then publishing the message to all subscribed clients.

    mqtt-broker

    There are several brokers you can use. In home automation projects, we use the Mosquitto Broker installed on a Raspberry Pi. You can also install the Mosquitto broker on your PC (which is not as convenient as using a Raspberry Pi board, because you have to keep your computer running all the time to keep the MQTT connection between your devices).

    Having the Mosquitto broker installed on a Raspberry Pi on your local network allows you to exchange data between your IoT devices that are also connected to that same network.

    To install Mosquitto broker on the Raspberry Pi follow our tutorial:

    • Install Mosquitto Broker on Raspberry Pi

    You can also run Mosquitto MQTT broker in the cloud. Running the MQTT Mosquitto Broker in the cloud allows you to connect several IoT devices from anywhere using different networks as long as they have an Internet connection.

    How to Use MQTT in Home Automation and IoT Projects

    MQTT is great for home automation and internet of things projects. Here’s an example of how it can be used in a Home Automation System built with low-cost development boards like a Raspberry Pi, ESP32, ESP8266, and Arduino.

    Home Automation System Example
    • A Raspberry Pi runs the Mosquitto broker, which is essential for MQTT protocol.
    • The same Raspberry Pi runs Node-RED, which is a Home Automation Platform with MQTT support—this means it can subscribe to topics to receive messages from the other IoT devices, and publish messages on specific topics to send messages to other devices.
    • Node-RED also allows you to build an User Interface with buttons to control outputs and charts to display sensor readings.
    • The Arduino, the ESP32 and ESP8266 can act as MQTT clients that publish and subscribe to topics.
    • These boards are connected to actuators like LEDs or relays, and sensors like temperature, humidity, smoke sensors, etc..
    • These boars can publish data about the sensor’s state on a specific topic, that Node-RED is also subscribed to. This way, Node-RED receives the sensor readings and can display them on the user interface.
    • On the other side, Node-RED can publish data on a specific topic to control outputs when you use the buttons on the interface. The other boards are also subscribed to that topic and control the outputs accordingly.

    The following image shows an example of a Node-RED UI that allows you to control one output and displays temperature and humidity readings:

    Here’s a quick summary of the steps you should follow to build something as described previously:

    1. Set up your Raspberry Pi. Follow our Getting Started Guide with Raspberry Pi.
    2. Enable and Connect your Raspberry Pi with SSH.
    3. You need Node-RED installed on your Pi and Node-RED Dashboard.
    4. Install the Mosquitto broker on the Raspberry Pi.

    Wrapping Up

    MQTT is a communication protocol based on a publish and subscribe system. Devices can subscribe to a topic or publish data on a topic. Devices receive messages that are published on topics they are subscribed to.

    MQTT is simple to use and it is great for Internet of Things and Home Automation projects.

    Thanks for reading.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email
    Previous ArticleHow to Configure WiFi on Your Raspberry Pi
    Next Article Install Mosquitto MQTT Broker on Raspberry Pi
    admin
    • Website

    Related Posts

    Testing Mosquitto Broker and Client on Raspberry Pi

    18 September، 2022

    Install Mosquitto MQTT Broker on Raspberry Pi

    18 September، 2022
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Subscribe to Updates

    Get the latest sports news from SportsSite about soccer, football and tennis.

    Keep Up Technologies. Articles and topics to keep up with computer science and technology
    We're social. Connect with us:

    Facebook X (Twitter) Instagram Pinterest YouTube
    Top Insights
    Get Informed

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    © 2025 Makrof. Designed by Makrof.

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