Reader small image

You're reading from  Internet of Things from Scratch

Product typeBook
Published inFeb 2024
PublisherPackt
ISBN-139781837638543
Edition1st Edition
Right arrow
Author (1)
Renaldi Gondosubroto
Renaldi Gondosubroto
author image
Renaldi Gondosubroto

Renaldi Gondosubroto is an accomplished software engineer and developer advocate in the tech community. With a wealth of experience in developing proprietary and open-source solutions, he has made significant contributions to numerous organizations and communities. Currently, he holds all 12 AWS certifications, along with 20 Microsoft Azure certifications. He has a Bachelor of Science in Computing and Software Systems from the University of Melbourne and a Master of Science in Computer Science from Columbia University. Outside of the industry, he is active in the academic community, with his research focused on IoT and Artificial Intelligence. Having spoken at over 40 events, conferences, and workshops, he has been an international speaker for the past six years, sharing his experiences and projects. He aims to build open-source solutions and deliver content that can help people achieve more value in what they do and promote best practices for practitioners.
Read more about Renaldi Gondosubroto

Right arrow

Integrating Application Protocols

In the previous chapters, we learned about IoT networks and what constitutes them. However, to ensure that the smart devices within these networks function and communicate with each other, they rely on a diversity of application protocols. These come together with the communication protocols that we saw in the last chapter and certainly build more of a picture of the network. Integrating them further creates new challenges in terms of having trade-offs, but creates powerful opportunities to further power your solution to make use of the best communication methods.

Application protocols are the rules and standards that dictate how devices exchange information over a given network. These protocols help devices discover and connect to each other, allow them to send and receive data, and help control and manage them. This chapter will discuss why these protocols are important to the development of IoT networks and solutions and how you can design with...

Technical requirements

This chapter will require you to have the following hardware and software installed:

  • Hardware:
    • Two laptops (if you don’t have two, you can use the Raspberry Pi as one of them)
  • Software:
    • Mosquitto client
    • Arduino IDE
    • Command Prompt (you already have this on Windows)
    • cURL

If you are not familiar with Mosquitto or cuRL and/or currently do not have them installed, we will guide you through installation in the following subsections. Otherwise, feel free to skip the next subsections and go to the next heading.

Installing Mosquitto

Mosquitto is an MQTT-based, open source message broker service that sends and receives messages. It is used within remote locations to power connections where the network bandwidth is limited or only a small code footprint is required. It is lightweight and can be used over all types of devices, from low-power microcomputers to full servers. In this chapter, we will be using it to establish MQTT connections. We will...

Application protocols and they fit into the picture

We have discussed much about how IoT networks are formed and their considerations as part of different components, including communication protocols, components for the networks, and many more. However, we have not yet discussed one very important component that operates on the application layer: application protocols. Application protocols operate to ensure that data is sent from one device to another, and understanding which protocol to use and when is imperative for designing effective and optimized networks. In this section, we will be discussing the fundamental application protocols that are usually used within different IoT deployments, and what we should consider when we are faced with different use cases.

We will also have some practical exercises within the section to help you understand the process of how communications work between devices that use the protocol. We will then apply this understanding to the more complex...

Requirements for application protocols

Within the different protocols that we have discussed, we have been able to understand the strengths and weaknesses of each and how they have been used in various use cases. However, how can we further understand the requirements that warrant the use of certain protocols over others? This section will highlight some of the factors that come into play while optimizing networks based on protocols, and help you understand design decisions that come as part of this.

Reliability

Error handling and being able to ensure that messages are delivered are very important aspects of application protocols. Often, there may be scenarios that require much more capability of handling errors and retries than others, such as networks that are based in urban locations and may have connections that are intermittent. Factors that can affect the reliability of how data is transmitted on the application layer include network congestion, interference, and failure...

Integrating application protocols into the design

Now that we’ve seen the considerations of choosing an application protocol, let’s look at integrating the protocols into the design of a network. We already have the knowledge of the components of an IoT network and have seen the interactions that take place between several protocols, so we can put that knowledge to use with the following set of use cases, and see how we can apply our understanding to building our own networks for our use cases based on best practices.

A simple integration into the smart thermostat network

Let’s return to our smart home example, starting off with a simple example of a smart thermostat’s communications with an MQTT broker, which we can see implemented as follows:

Figure 3.5 – Simple smart thermostat communication with MQTT broker

Figure 3.5 – Simple smart thermostat communication with MQTT broker

In this network, we can see that the Thermostat would publish its measurement of the temperature in the...

Practical – creating an MQTT pub and sub communication between an ESP32 and a Raspberry Pi

One of the best ways to see MQTT in action is to create a pub/sub model based on communication between two devices. In this case, we will be using the ESP32 and the Raspberry Pi, where the ESP32 will serve as the publisher and subscriber while the Pi serves as the MQTT broker. Here is a breakdown of the roles of all three in this practical:

  • Publisher: The ESP32 publishes messages to the MQTT broker. It sends messages to the /topic/test1 topic when there is user input from the serial monitor, and it also periodically sends Hello World messages to the /topic/test3 topic every 15 seconds.
  • Subscriber: The ESP32 is also a subscriber, as it listens for messages on the /topic/test1 and /topic/test2 topics. When it receives a message on one of these topics, it processes the message in the callback function, which in this case prints the received message to the Serial Monitor.
  • Broker...

Summary

In this chapter, we have learned the fundamentals of application protocols for IoT networks, particularly those that are commonly used for IoT, including MQTT, HTTP, CoAP, and XMPP, and understood the considerations that are put in place when designing for a network. We looked at a practical use case of using an MQTT pub/sub client as part of deepening our understanding of it, and learned how to use cURL to send GET and POST requests to retrieve and send data to websites. Understanding these protocols and design considerations is paramount for anyone involved in developing or managing IoT networks as they ensure optimal communication, security, and data transmission across various devices and platforms. This knowledge is instrumental in developing efficient, secure, and scalable IoT solutions, thereby enhancing your ability to contribute effectively to IoT projects and innovations.

In the next chapter, we will be looking at understanding the use of communication and connectivity...

Further reading

For more information about what was covered in this chapter, please refer to the following links:

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Internet of Things from Scratch
Published in: Feb 2024Publisher: PacktISBN-13: 9781837638543
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
Renaldi Gondosubroto

Renaldi Gondosubroto is an accomplished software engineer and developer advocate in the tech community. With a wealth of experience in developing proprietary and open-source solutions, he has made significant contributions to numerous organizations and communities. Currently, he holds all 12 AWS certifications, along with 20 Microsoft Azure certifications. He has a Bachelor of Science in Computing and Software Systems from the University of Melbourne and a Master of Science in Computer Science from Columbia University. Outside of the industry, he is active in the academic community, with his research focused on IoT and Artificial Intelligence. Having spoken at over 40 events, conferences, and workshops, he has been an international speaker for the past six years, sharing his experiences and projects. He aims to build open-source solutions and deliver content that can help people achieve more value in what they do and promote best practices for practitioners.
Read more about Renaldi Gondosubroto