Reader small image

You're reading from  Raspberry Pi and MQTT Essentials

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803244488
Edition1st Edition
Right arrow
Author (1)
Dhairya Parikh
Dhairya Parikh
author image
Dhairya Parikh

Dhairya Parikh is an Electronics Engineer who currently works as a Data Engineer at Accenture. He has a year’s experience in building and maintaining data pipelines for a huge amount of data. In his free time, he builds IoT and Machine Learning projects and even writes about them. He has written several project articles for Circuit Cellar, which is a monthly tech magazine. He makes projects which positively impacts the society, making people’s life easier.
Read more about Dhairya Parikh

Right arrow

Preface

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.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Raspberry-Pi-and-MQTT-Essentials. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/860jg.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system.”

A block of code is set as follows:

void setup ()
{
  pinMode (LED_BUILTIN, OUTPUT);
}

Any command-line input or output is written as follows:

sudo apt install mosquitto mosquitto-clients

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Select System info from the Administration panel.”

Tips or Important Notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Raspberry Pi and MQTT Essentials, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi and MQTT Essentials
Published in: Sep 2022Publisher: PacktISBN-13: 9781803244488
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Dhairya Parikh

Dhairya Parikh is an Electronics Engineer who currently works as a Data Engineer at Accenture. He has a year’s experience in building and maintaining data pipelines for a huge amount of data. In his free time, he builds IoT and Machine Learning projects and even writes about them. He has written several project articles for Circuit Cellar, which is a monthly tech magazine. He makes projects which positively impacts the society, making people’s life easier.
Read more about Dhairya Parikh