How to install Raspberry Pi OS (Raspbian)
+ Mosquitto MQTT Broker on a RaspBerry Pi


This tutorial is useful for setup a local MQTT Broker for testing our

You can also chose a MQTT Broker on Internet or an Android app like MQTT Broker.

Install Raspberry Pi OS Lite

Download “Raspberry Pi OS Lite” on
Download, install and launch “BalenaEtcher” on
Insert your Micro SD-Card in your PC
Flash the “Raspberry Pi OS Lite” on your SD-Card with Balena Etcher

Opening of SSH access

Open “boot” disk/directory of your SD-Card (Re-insert the SD-Card if you can see “boot”)
Add in “boot” an empty text file and name it “ssh”

Setting up a WiFi connection

Add in “boot” a text file and name it “wpa_supplicant.conf”
Open it and write inside:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

Replace SSID and PASSWORD with your own

With RaspBerry

Eject and insert your SD-Card in your RaspBerry Zero
Power on your RaspBerry Zero and wait its connection to your WiFi
Search your RaspBerry IP address on your network (you can use Angry IP Scanner)
Download, install and launch PuTTY for SSH access
SSH connection to your RaspBerry IP address
Login=pi Password=raspberry
Enter the commands: passwd for change the password of you RaspBerry

Install Mosquitto Broker

Enter the commands: sudo apt-get install mosquitto and confirm installation
Enter the commands: systemctl status mosquitto for check the Mosquitto MQTT installation

Change the HostName (Optional)

If you want to change the RaspBerry hostname:
Enter the commands: sudo nano /etc/hosts
With keyboard, replace “raspberry” text by another one (without special characters)
Ctrl+X + Y + Enter for save the file
Enter the commands: sudo nano /etc/hostname
With keyboard, replace “raspberrypi” text by another one (without special characters)


Enter the commands: “sudo reboot” for reboot !

Add a Password to the MQTT Broker

Replace USER by your username in this commands and execute: sudo mosquitto_passwd -c /etc/mosquitto/passwd USER for add a password to MQTT Broker
It will ask the new password
Enter the commands: sudo nano /etc/mosquitto/mosquitto.conf and add these lines:
allow_anonymous false
password_file /etc/mosquitto/passwd

Ctrl+X + Y + Enter for save the file
Enter the commands: systemctl restart mosquitto to take into account the parameters
It will ask you for your password for user “pi” (which you changed in the “With RaspBerry” section)

Connect a MQTT Client

You can use MQTT Explorer as MQTT Client

Host = Raspberr IP addres (Use AngryIP to find the IP address of your Raspberry)
Port = 1883
Username = USER you have chosen in the previous section
Password = PASSWORD that you also chose in the previous section

Note: Lifetime of SD cards

The life of SD cards is limited to between 10,000 and 100,000 writes! And your Raspberry Pi OS Lite and MQTT Server work ONLY on this card!

Don’t neglect the quality of the SD card in your Raspberry Pi!

Example of start-up test:

  • Samsung EVO 16 GB Card Class (10): 25 seconds
  • Unbranded 8GB Class (4): 2 minutes 35 seconds

It is for these reasons that the use of a classic Raspberry in an industrial / production environment is not recommended.

Note: Cloning your SD card

It is important to have a backup of your SD card. In case of failure, you will be very happy to have it 😊