{"id":31605,"date":"2021-12-16T07:21:00","date_gmt":"2021-12-16T07:21:00","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=31605"},"modified":"2021-12-16T15:41:46","modified_gmt":"2021-12-16T15:41:46","slug":"what-is-mqtt-and-how-it-works","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/what-is-mqtt-and-how-it-works\/","title":{"rendered":"What is MQTT and How It Works"},"content":{"rendered":"\n<p>This article is an introduction to the MQTT protocol. MQTT stands for <strong>M<\/strong>essage <strong>Q<\/strong>ueuing <strong>T<\/strong>elemetry <strong>T<\/strong>ransport, a simple messaging protocol suitable for communication between IoT devices.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/What-is-MQTT-How-it-Works.jpg?resize=1024%2C576&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"What is MQTT and How it Works\" class=\"wp-image-108439\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/What-is-MQTT-How-it-Works.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/What-is-MQTT-How-it-Works.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/What-is-MQTT-How-it-Works.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/What-is-MQTT-How-it-Works.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"rntbox rntclgray\"><em>Updated 16 December 2021<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is MQTT?<\/h2>\n\n\n\n<p>MQTT stands for&nbsp;<strong>M<\/strong>essage<strong>&nbsp;Q<\/strong>ueuing<strong>&nbsp;T<\/strong>elemetry&nbsp;<strong>T<\/strong>ransport. MQTT is a simple messaging protocol, designed for constrained devices with low bandwidth. So, it\u2019s the perfect solution to exchange data between multiple IoT devices.<\/p>\n\n\n\n<p>MQTT communication works as a&nbsp;<em>publish&nbsp;<\/em>and&nbsp;<em>subscribe&nbsp;<\/em>system. Devices&nbsp;<em>publish&nbsp;<\/em>messages on a specific topic. All devices that are&nbsp;<em>subscribed&nbsp;<\/em>to that topic receive the message.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"268\" height=\"149\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/Publish-subscribe-MQTT.png?resize=268%2C149&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"MQTT Publish Subscribe\" class=\"wp-image-108443\"\/><\/figure><\/div>\n\n\n\n<p>Its main applications include sending messages to control outputs, read and publish data from sensor nodes and much more.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MQTT Basic Concepts<\/h2>\n\n\n\n<p>In MQTT there are a few basic concepts that you need to understand:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#publish-subscribe\">Publish\/Subscribe<\/a><\/li><li><a href=\"#messages\">Messages<\/a><\/li><li><a href=\"#topics\">Topics<\/a><\/li><li><a href=\"#broker\">Broker<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"publish-subscribe\">MQTT \u2013 Publish\/Subscribe<\/h2>\n\n\n\n<p>The first concept is the&nbsp;<em>publish and subscribe<\/em>&nbsp;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<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"743\" height=\"125\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/Publish-Subscribe-Topic-MQTT.png?resize=743%2C125&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Publish Subscribe Topic MQTT\" class=\"wp-image-108444\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/Publish-Subscribe-Topic-MQTT.png?w=743&amp;quality=100&amp;strip=all&amp;ssl=1 743w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/Publish-Subscribe-Topic-MQTT.png?resize=300%2C50&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 743px) 100vw, 743px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>For example <strong>Device 1 <\/strong>publishes on a topic.<\/li><li><strong>Device 2<\/strong> is subscribed to the same topic that <strong>device 1 <\/strong>is publishing in.<\/li><li>So, <strong>device 2 <\/strong>receives the message.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"messages\">MQTT \u2013 Messages<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"topics\">MQTT \u2013 Topics<\/h2>\n\n\n\n<p>Another important concept is the <em>topics<\/em>. Topics are the way you register interest for incoming messages or how you specify where you want to publish the message.<\/p>\n\n\n\n<p>Topics are represented with strings separated by a forward slash. Each forward slash indicates a topic level. Here\u2019s an example of how you would create a topic for a lamp in your home office:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"246\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=442%2C246&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-31609\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?w=442&amp;quality=100&amp;strip=all&amp;ssl=1 442w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=150%2C83&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=300%2C167&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=80%2C45&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=220%2C122&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=180%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 180w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=270%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 270w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/5mqtt-topics.jpg?resize=428%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 428w\" sizes=\"(max-width: 442px) 100vw, 442px\" \/><\/figure><\/div>\n\n\n\n<p><strong>Note:<\/strong> topics are case-sensitive, which makes these two topics different:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"188\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=300%2C188&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-31611\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=300%2C188&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=150%2C94&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=80%2C50&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=220%2C138&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=160%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 160w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/7case-sensitive-300x188.jpg?resize=239%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 239w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<p>If you would like to turn on a lamp in your home office using MQTT you can imagine the following scenario:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"384\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/MQTT-Publish-Subscribe-Example.png?resize=732%2C384&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"MQTT Publish Subscribe Example\" class=\"wp-image-108445\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/MQTT-Publish-Subscribe-Example.png?w=732&amp;quality=100&amp;strip=all&amp;ssl=1 732w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/09\/MQTT-Publish-Subscribe-Example.png?resize=300%2C157&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 732px) 100vw, 732px\" \/><\/figure><\/div>\n\n\n\n<ol class=\"wp-block-list\"><li>A device publishes \u201con\u201d and \u201coff\u201d messages on the&nbsp;<strong>home\/office\/lamp&nbsp;<\/strong>topic.<\/li><li>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:&nbsp;<strong>home\/office\/lamp<\/strong>.<\/li><li>So, when a new message is published on that topic, the ESP32 receives the \u201con\u201d or \u201coff\u201d messages and turns the lamp on or off.<\/li><\/ol>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"555\" height=\"247\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/device1.png?resize=555%2C247&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"mqtt-device\" class=\"wp-image-73562\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/device1.png?w=555&amp;quality=100&amp;strip=all&amp;ssl=1 555w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/device1.png?resize=300%2C134&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"broker\">MQTT \u2013 Broker<\/h2>\n\n\n\n<p>Finally, another important concept is the <em>broker<\/em>.<\/p>\n\n\n\n<p>The&nbsp;<strong>MQTT broker<\/strong>&nbsp;is responsible for&nbsp;<strong>receiving<\/strong>&nbsp;all messages,&nbsp;<strong>filtering<\/strong>&nbsp;the messages,&nbsp;<strong>deciding<\/strong>&nbsp;who is interested in them, and then&nbsp;<strong>publishing<\/strong>&nbsp;the message to all subscribed clients.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"303\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mqtt_broker.png?resize=750%2C303&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"mqtt-broker\" class=\"wp-image-73565\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mqtt_broker.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mqtt_broker.png?resize=300%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mqtt_broker.png?resize=250%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 250w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>There are several brokers you can use. In home automation projects, we use the&nbsp;<strong><a href=\"https:\/\/mosquitto.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mosquitto Broker<\/a><\/strong>&nbsp;installed on a&nbsp;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).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"197\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mosquitto-broker.png?resize=200%2C197&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-73566\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mosquitto-broker.png?w=200&amp;quality=100&amp;strip=all&amp;ssl=1 200w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/mosquitto-broker.png?resize=80%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 80w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/figure><\/div>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>To install Mosquitto broker on the Raspberry Pi follow our tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-mosquitto-broker-on-raspberry-pi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Mosquitto Broker on Raspberry Pi<\/a><\/li><\/ul>\n\n\n\n<p>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. Check the tutorial below:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/cloud-mqtt-mosquitto-broker-access-anywhere-digital-ocean\/\">Run Your Cloud MQTT Mosquitto Broker (access from anywhere using Digital Ocean)<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use MQTT in Home Automation and IoT Projects<\/h2>\n\n\n\n<p>MQTT is great for home automation and internet of things projects. Here&#8217;s an example of how it can be used in a <a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\">Home Automation System<\/a> built with low-cost development boards like a Raspberry Pi, ESP32, ESP8266, and Arduino.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"505\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/home-automation-mqtt-example.png?resize=750%2C505&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Home Automation System Example\" class=\"wp-image-73567\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/home-automation-mqtt-example.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/home-automation-mqtt-example.png?resize=300%2C202&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>A Raspberry Pi runs the Mosquitto broker, which is essential for MQTT protocol.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>The same Raspberry Pi runs Node-RED, which is a Home Automation Platform with MQTT support\u2014this 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.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Node-RED also allows you to build an User Interface with buttons to control outputs and charts to display sensor readings.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>The Arduino, the ESP32 and ESP8266 can act as MQTT clients that publish and subscribe to topics.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>These boards are connected to actuators like LEDs or relays, and sensors like temperature, humidity, smoke sensors, etc..<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>These boars can publish data about the sensor&#8217;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.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>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.<\/li><\/ul>\n\n\n\n<p>The following image shows an example of a Node-RED UI that allows you to control one output and displays temperature and humidity readings:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"517\" height=\"699\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/node-red-ui-output-temperature-humidity.png?resize=517%2C699&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-62621\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/node-red-ui-output-temperature-humidity.png?w=517&amp;quality=100&amp;strip=all&amp;ssl=1 517w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/node-red-ui-output-temperature-humidity.png?resize=222%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 222w\" sizes=\"(max-width: 517px) 100vw, 517px\" \/><\/figure><\/div>\n\n\n\n<p>Here&#8217;s a quick summary of the steps you should follow to build something as described previously:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Set up your Raspberry Pi. Follow our&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Getting Started Guide with Raspberry Pi<\/a>.<\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/\">Enable and Connect your Raspberry Pi with SSH<\/a>.<\/li><li>You need&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-node-red-on-raspberry-pi\/\">Node-RED installed on your Pi<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-node-red-dashboard\/\">Node-RED Dashboard<\/a>.<\/li><li>Install the <a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-mosquitto-broker-on-raspberry-pi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mosquitto broker on the Raspberry Pi<\/a>.<\/li><li>Add the ESP8266 or the ESP32 to this system. You can follow the next MQTT tutorials:<\/li><\/ol>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-mqtt-publish-subscribe-arduino-ide\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>ESP32<\/strong> and Node-RED with MQTT \u2013 Publish and Subscribe<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-and-node-red-with-mqtt\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>ESP8266<\/strong> and Node-RED with MQTT <\/a><a href=\"https:\/\/randomnerdtutorials.com\/esp32-mqtt-publish-subscribe-arduino-ide\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u2013<\/a><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-and-node-red-with-mqtt\/\" target=\"_blank\" rel=\"noreferrer noopener\"> Publish and Subscribe<\/a><\/li><\/ul>\n\n\n\n<p>If you want to learn more about these subjects, we have a dedicated course on how to create your own Home Automation System using Raspberry Pi, ESP8266, Arduino, and Node-RED. Just click the following link.<\/p>\n\n\n\n<p><a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\" target=\"_blank\" rel=\"noreferrer noopener\">&gt;&gt;<strong> Enroll in Build a Home Automation System for $100 &lt;&lt;<\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>MQTT is simple to use and it is great for Internet of Things and Home Automation projects. You can check all our <a href=\"https:\/\/randomnerdtutorials.com\/?s=mqtt\">MQTT-related tutorials here<\/a>.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful and you now understand what is MQTT and how it works.<\/p>\n\n\n\n<p>Thanks for reading. If you like this article, please support our work by <a href=\"https:\/\/randomnerdtutorials.com\/download\">subscribing to my blog<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the video tutorial below<\/h2>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/EIxdz-2rhLs?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we&#8217;re going to introduce you to the MQTT protocol. MQTT stands for Message Queuing Telemetry Transport. <\/p>\n<p class=\"read-more-container\"><a href=\"https:\/\/randomnerdtutorials.com\/what-is-mqtt-and-how-it-works\/\" class=\"read-more button\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":108439,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[304,214,265,240,225,282,273,264],"tags":[],"class_list":["post-31605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-home-automation","category-esp8266","category-esp8266-project","category-esp8266-projects","category-home-automation","category-mqtt","category-node-red","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/What-is-MQTT-How-it-Works.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/31605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=31605"}],"version-history":[{"count":3,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/31605\/revisions"}],"predecessor-version":[{"id":108450,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/31605\/revisions\/108450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/108439"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=31605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=31605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=31605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}