Welcome back to another video of how
to MQTT series in the last video
we discussed what MQTT is> how it
works? and how it was developed? we also
discussed the components of MQTT if
you haven't watched that video watch
that by clicking the link in the
description in this video we will be
installing the MQTT broker in Raspberry PI and use it locally this is the
cheapest broker you can have you can use
raspberry pi 4 or Raspberry Pi 0 which
is affordable yet powerful as we
discussed in the last video a broker is
the central part of the MQTT
network which is responsible for
receiving all the messages and then
forward the messages to the SUBSCRIBE
devices the broker is also responsible
for deciding which message to send to
which devices as it already has
information of devices that is devices
have already subscribed to different
topics we will be installing the
mosquitto broker which is an open source
message broker that implements the
MQTT protocol versions 5.0 and 3.1 if
you haven't subscribed high voltages do
it now and press the bell icon so you
can get notification whenever I post a new
video before starting you will need
to boot SD card with Raspbian OS and
plug the card in Raspberry Pi and boot it. Let's get started
I am accessing my Raspberry Pi using VNC
viewer you can attach a keyboard and a
mouse and LCD or you can connect with
VNC
after booting it up open terminal and
type sudo apt-get update that will
update your pi
and then type
sudo apt install - y mosquitto mosquitto-clients
this
will install the broker
now to make it run automatically on
boot type
sudo systemctl enable mosquito.service
we are good to go
now
you can check the installation by typing
mosquito - V it will return the version
of the broker installed on your pi.
now let's run the mosquito service on
background by typing mosquito - d
now we can test the broker by
subscribing to our topic
so we will open a terminal window and
type
mosquito_sub -d -t Highvoltages
high voltages is a topic
so now let's publish something on a
topic we will open another window and
type
mosquito_pub -d - t Highvoltages -m "Hello world!"
in inverted commas hello world in inverted commas is
the message when you will press enter
you will see the message in the first
window so it works now let's download
MQTT explorer and access the MQTT
broker locally from our laptop so
I will download the MQTT Explorer
you can get the link from the
description and after downloading the
MQTT Explorer open it and enter the
credentials host will be the IP address
of your Raspberry Pi
and port will be 1883 currently the
broker is not password protected so we
will leave the password and username and
we will connect after connecting we will
enter the topic name and we will enter
the message
when we will hit the publish you can see
the message on Raspberry Pi let's try it
again
okay now let's make our broker protected
by giving a username and password we can
set the username and password by typing
mosquitto_passwd -c passwordfile pi
and we will enter username I'm entering PI and it
will ask us for the password and we can
enter the password it will ask you to
retype the password and your broker is
protected now now let's check our broker
from our laptop again make sure PI and
PC are on the same network and now we
can access the mosquito broker using
username and password so now we will
enter host for username and password and
then we will it connect after connecting
we can publish messages so that's it
thank you for watching please like share
and subscribe for more such videos
