Installing MOSQUITTO


Start with a fresh install


Download the Raspbian image and transfer it to an SD card.

Boot the Raspi.

Login to your Wifi network. Note down the allocated IP-address.

Open “Raspberry Pi configuration”. If required change “hostname” on tab “System”. Activate “SSH” on tab “Interfaces”. On tab “Localisation” adjust settings to your needs.

Reboot.

Login remotely to your Raspi using the IP-address you noted down.

Apply the command “sudo apt-get install mosquitto mosquitto-clients”.

Stop Mosquitto with “sudo service mosquitto stop”.

Configuring and Starting the Mosquitto Server


Before using Mosquitto, we need to set up the configuration file. The configuration files is located at /etc/mosquitto.

Open the file with “sudo nano /etc/mosquitto/mosquitto.conf”

You should see the following:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
  
pid_file /var/run/mosquitto.pid
  
persistence true
persistence_location /var/lib/mosquitto/
  
log_dest file /var/log/mosquitto/mosquitto.log
  
include_dir /etc/mosquitto/conf.d


Change your /etc/mosquitto.conf file to look like:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
include_dir /etc/mosquitto/conf.d 



Now start the mosquitto server with “sudo service mosquitto start”

Testing the Mosquitto server



In the already open Terminal window 1 insert:
mosquitto_sub -d -t hello/world

Open a second terminal session with your raspi and insert:
mosquitto_pub -d -t hello/world -m “Hello from Terminal window 2!”

You should see the message in the Terminal 1 window.

Setting a static IP address



Edit /etc/dhcpcd.conf with “sudo nano /etc/dhcpcd.conf”
ad the following lines:

interface wlan0
static ip_address=192.168.2.254
static routers=192.168.2 .1
static domain_name_servers=192.168.2 .1


static ip_address is the IP-address planned for mosquitto on your WiFi network,
static routers is the address of your router (or gateway).
static domain_name_servers is the DNS address(es) from /etc/resolv.conf. (mostly the same as your static routers IP-address)

Save and reboot


To update your freshly installed Raspi login remotely and apply “sudo apt-get update” followed by “sudo apt-get upgrade”.

That is all.


Personal Tools