This codelab introduces the fundamental concepts of the Internet of Things (IoT), its real-world applications, and how to set up an MQTT broker using Mosquitto. You will also learn how to subscribe to and publish messages on MQTT topics and watch me demonstrate a simple IoT project.
The Internet of Things (IoT) is the network of physical objects or "things" embedded with electronics, software, sensors, and network connectivity, which enables these objects to collect and exchange data.

IoT is transforming many industries with innovative applications. Here are a few examples:
MQTT (Message Queuing Telemetry Transport) is a lightweight protocol designed for IoT. It follows a Publish/Subscribe model:
Follow the instructions in the relevant section to download and install the broker. The categories of the lab will include the instructions for Linux and Windows but for more operating systems, visit the Mosquitto Website
Install Mosquitto on Linux using the following command:
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients
Install Mosquitto on Windows using the following steps:
We would be using the mosquitto_sub command to subscribe to a topic. Use the following command to subscribe to a topic called "test"
mosquitto_sub -i 813117992 -t "test" -d
The flags passed are as follows:
i – Client id. If this parameter is not passed, client ID is generated automatically.
t – Name of the topic to subscribe to.
d – Enables printing of debug messages.
h – Hostname (optional). THis defaults to localhost
p – Port (optional, note the lowercase p). This defaults to 1884
u – username. Username (optional). Only used if auth is required
P – password. Password (optional, note the uppercase p). Only used if auth is required
# Example of a full command with all parameters
mosquitto_sub -i 813117992 -t "test" -d -h 192.168.100.223 -p 2534 -u kwasi -P password123
We would be using the mosquitto_pub command to publish a message on a topic. Use the following command to publish to a topic called "test"
mosquitto_pub -i 813117992 -t "test" -m "Test yesterday was so EZ. We cooked" -d
The flags passed are as follows:
i – Client id. If this parameter is not passed, the server generates client ID automatically.
t – Name of the topic to which the message is published.
m – Text payload of the message to be published.
d – Enables printing of debug messages.
h – Hostname (optional). THis defaults to localhost
p – Port (optional, note the lowercase p). This defaults to 1884
u – username. Username (optional). Only used if auth is required
P – password. Password (optional, note the uppercase p). Only used if auth is required
# Example of a full command with all parameters
mosquitto_pub -i 813117992 -t "test" -m "Nah bro. I'm cooked fr." -d -h 192.168.100.223 -p 2534 -u kwasi -P password123