{"id":31713,"date":"2022-06-10T09:02:00","date_gmt":"2022-06-10T09:02:00","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=31713"},"modified":"2023-06-30T15:18:09","modified_gmt":"2023-06-30T15:18:09","slug":"how-to-install-mosquitto-broker-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/how-to-install-mosquitto-broker-on-raspberry-pi\/","title":{"rendered":"Install Mosquitto MQTT Broker on Raspberry Pi"},"content":{"rendered":"\n<p>This tutorial shows how to install the Mosquitto Broker for MQTT communication on a Raspberry Pi board.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/Mosquitto-MQTT-Broker-Rpi.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install Mosquitto MQTT Broker on Raspberry Pi\" class=\"wp-image-108407\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/Mosquitto-MQTT-Broker-Rpi.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/Mosquitto-MQTT-Broker-Rpi.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/Mosquitto-MQTT-Broker-Rpi.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/Mosquitto-MQTT-Broker-Rpi.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><em>Updated 10 June 2022<\/em><\/p>\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 ESP32\/ESP8266 boards and other 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\">\n<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>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is an MQTT Broker?<\/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 <em>publish <\/em>and <em>subscribe <\/em>system. Devices <em>publish <\/em>messages on a specific topic. All devices that are <em>subscribed <\/em>to that topic receive the message.<\/p>\n\n\n\n<p>The <strong>MQTT broker<\/strong> is responsible for <strong>receiving<\/strong> all messages, <strong>filtering<\/strong> the messages, <strong>deciding<\/strong> who is interested in them, and then <strong>publishing<\/strong> the message to all subscribed clients.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" 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<p>There are several brokers you can use. In home automation projects, we use the <strong><a href=\"https:\/\/mosquitto.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mosquitto Broker<\/a><\/strong> installed on a&nbsp;Raspberry Pi. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"200\" height=\"197\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Eclipse-Mosquitto-logo.png?resize=200%2C197&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-67892\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Eclipse-Mosquitto-logo.png?w=200&amp;quality=100&amp;strip=all&amp;ssl=1 200w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Eclipse-Mosquitto-logo.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<p>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 alive).<\/p>\n\n\n\n<p class=\"rntbox rntclblue\">For a more detailed explanation of MQTT communication, check out this article: <a href=\"https:\/\/randomnerdtutorials.com\/what-is-mqtt-and-how-it-works\/\">What is MQTT and How It Works<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before continuing with this tutorial<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You should be familiar with the Raspberry Pi board \u2013&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\" target=\"_blank\" rel=\"noreferrer noopener\">read Getting Started with Raspberry Pi<\/a>;<\/li>\n\n\n\n<li>You should have the Raspberry Pi OS installed in your Raspberry Pi \u2013&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Raspberry Pi OS, Set Up Wi-Fi, Enable and Connect with SSH<\/a>;<\/li>\n\n\n\n<li>You also need the following hardware:\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/raspberry-pi-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">Raspberry Pi board<\/a>&nbsp;\u2013 read&nbsp;<a href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-3-starter-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Raspberry Pi Starter Kits<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\" rel=\"noreferrer noopener\">MicroSD Card \u2013 16GB Class10<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-power-supply\/\" target=\"_blank\" rel=\"noreferrer noopener\">Raspberry Pi Power Supply (5V 2.5A)<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<p>If you like home automation and you want to build a complete home automation system, I recommend downloading my <a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\">home automation course<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Mosquitto Broker on Raspberry Pi OS<\/h2>\n\n\n\n<p>After having your Raspberry Pi board prepared with Raspberry Pi OS, you can continue with this tutorial.&nbsp;<\/p>\n\n\n\n<p>Let\u2019s install the <strong><a href=\"http:\/\/mosquitto.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mosquitto Broker<\/a><\/strong>.<\/p>\n\n\n\n<p><strong>1)<\/strong> Open a new Raspberry Pi terminal window. If you&#8217;re running your Raspberry Pi headless, check this <a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/#connect-RPi-SSH\">tutorial to learn how to establish an SSH connection between your computer and the Raspberry Pi<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"573\" height=\"146\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/raspberry-pi-terminal-window.png?resize=573%2C146&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-73572\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/raspberry-pi-terminal-window.png?w=573&amp;quality=100&amp;strip=all&amp;ssl=1 573w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/raspberry-pi-terminal-window.png?resize=300%2C76&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 573px) 100vw, 573px\" \/><\/figure><\/div>\n\n\n<p><strong>2)<\/strong> Run the following command to upgrade and update your system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo apt update &amp;&amp; sudo apt upgrade<\/strong><\/code><\/pre>\n\n\n\n<p><strong>3)<\/strong> Press <strong>Y<\/strong> and <strong>Enter<\/strong>. It will take some time to update and upgrade (in my case, it took approximately 10 minutes).<\/p>\n\n\n\n<p><strong>4)<\/strong> To install the Mosquitto Broker enter these next commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em><strong>s<\/strong><\/em><strong>udo apt install -y mosquitto mosquitto-clients<\/strong><\/code><\/pre>\n\n\n\n<p><strong>5)<\/strong> To make Mosquitto auto start when the Raspberry Pi boots, you need to run the following command (this means that the Mosquitto broker will automatically start when the Raspberry Pi starts):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl enable mosquitto.service<\/strong><\/code><\/pre>\n\n\n\n<p><strong>6)<\/strong> Now, test the installation by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>mosquitto -v<\/strong><\/code><\/pre>\n\n\n\n<p>This returns the Mosquitto version that is currently running in your Raspberry Pi. It will be 2.0.11 or above.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"418\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/Mosquitto-check-installed-version.png?resize=661%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing Mosquitto MQTT broker Raspberry Pi\" class=\"wp-image-108402\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/Mosquitto-check-installed-version.png?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/Mosquitto-check-installed-version.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n<p>It will prompt the following message: &#8220;<em>Starting in local only mode. Connections will only be possible from clients running on this machine. Create a configuration file which defines a listener to allow remote access<\/em>.&#8221; <\/p>\n\n\n\n<p>This means that by default, you can\u2019t communicate with the Mosquitto broker from another device (other than your Raspberry Pi). This is applicable for Mosquitto version 2. More information about this topic on the <a href=\"https:\/\/mosquitto.org\/documentation\/migrating-to-2-0\/\">Mosquitto documentation<\/a>. <\/p>\n\n\n\n<p>&#8220;<em>In Mosquitto 2.0 and up, you must choose your authentication options explicitly before clients can connect. In earlier versions, the default is to allow clients to connect without authentication.<\/em>&#8220;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"remote-access\">Enable Remote Access\/ Authentication<\/h2>\n\n\n\n<p>To enable remote access so that we can communicate with other IoT devices, we need to edit\/create a configuration file.<\/p>\n\n\n\n<p>In this tutorial, we&#8217;ll cover:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#mosquitto-no-authentication\">No Authentication<\/a><\/li>\n\n\n\n<li><a href=\"#mosquitto-set-user-password\">Authentication with user and password<\/a><\/li>\n<\/ul>\n\n\n\n<p>Choose the section that is more suitable for your scenario. We also recommend taking a look at the <a href=\"https:\/\/mosquitto.org\/documentation\/authentication-methods\/\">documentation<\/a> for more details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mosquitto-no-authentication\">Mosquitto Broker Enable Remote Access (No Authentication)<\/h3>\n\n\n\n<p><strong>1)<\/strong> Run the following command to open the <span class=\"rnthl rntliteral\">mosquitto.conf<\/span> file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo nano \/etc\/mosquitto\/mosquitto.conf<\/strong><\/code><\/pre>\n\n\n\n<p>2<strong>)<\/strong> Move to the end of the file using the arrow keys and paste the following two lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>listener 1883<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>allow_anonymous true<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"418\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/mosquitto-configuration-file.png?resize=661%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Mosquitto configuration file to allow remote connections and anonymous users\" class=\"wp-image-108403\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/mosquitto-configuration-file.png?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/mosquitto-configuration-file.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n<p>&nbsp;<br><strong>3)<\/strong>&nbsp;Then, press&nbsp;<strong>CTRL-X<\/strong>&nbsp;to exit and save the file. Press&nbsp;<strong>Y<\/strong>&nbsp;and&nbsp;<strong>Enter<\/strong>.<br>&nbsp;<br><strong>4)<\/strong>&nbsp;Restart Mosquitto for the changes to take effect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mosquitto<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mosquitto-set-user-password\">Mosquitto Broker Enable Remote Access (Authentication: user and password)<\/h3>\n\n\n\n<p>You can add a user\/password authentication to your MQTT broker.<\/p>\n\n\n\n<p><strong>1)<\/strong> Run the following command, but replace <span class=\"rnthl rntliteral\">YOUR_USERNAME<\/span> with the username you want to use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo mosquitto_passwd -c \/etc\/mosquitto\/passwd YOUR_USERNAME<\/strong><\/code><\/pre>\n\n\n\n<p>I\u2019ll be using the MQTT user <span class=\"rnthl rntliteral\">sara<\/span>, so I run the command as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo mosquitto_passwd -c \/etc\/mosquitto\/passwd sara<\/strong><\/code><\/pre>\n\n\n\n<p>When you run the preceding command with the desired username, you\u2019ll be asked to enter a password. No characters will be displayed while you enter the password. Enter the password and&nbsp;<strong>memorize the user\/pass combination, you\u2019ll need it later<\/strong> in your projects to make a connection with the broker.<\/p>\n\n\n\n<p>This previous command creates a password file called <span class=\"rnthl rntliteral\">passwd<\/span> on the <span class=\"rnthl rntliteral\">\/etc\/mosquitto<\/span> directory.<\/p>\n\n\n\n<p>Now, we need to edit the mosquitto configuration file so that it only allows authentication with the username and password we&#8217;ve defined.<\/p>\n\n\n\n<p><strong>2)<\/strong> Run the following command to edit the configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo nano \/etc\/mosquitto\/mosquitto.conf<\/strong><\/code><\/pre>\n\n\n\n<p><strong>3)<\/strong> Add the following line at the top of the file (make sure it is at the top of the file, otherwise it won&#8217;t work):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>per_listener_settings true<\/code><\/pre>\n\n\n\n<p><strong>4)<\/strong> Add the following three lines to allow connection for authenticated users and tell Mosquitto where the username\/password file is located.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>allow_anonymous false\nlistener 1883\npassword_file \/etc\/mosquitto\/passwd<\/code><\/pre>\n\n\n\n<p>Your configuration file will look as follows (the new lines are in bold):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Place your local configuration in \/etc\/mosquitto\/conf.d\/\n#\n# A full description of the configuration file is at\n# \/usr\/share\/doc\/mosquitto\/examples\/mosquitto.conf.example\n\n<strong>per_listener_settings true\n<\/strong>\npid_file \/run\/mosquitto\/mosquitto.pid\n\npersistence true\npersistence_location \/var\/lib\/mosquitto\/\n\nlog_dest file \/var\/log\/mosquitto\/mosquitto.log\n\ninclude_dir \/etc\/mosquitto\/conf.d\n<strong>allow_anonymous false \nlistener 1883  \npassword_file \/etc\/mosquitto\/passwd<\/strong><\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"418\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/Mosquitto-broker-config-file-authentication-user-pass.png?resize=661%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Mosquitto broker configuration file authentication user pass\" class=\"wp-image-111746\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/Mosquitto-broker-config-file-authentication-user-pass.png?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/12\/Mosquitto-broker-config-file-authentication-user-pass.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n<p><strong>5)<\/strong> Press <strong>CTRL-X<\/strong>, then <strong>Y<\/strong>, and finally press <strong>Enter<\/strong> to exit and save the changes.<\/p>\n\n\n\n<p><strong>6)<\/strong> Restart Mosquitto for the changes to take effect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl restart mosquitto<\/strong><\/code><\/pre>\n\n\n\n<p>To check if Mosquitto is actually running, you can run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl status mosquitto<\/strong><\/code><\/pre>\n\n\n\n<p>Now, you have authentication with username and password enabled. Remember that everytime you want to communicate with the broker, you&#8217;ll need to provide the username and password.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Add More Users\/Change Password<\/h4>\n\n\n\n<p>To add more users to an existing password file, or to change the password for an existing user, leave out the&nbsp;<span class=\"rnthl rntliteral\">-c<\/span> argument:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mosquitto_passwd &lt;password file&gt; &lt;username&gt;<\/code><\/pre>\n\n\n\n<p>For example, if I want to change the password for the <span class=\"rnthl rntliteral\">sara<\/span> user and taking into account that the password file we created was called <span class=\"rnthl rntliteral\">passwd<\/span>, the command will be as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mosquitto_passwd \/etc\/mosquitto\/passwd sara<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Raspberry Pi IP Address<\/h2>\n\n\n\n<p>To use Mosquitto broker later in your projects, you&#8217;ll need to know the Raspberry Pi IP address. To retrieve your Raspberry Pi IP address, type the next command in your Pi Terminal window:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>hostname -I<\/strong><\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"146\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/raspberr-pi-ip-address.png?resize=542%2C146&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-73573\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/raspberr-pi-ip-address.png?w=542&amp;quality=100&amp;strip=all&amp;ssl=1 542w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/raspberr-pi-ip-address.png?resize=300%2C81&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 542px) 100vw, 542px\" \/><\/figure><\/div>\n\n\n<p>In our case, the Raspberry Pi IP address is&nbsp;<strong>192.168.1.144<\/strong>.&nbsp;Save your Raspberry Pi IP address because you&#8217;ll need it in future projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing Mosquitto Broker and MQTT Client<\/h2>\n\n\n\n<p>After installing the Mosquitto broker, you should test your installation. You can follow the next tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/testing-mosquitto-broker-and-client-on-raspbbery-pi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Testing Mosquitto Broker and Client on Raspbbery Pi<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>An MQTT broker is essential if you want to use the MQTT protocol in IoT projects. The MQTT broker receives all MQTT messages and forwards them to all subscribed clients. In this tutorial, you&#8217;ve learned how to install the Mosquitto broker on a Raspberry Pi. <\/p>\n\n\n\n<p>Like home automation? Learn more about Node-RED, Raspberry Pi, ESP8266, and Arduino&nbsp;with&nbsp;my course:&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\" target=\"_blank\" rel=\"noreferrer noopener\">Build a Home Automation System for $100<\/a>.<\/p>\n\n\n\n<p><strong>Do you have any questions?&nbsp;<\/strong><strong>Leave a comment down below!<\/strong><\/p>\n\n\n\n<p>Thanks for reading. If you like this post probably you might like my next ones, so please support me by <a href=\"https:\/\/randomnerdtutorials.com\/download\">subscribing to my blog<\/a>.<\/p>\n\n\n\n<p>Updated June 10, 2022<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post explains how to install the Mosquitto Broker on a Raspberry Pi. The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in it and then publishing the message to all subscribed clients. <\/p>\n<p class=\"read-more-container\"><a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-mosquitto-broker-on-raspberry-pi\/\" class=\"read-more button\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":108407,"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,301,225,282,283,284,264,268],"tags":[],"class_list":["post-31713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-home-automation","category-0-raspberrypi","category-home-automation","category-mqtt","category-mqtt-broker","category-mqtt-client","category-project","category-raspberry-pi-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/Mosquitto-MQTT-Broker-Rpi.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\/31713","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=31713"}],"version-history":[{"count":11,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/31713\/revisions"}],"predecessor-version":[{"id":132607,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/31713\/revisions\/132607"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/108407"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=31713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=31713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=31713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}