Print

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 raspberrypi.org
Download, install and launch “BalenaEtcher” on balena.io/etcher
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
update_config=1
country=FR
network={
ssid="SSID"
psk="PASSWORD"
key_mgmt=WPA-PSK
}

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)

Reboot

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