Installing MOSQUITTO


At this moment it is a little troublesome to come up with a working procedure.
During testing of the procedure I put together in the past it turned out that Rasbian version Stretch is not 100% OK for the installation procedure for earlier versions.

Procedure to install Mosquito as used for versions of Raspbian upto including "Jessie"


Remote log in to your Raspi on which Rocrail already has been installed.


To use the new mosquitto repository first import the repository package signing key:
sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key

cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients python-mosquitto

As with most Debian packages, the broker is immediately started; stop it.
sudo /etc/init.d/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 as follows:
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 the “log_dest” line to:
log_dest topic
This puts the logging information as a “topic” so we can subscribe to it later on to see what is going on in our system.
Next add the next six lines:

log_type error
log_type warning
log_type notice
log_type information

connection_messages true
log_timestamp true


Now your /etc/mosquitto.conf files should 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:

sudo /etc/init.d/mosquitto start

Testing the Mosquitto server


Open up two more terminal windows.

In Terminal window 1 type:
mosquitto_sub -d -t hello/world

In Terminal window 2 type:
mosquitto_pub -d -t hello/world -m “Hello from Terminal window 2!”

When you have done the second statement you should see the message in the Terminal 1 window.

Changing hostname:


Log in on the Raspi and follow these steps:
sudo nano /etc/hostname
change “raspberry” into new name
save

Setting a static IP address



Edit /etc/dhcpcd.conf as follows:
sudo nano /etc/dhcpcd.conf
ad the following lines:

interface eth0
static ip_address=10.1.1.30/24
static routers=10.1.1.1
static domain_name_servers=10.1.1.1

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


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

Save and reboot



Personal Tools