The future of IoT has the potential to be limitless. By 2025, it is estimated that there will be more
than 21 billion IoT devices. So, wouldn’t it be great if you could add these to your known
technological stacks? But where to start? Of course, with the basics.
First, we will learn about the most popular hardware used for IoT prototyping, the Raspberry Pi.
Then, we will learn what MQTT, one of the most used communication protocols for
communicating between devices, is. We will then explore why these are the most suitable options
to get started, their advantages, and how they are currently being used in the industry. Then, you
will see how to use them together by setting up your very own MQTT Server on the Raspberry Pi
and understanding how it works. We will get into the details of MQTT and learn more about the
clients or devices we will connect to our server. In particular, we will cover two very popular IoT
development boards among project developers: ESP8266 and ESP32. You will also learn how to
build interactive dashboards on your Pi and control or monitor your client devices. You will build
the dashboards using another popular software – Node-RED.
You will then put your theory into practical use by creating two full-scale projects: an IoT weather
station and a smart relay system. That’s not all; you will also learn how to host your very own
MQTT server on a virtual cloud service. Then you will be guided on the next steps to take after
reading this book, what technologies to learn along with some useful project recommendations.
Finally, we will cover the popular cloud platforms (AWS and GCP) to create IoT projects and also
create a project where we connect our Node MCU to AWS IoT.
Who this book is for
This book is suitable for a wide range of audiences. Particularly, this book is targeted at students
who want to start building IoT projects, educators who want to teach an introductory IT course,
technology enthusiasts, and IoT and hardware developers.
What this book covers
Chapter 1, Introduction to Raspberry PI and MQTT, provides an introduction to the hardware we
will be using, the Raspberry Pi. Moreover, it will also cover the basics of MQTT and how the
communication protocol actually works. Next, we will learn to set up the Raspberry Pi. This
includes installing the popular Debian-based Raspberry Pi OS on our Raspberry Pi. After that, we
will install the necessary libraries and packages to make our device a local MQTT broker.
Chapter 2, MQTT in Detail, covers how exactly MQTT works. This includes a gentle introduction
to MQTT brokers and clients, and different MQTT control packets will be covered in detail.
Finally, we will see a demonstration of how a client connects and communicates with a broker.
,Chapter 3, Introduction to ESP Development Boards, is all about implementing what we learned
in the previous chapter. It will first introduce you to the popular ESP development boards –
NodeMCU and ESP32. After covering the specifications of each board, we will move on to learn
how to set up the boards as an MQTT client. Finally, we will create our first project wherein we
will connect to our Raspberry Pi’s MQTT broker and control the onboard LED through MQTT.
Chapter 4, Node-RED on Raspberry Pi, gets you acquainted with very popular software for the
Raspberry Pi – Node-RED. It is divided into four sections. First is an introduction to Node-RED,
followed by a guide to installing and setting up Node-RED on Raspberry Pi. After that, we will
cover the Node-RED MQTT and dashboard components, and then create a simple project to
implement everything we have learned.
Chapter 5, Major Project 1: IoT Weather Station, is where, now that we have the knowledge from
all the topics discussed in the previous chapters, we will be working on our first major project:
making an IoT weather station. This chapter provides step-by-step instructions on how to build
this.
Chapter 6, Major Project 2: Smart Home Control Relay System, helps you create a smart home
device to control wall switches using the Node-RED dashboard hosted on the Raspberry Pi. The
device will be based on the popular ESP32 development board. For this project, we will be
preparing a PCB instead of creating the circuit on a breadboard for a more finished and professional
look.
Chapter 7, Taking Your MQTT Broker Global, is where we will discuss the advantages of having
an online MQTT broker further, and two major options that we currently have to achieve these
advantages. We can still use the local broker on our Pi, but we can route all the data to any
destination through the internet.
Chapter 8, Project Prototype to Product, How?, starts by exploring IoT services provided by some
popular cloud services, such as AWS and GCP, now that the book has covered all the essentials
required to get you familiar with all the concepts related to Raspberry Pi and MQTT. We will even
create a project demo integrating our Node MCU board with AWS IoT.
To get the most out of this book
This book has been written for beginners, so in terms of knowledge, there are no prerequisites. As
for the hardware, you will need all the hardware devices listed in the following table in order to
follow along and build projects with me. In terms of software requirements, you will need the
Raspberry Pi Imager software (available for all three major operating systems) to create flashed
SD cards for your Pi (it even supports SD card formatting), Wireshark on the Raspberry Pi OS to
dissect the MQTT control packets, and Node-RED as a dashboard interface for our projects, also
to be installed on Raspberry Pi OS.
, Part 1:Covering the Basics
After completing this section, you will know all about Raspberry Pi, MQTT, NodeMCU, ESP32
development boards, and Node-RED. You will gain the knowledge required to build intermediate-
complexity projects.
This part comprises of the following chapters:
Chapter 1, Introduction to Raspberry PI and MQTT
Chapter 2, MQTT in Detail
Chapter 3, Introduction to ESP Development Boards
Chapter 4, Node-RED on Raspberry Pi
1
Introduction to Raspberry Pi and MQTT
In recent years, the Internet of Things (IoT) has been a trending field for research and
development. The future of IoT has the potential to be limitless. By 2025, it is estimated that there
will be more than 21 billion IoT devices. So, wouldn’t it be great if you could add these to your
known technological stacks? In this book, we will start with the absolute basics.
I will walk you through two fascinating subjects throughout this book: Raspberry Pi, which is a
prevalent development board for beginners, and MQTT, a very commonly used and robust
communication protocol to delve into the world of IoT.
This chapter will introduce you to the basics of MQTT and Raspberry Pi. Moreover, it will help
you set up your Raspberry Pi. Although simple, it is crucial to perform each step as this will help
us set up our own local MQTT broker on the Raspberry Pi. This will also help you understand
how to get started with your new Raspberry Pi by installing an operating system onto it.
First, we will flash the popular Debian-based Raspberry Pi OS on our Raspberry Pi. After that, we
will install all the necessary libraries and packages to make our device a local MQTT broker.
We will cover the following main topics in this chapter:
What is MQTT and how does it work?
A gentle introduction to Raspberry Pi