27,59 €
Explore the features included in the latest versions of MQTT for IoT and M2M communications and use them with modern Python 3.
MQTT is a lightweight messaging protocol for small sensors and mobile devices. This book explores the features of the latest versions of MQTT for IoT and M2M communications, how to use them with Python 3, and allow you to interact with sensors and actuators using Python.
The book begins with the specific vocabulary of MQTT and its working modes, followed by installing a Mosquitto MQTT broker. You will use different utilities and diagrams to understand the most important concepts related to MQTT. You will learn to make all the necessary configuration to work with digital certificates for encrypting all data sent between the MQTT clients and the server. You will also work with the different Quality of Service levels and later analyze and compare their overheads.
You will write Python 3.x code to control a vehicle with MQTT messages delivered through encrypted connections (TLS 1.2), and learn how leverage your knowledge of the MQTT protocol to build a solution based on requirements. Towards the end, you will write Python code to use the PubNub cloud-based real-time MQTT provider to monitor a surfing competition.
In the end, you will have a solution that was built from scratch by analyzing the requirements and then write Python code that will run on water-proof IoT boards connected to multiple sensors in surfboards.
This book is for developers who want to learn about the MQTT protocol for their IoT projects. Prior knowledge of working with IoT and Python will be helpful.
Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. Gaston has a bachelor's degree in computer science (graduated with honors) and an MBA. He is the CTO of Mapgenix, a freelance author, and a speaker. He has been a senior contributing editor at Dr. Dobb's and has written more than a hundred articles on software development topics. He has received the prestigious Intel® Black Belt Software Developer award eight times. He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 270
Veröffentlichungsjahr: 2018
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Kunal ChoudhariAcquisition Editor: Reshma RamanContent Development Editor: Aditi GourTechnical Editor: Sushmeeta JenaCopy Editor: Safis EditingProject Coordinator: Hardik BhindeProofreader: Safis EditingIndexer: Tejal Daruwale SoniGraphics: Jason MonteiroProduction Coordinator: Shraddha Falebhai
First published: May 2018
Production reference: 1180518
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78913-854-2
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and, as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. Gaston has a bachelor's degree in computer science (graduated with honors) and an MBA. He is the CTO of Mapgenix, a freelance author, and a speaker.
He has been a senior contributing editor at Dr. Dobb's and has written more than a hundred articles on software development topics. He has received the prestigious Intel® Black Belt Software Developer award eight times.
He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.
Acknowledgements:
Ben Howes is the founder and lead consultant at Zoetrope Ltd, a specialist IoT consultancy and product development firm in the UK. Ben has been creating connected hardware for over 10 years and has worked across projects spanning from start-ups to multinational deployments.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Hands-On MQTT Programming with Python
Packt Upsell
Why subscribe?
PacktPub.com
About the Author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Installing an MQTT 3.1.1 Mosquitto Server
Understanding convenient scenarios for the MQTT protocol
Working with the publish-subscribe pattern
Working with message filtering
Understanding the MQTT puzzle – clients, servers, and connections
Installing a Mosquitto server on Linux
Installing a Mosquitto server on macOS
Installing a Mosquitto server on Windows
Considerations for running a Mosquitto server in the cloud
Test your knowledge
Summary
Using Command-Line and GUI Tools to Learn How MQTT Works
Subscribing to topics with a command-line tool
Subscribing to topics with a GUI tool
Publishing messages with a command-line tool
Publishing messages with a GUI tool
Unsubscribing from topics with a GUI tool
Learning best practices for topics
Understanding MQTT wildcards
Learning about the different QoS levels
Working with at least once delivery (QoS level 1)
Working with exactly once delivery (QoS level 2)
Understanding overhead in the different Quality of Service levels
Test your knowledge
Summary
Securing an MQTT 3.1.1 Mosquitto Server
Understanding the importance of securing a Mosquitto server
Generating a private certificate authority to use TLS with Mosquitto
Creating a certificate for the Mosquitto server
Configuring TLS transport security in Mosquitto
Testing the MQTT TLS configuration with command-line tools
Testing the MQTT TLS configuration with GUI tools
Creating a certificate for each MQTT client
Configuring TLS client certificate authentication in Mosquitto
Testing the MQTT TLS client authentication with command-line tools
Testing the MQTT TLS configuration with GUI tools
Forcing the TLS protocol version to a specific number
Test your knowledge
Summary
Writing Code to Control a Vehicle with Python and MQTT Messages
Understanding the requirements to control a vehicle with MQTT
Defining the topics and commands
Creating a virtual environment with Python 3.6.x and PEP 405
Understanding the directory structure for a virtual environment
Activating the virtual environment
Deactivating the virtual environment
Installing paho-mqtt for Python
Connecting a client to the secured MQTT server with paho-mqtt
Understanding callbacks
Subscribing to topics with Python
Configuring certificates for IoT boards that will work as clients
Creating a class to represent a vehicle
Receiving messages in Python
Working with multiple calls to the loop method
Test your knowledge
Summary
Testing and Improving Our Vehicle Control Solution in Python
Processing commands with Python
Sending messages with Python
Working with the network loop with Python
Working with last will and testament with Python
Working with retained last will messages
Understanding blocking and non-blocking code
Using the threaded client interface
Test your knowledge
Summary
Monitoring a Surfing Competition with Cloud-Based Real-Time MQTT Providers and Python
Understanding the requirements
Defining the topics and payloads
Coding a surfboard sensor emulator
Configuring the PubNub MQTT interface
Publishing data retrieved from sensors to the cloud-based MQTT server
Working with multiple MQTT servers
Running multiple clients
Building a web-based dashboard with freeboard
Test your knowledge
Summary
Solutions
Chapter 1: Installing an MQTT 3.1.1 Mosquitto server
Chapter 2: Using Command-Line and GUI Tools to Learn How MQTT Works
Chapter 3: Securing an MQTT 3.1.1 Mosquitto Server
Chapter 4: Writing Code to Control a Vehicle with Python and MQTT Messages
Chapter 5: Testing and Improving our Vehicle Control Solution in Python
Chapter 6:  Monitoring a Surfing Competition with Cloud-Based Real-Time MQTT Providers and Python
Other Books You May Enjoy
Leave a review - let other readers know what you think
MQTT is the preferred IoT publish-subscribe lightweight messaging protocol. Python is definitely one of the most popular programming languages. It is open source, multiplatform, and you can use it to develop any kind of application. If you develop IoT, web applications, mobile apps, or a combination of these solutions, you must learn how MQTT and its lightweight messaging system works. The combination of Python and MQTT makes it possible to develop powerful applications that communicate with sensors, different devices, and other applications. Of course, it is extremely important to take security into account when working with this protocol.
Most of the time, when you work with complex IoT solutions coded in modern Python 3.6, you will use different IoT boards that might use diverse operating systems. MQTT has its own specific vocabulary and different working modes. Learning MQTT is challenging, because it includes too many abstract concepts that require real-life examples to be easy to understand.
This book will allow you to dive deep in to the latest version of the MQTT protocol: 3.1.1. You will learn to work with the most recent Mosquitto MQTT server, command-line tools, and GUI tools to allow you to understand how everything works with MQTT and the possibilities that this protocol provides for your projects. You will learn security best practices and use them for a Mosquitto MQTT server. Then, you will work with many real-life examples in Python 3.6. You will control a vehicle, process commands, interact with actuators, and monitor a surf competition by exchanging MQTT messages with the Eclipse Paho MQTT client library. You will also work with a cloud-based, real-time MQTT provider.
You will be able to run the examples on a wide range of modern IoT boards, such as Raspberry Pi 3 Model B+, Qualcomm DragonBoard 410c, BeagleBone Black, MinnowBoard Turbot Quad-Core, LattePanda 2G, and UP Core 4GB. However, any other board that supports Python 3.6 will be able to run the samples.
This book is aimed at Python developers who want to develop applications that can interact with other applications and devices, such as IoT boards, sensors, and actuators.
Chapter 1, Installing an MQTT 3.1.1 Mosquitto Server, starts our journey toward the usage of the preferred IoT publish-subscribe lightweight messaging protocol in diverse IoT solutions, combined with mobile apps and web applications. We will learn how MQTT and its lightweight messaging system work. We will understand the MQTT puzzle: clients, servers (formerly known as brokers), and connections. We will learn the procedures to install an MQTT 3.1.1 Mosquitto server in Linux, macOS, and Windows. We will learn special considerations for running a Mosquitto server on the Cloud (Azure, AWS, and other cloud providers).
Chapter 2, Using Command-Line and GUI Tools to Learn How MQTT Works, teaches us to work with command-line and GUI tools to learn how MQTT works in detail. We will learn MQTT basics, the specific vocabulary for MQTT, and its working modes. We will use different utilities and diagrams to understand the most important concepts related to MQTT. We will understand everything we need to know before writing Python code to work with the MQTT protocol. We will work with the different Quality of Service levels, and we will analyze and compare their overheads.
Chapter 3, Securing an MQTT 3.1.1 Mosquitto Server, focuses on how to secure an MQTT 3.1.1 Mosquitto server. We will make all the necessary configurations to work with digital certificates to encrypt all the data sent between the MQTT clients and the server. We will use TLS, and we will learn to work with client certificates for each MQTT client. We will also learn to force the desired TLS protocol version.
Chapter 4, Writing Code to Control a Vehicle with Python and MQTT Messages, focuses on writing Python 3.x code to control a vehicle with MQTT messages delivered through encrypted connections (TLS 1.2). We will write code that will be able to run on different popular IoT platforms, such as a Raspberry Pi 3 board. We will understand how we can leverage our knowledge of the MQTT protocol to build a solution based on requirements. We will learn to work with the latest version of the Eclipse Paho MQTT Python client library.
Chapter 5, Testing and Improving Our Vehicle Control Solution in Python, outlines using our vehicle control solution with MQTT messages and Python code. We will learn how to process commands received in MQTT messages with Python code. We will write Python code to compose and send MQTT messages with commands. We will work with the blocking and threaded network loops, and we will understand the difference between them. Finally, we will take advantage of the last will and testament feature.
Chapter 6, Monitoring a Surfing Competition with Cloud-Based Real-Time MQTT Providers and Python, gets you started with writing Python code to use the PubNub cloud-based, real-time MQTT provider in combination with a Mosquitto MQTT server to monitor a surfing competition. We will build a solution from scratch by analyzing the requirements, and we will write Python code that will run on waterproof IoT boards connected to multiple sensors in surfboards. We will define the topics and commands, and we will work with a cloud-based MQTT server, in combination with the Mosquitto MQTT server used in the previous chapters.
Appendix, Solutions, the right answers for the Test Your Knowledge sections of each chapter are included in the appendix.
You need a basic knowledge of Python 3.6.x and IoT boards.
You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packtpub.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-MQTT-Programming-with-Python. In case there's an update to the code, it will be updated on the existing 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!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/HandsOnMQTTProgrammingwithPython_ColorImages.pdf.
There are a number of text conventions used throughout this book.
CodeInText: 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:
@staticmethod def on_subscribe(client, userdata, mid, granted_qos): print("I've subscribed with QoS: {}".format( granted_qos[0]))
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
time.sleep(0.5)
client.disconnect()
client.loop_stop()
Any command-line input or output is written as follows:
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
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/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
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 [email protected] 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.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
In this chapter, we will start our journey toward using the preferred IoT publish-subscribe lightweight messaging protocol in diverse IoT solutions, combined with mobile apps and web applications. We will learn how MQTT and its lightweight messaging system work.
We will understand the MQTT puzzle: clients, servers (formerly known as brokers), and connections. We will learn the procedures to install an MQTT 3.1.1 Mosquitto server in Linux, macOS, and Windows. We will learn special considerations for running a Mosquitto server in the cloud (Azure, AWS, and other cloud providers). We will gain an understanding of the following:
Understanding convenient scenarios for the MQTT protocol
Working with the publish-subscribe pattern
Working with message filtering
Understanding the MQTT puzzle: clients, servers, and connections
Installing a Mosquitto server on Linux
Installing a Mosquitto server on macOS
Installing a Mosquitto server on Windows
Considerations for running a Mosquitto server in the cloud
Imagine that we have dozens of different devices that must exchange data between themselves. These devices have to request data from other devices, and the devices that receive the requests must respond with that data. The devices that request the data must process the data received from the devices that responded with the required data.
The devices are Internet of Things (IoT) boards that have dozens of sensors wired to them. We have the following IoT boards with different processing powers:
Raspberry Pi 3 Model B+
Qualcomm DragonBoard 410c
Udoo Neo
BeagleBone Black
Phytec phyBoard-i.MX7-Zeta
e-con Systems eSOMiMX6-micro
MinnowBoard Turbot Quad-Core
Each of these boards has to be able to send and receive data. In addition, we want a web application to be able to send and receive data. We want to send and receive data in near-real time over the internet, and we might face some network problems: our wireless networks are somewhat unreliable and we have some high-latency environments. Some devices have low power, many of them are powered by batteries, and their resources are scarce. In addition, we must be careful with the network bandwidth usage because some of the devices use metered connections.
A metered connection is a network connection where we have a limited amount of data usage per month. If we go over this amount of data, we get billed extra.
We can use HTTP requests and build a publish-subscribe model to exchange data between different devices. However, there is a protocol that has been specifically designed to be lighter than the HTTP 1.1 and HTTP/2 protocols. The MQ Telemetry Transport (MQTT) is better suited for a scenario in which many devices have to exchange data between themselves in near-real time over the internet and we need to consume the least network bandwidth possible. This protocol works better than HTTP 1.1 and HTTP/2 when unreliable networks are involved and connectivity is intermittent.
The MQTT protocol is a machine-to-machine (M2M) and IoT connectivity protocol. MQTT is a lightweight messaging protocol that works with a server-based publish-subscribe mechanism and runs on top of TCP/IP (Transmission Control Protocol/Internet Protocol). The following diagram shows the MQTT protocol on top of the TCP/IP stack:
MQTT is lighter than the HTTP 1.1 and HTTP/2 protocols, and therefore it is a very interesting option whenever we have to send and receive data in near-real time with a publish-subscribe model, while requiring the lowest possible footprint. MQTT is very popular in IoT, M2M, and embedded projects, but it is also gaining presence in web applications and mobile apps that require assured messaging and an efficient message distribution. As a summary, MQTT is suitable for the following application domains in which data exchange is required:
Asset tracking and management
Automotive telematics
Chemical detection
Environment and traffic monitoring
Field force automation
Fire and gas testing
Home automation
In-Vehicle Infotainment
(
IVI
)
Medical
Messaging
Point of Sale
(
POS
) kiosks
Railway
Radio-Frequency Identification
(
RFID
)
Supervisory Control and Data Acquisition
(
SCADA
)
Slot machines
As a summary, MQTT was designed to be suitable to support the following typical challenges in IoT, M2M, embedded, and mobile applications:
Be lightweight to make it possible to transmit high volumes of data without huge overheads
Distribute minimal packets of data in huge volumes
Support an event-oriented paradigm with the asynchronous, bidirectional, low-latency push delivery of messages
Easily emit data from one client to many clients
Make it possible to listen for events whenever they happen (event-oriented architecture)
Support always-connected and sometimes-connected models
Publish information over unreliable networks and provide reliable deliveries over fragile connections
Work very well with battery-powered devices or require low power consumption
Provide responsiveness to make it possible to achieve near-real-time delivery of information
Offer security and privacy for all the data
Be able to provide the necessary scalability to distribute data to hundreds of thousands of clients
Before we dive deep into MQTT, we must understand the publish-subscribe pattern, also known as the pub-sub pattern. In the publish-subscribe pattern, a client that publishes a message is decoupled from the other client or clients that receive the message. The clients don't know about the existence of the other clients. A client can publish messages of a specific type and only the clients that are interested in that specific type of message will receive the published messages.
The publish-subscribe pattern requires a server, also known as a broker. All the clients establish a connection with the server. A client that sends a message through the server is known as the publisher. The server filters the incoming messages and distributes them to the clients that are interested in that type of received messages. Clients that register to the server as interested in specific types of messages are known as subscribers. Hence, both publishers and subscribers establish a connection with the server.
It is easy to understand how things work with a simple diagram. The following diagram shows one publisher and two subscribers connected to a server:
A Raspberry Pi 3 Model B+ board with an altitude sensor wired to it is a publisher that establishes a connection with the server. A BeagleBone Black board and a Udoo Neo board are two subscribers that establish a connection with the server.
The BeagleBone Black board indicates to the server that it wants to subscribe to all messages that belong to the sensors/drone01/altitude topic. The Udoo Neo board indicates the same to the server. Hence, both boards are subscribed to the sensors/drone01/altitude topic.
A topic is a named logical channel, and it is also referred to as a channel or subject. The server will send subscribers only messages published to topics to which they are subscribed.
The Raspberry Pi 3 Model B+ board publishes a message with 100 feet as the payload and sensors/drone01/altitude as the topic. This board, that is, the publisher, sends the publish request to the server.
The server distributes the message to the two clients that are subscribed to the sensors/drone01/altitude topic: the BeagleBone Black and the Udoo Neo boards.
Publishers and subscribers are decoupled in space because they don't know each other. Publishers and subscribers don't have to run at the same time. The publisher can publish a message and the subscriber can receive it later. In addition, the publish operation isn't synchronized with the receive operation.
A publisher requests the server to publish a message, and the different clients that have subscribed to the appropriate topic can receive the message at different times. The publisher can send a message as an asynchronous operation to avoid being blocked until the server receives the message. However, it is also possible to send a message to the server as a synchronous operation with the server and to continue the execution only after the operation was successful. In most cases, we will want to take advantage of asynchronous operations.
A publisher that requires sending a message to hundreds of clients can do it with a single publish operation to a server. The server is responsible for sending the published message to all the clients that have subscribed to the appropriate topic. Because publishers and subscribers are decoupled, the publisher doesn't know whether any subscriber is going to listen to the messages it is going to send. Hence, sometimes it is necessary to make the subscriber become a publisher too and to publish a message indicating that it has received and processed a message. The specific requirements depend on the kind of solution we are building. MQTT offers many features that make our lives easier in many of the scenarios we have been analyzing. We will use these different features throughout the book.
The server has to make sure that subscribers only receive the messages they are interested in. It is possible to filter messages based on different criteria in a publish-subscribe pattern. We will focus on analyzing topic-based filtering, also known as subject-based filtering.
Consider that each message belongs to a topic. When a publisher requests the server to publish a message, it must specify both the topic and the message. The server receives the message and delivers it to all the subscribers that have subscribed to the topic to which the message belongs.
The server doesn't need to check the payload for the message to deliver it to the corresponding subscribers; it just needs to check the topic for each message that has arrived and needs to be filtered before publishing it to the corresponding subscribers.
A subscriber can subscribe to more than one topic. In this case, the server has to make sure that the subscriber receives messages that belong to all the topics to which it has subscribed. It is easy to understand how things work with another simple diagram.
The following diagram shows two future publishers that haven't published any messages yet, a server, and two subscribers connected to the server:
A Raspberry Pi 3 Model B+ board with an altitude sensor wired to it and a Raspberry Pi 3 board with a temperature sensor wired to it will be the two publishers. A BeagleBone Black board and a Udoo Neo board are the two subscribers that establish a connection to the server.
The BeagleBone Black board indicates to the server that it wants to subscribe to all the messages that belong to the sensors/drone01/altitude topic. The Udoo Neo board indicates to the server that it wants to subscribe to all the messages that belong to either of the following two topics: sensors/drone01/altitude and sensors/drone40/temperature. Hence, the Udoo Neo board is subscribed to two topics while the BeagleBone Black board is subscribed to just one topic.
The following diagram shows what happens after the two publishers connect and publish messages to different topics through the server:
The Raspberry Pi 3 Model B+ board publishes a message with 120 feet as the payload and sensors/drone01/altitude as the topic. The board, that is, the publisher, sends the publish request to the server. The server distributes the message to the two clients that are subscribed to the sensors/drone01/altitude topic: the BeagleBone Black and the Udoo Neo boards.
The Raspberry Pi 3 board publishes a message with 75 F as the payload and sensors/drone40/temperature as the topic. The board, that is, the publisher, sends the publish request to the server. The server distributes the message to the only client that is subscribed to the sensors/drone40/temperature topic: the Udoo Neo board. Thus, the Udoo Neo board receives two messages from the server, one that belongs to the sensors/drone01/altitude topic and one that belongs to the sensors/drone40/temperature topic.
The following diagram shows what happens after one publisher publishes a message to a topic through the server, and this topic has only one subscriber:
The Raspberry Pi 3 board publishes a message with 76 F as the payload and sensors/drone40/temperature as the topic. The board, that is, the publisher, sends the publish request to the server. The server distributes the message to the only client that is subscribed to the sensors/drone40/temperature topic: the Udoo Neo board.
In versions of the MQTT protocol lower than 3.1.1, the MQTT server was known as an MQTT broker. Starting in MQTT 3.1.1, the MQTT broker was renamed the MQTT server, and therefore we will refer to it as the server. However, we must take into account that the documentation for MQTT servers, tools, and client libraries can use the old MQTT broker name to refer to the server. MQTT servers are also known as message brokers.
