Book Image

Internet of Things from Scratch

By : Renaldi Gondosubroto
Book Image

Internet of Things from Scratch

By: Renaldi Gondosubroto

Overview of this book

Develop the skills essential for building Internet of Things solutions with this indispensable guide. In an era where industries heavily rely on IoT, this book will quickly familiarize you with its foundations, widespread use, implementation guided by best practices, and the crucial technologies that allow it to work effectively. Starting with the use of IoT in real-life scenarios, this book offers comprehensive insights into basic IoT hardware, protocols, and technologies. You’ll then learn about architecting and implementing solutions such as wireless sensor networks, cloud computing with AWS, and crucial security considerations. You’ll understand how these systems are operated and monitored over time and work with simple to complex, industry-grade systems, adhering to best practices. In later chapters, you’ll be apprised of future IoT trends and strategies to manage the risks and opportunities that come with them. You’ll also get to grips with a diverse set of tools, including hardware such as ESP32 and Raspberry Pi, and software such as Mosquitto and ChatGPT for generative AI capabilities. By the end of this IoT book, you’ll be able to independently build and design complex, industry-standard solutions fully aligned with best practices.
Table of Contents (22 chapters)
1
Part 1: Getting Started with the Internet of Things
6
Part 2: Developing and Optimizing IoT Systems for Smart Environments
11
Part 3: Operating, Maintaining, and Securing IoT Networks
16
Part 4: Delving into Complex Systems and the Future of IoT

Choosing between IoT hardware

Choosing optimal hardware for an IoT project is imperative, especially when it comes to creating industry-grade implementations. Related hardware and software for IoT go through a standardized design process: requirements specification, conceptual design, prototyping, testing, and finally the rollout of the hardware and software that are part of the system. Some platforms, such as ESP8266 microcontrollers, facilitate easy prototyping and deployment, but this convenience often comes at the expense of lower processing power when compared to other options.

There are many factors to consider, but they can be categorized into four different factors: data acquisition, data processing, connectivity, and power management.

Data acquisition

Data acquisition is a major part of IoT systems, as many components of a system, in the form of sensors, function to collect data in the environment to provide real-time results and/or feedback. This data is often obtained at a fixed rate within a time known as the data sample rate and transmitted to a remote output device to be read in and sent for further processing.

Sensors are devices within an IoT network that are used to detect and measure physical quantities such as humidity, pressure, speed, light, and temperature. This data is obtained from the environment and sent through to the IoT platform either wired or wirelessly.

The way we interact with sensors also differs from use case to use case. As an example, instead of monitoring the environment, some sensors may instead monitor its internal state; these are known as proprioceptive sensors. There can also be sensors that allow personnel to interact directly with them via buttons or touchscreens while recording the actions that are done; these are known as-machine interfaces.

When evaluating which sensor to use, multiple factors come into play. The first and most obvious one is functionality. What are you going to use the sensor for? If you are going to measure changes in the environment for temperature and humidity, for example, you would consider the DHT11, which is a temperature and humidity sensor developed by Adafruit. It comes standardized in many development kits, including the one that this book uses. However, just because you have obtained a sensor that does what you need it to do does not mean that you have found the optimal sensor.

There are many options that need to be considered that are offered by sensors, which is why comparing sensors by their specifications is very important. The condition in which the sensor can operate is another important consideration. Where will you use it? Will it be used at room temperature or in extremely hot or cold environments?

The next consideration is the accuracy and precision of the sensor. Precision is the repeatability or consistency of the measurement. With high precision, a sensor will be able to produce results that deviate very slightly from one another when the same measurement is taken multiple times with the same conditions put on it. On the other hand, with low precision, a sensor would produce results that would deviate more from each other despite the same conditions put on it. This often comes as a trade-off with accuracy, which is how close the measured value is to the actual value of the physical quantity that is being measured. High accuracy for a sensor can produce results that are very close to the actual value, while low accuracy for sensors outputs results that deviate further from the true value. It is important to understand that a sensor can be precise but not accurate and vice versa. Optimally, we would like the sensor to be both precise and accurate, but there are often trade-offs between the two.

Finally, we must consider the resolution of the sensors. The resolution determines the smallest change within the physical quantity that the sensor is capable of detecting. For example, if a temperature sensor has a resolution of 0.1°C, this means that the sensor can detect changes in temperature as granular as 0.1°C. Hence, higher resolutions for sensors allow them to detect smaller changes within the physical quantity, while lower resolutions are only able to detect larger changes. It is also important to note that other factors aside from the sensor may also affect the resolution, such as the accuracy of the analog-to-digital converter (ADC), which converts the sensor’s output to digital form, and the accuracy of the software that processes the data sent by the sensor, which affects the overall resolution of the measurement system.

For example, we can compare the DHT11 and DHT22 sensors that are both developed by Adafruit. The following are the specifications for them from the Adafruit website:

Figure 1.7 – Comparison of DHT11 and DHT22 sensors from Adafruit

Figure 1.7 – Comparison of DHT11 and DHT22 sensors from Adafruit

At first glance, they both provide the functionality of being able to measure temperature and humidity, but they both have different specifications that can meet your deployments’ needs differently. When comparing the specifications, we can see that despite there being many factors that are the same between them, each has its own set of advantages. The DHT11 has a lower cost and a better resolution compared to the DHT22, while the latter has higher accuracy and works over a larger temperature range than the former. Depending on our priorities, this will affect how we choose one sensor over another with these specifications.

These sensors then lead to the next part of the consideration of hardware for the architecture, which is within data processing.

Data processing and storage

Data processing and storage is a crucial part of working with data as part of the IoT. Once we have obtained the data, we must determine how we can analyze, interpret, and work with the data. In different use cases, data is processed in different places of the architecture; the device obtaining the data may process the data itself while in other use cases, it may transmit the data to other places first, such as gateway devices or cloud applications, for the purpose of conducting further analysis.

The processing power and storage size that an IoT application needs rely on the performance needed by the consumers of the data; consumers may use different services of applications that utilize the data either for further processing or as an end goal. These may include factors such as memory, number of cores, clock speed, or processor specifications; all determine the device’s capability for data processing.

Two distinct scenarios arise when considering where to process and store the data:

  • Battery-powered devices: Consider a simple device such as a temperature sensor powered by batteries. Such dummy devices aren’t typically designed for local data processing and storage. The simpler the design, the lower the power consumption and, subsequently, costs.
  • Externally powered devices: Devices with an external power source, such as machines or electricity meters, can afford to have local data processing and storage. This arrangement not only reduces service latency but also conserves wireless backhaul bandwidth, enhancing the overall efficiency.

On the capacity side, this is what makes the consideration of non-volatile memory—the temporary data storage before data is transmitted upstream—imperative; we want to account for being able to hold data while considering the different environments that the device may be in. Is the data in environments of intermittent internet connectivity meaning there may be a chance of data loss if it relies fully on the internet to continuously store data in an upstream provider? Do we do data processing within the device itself? These are all questions that we need to consider when carefully choosing the hardware we need.

Connectivity

Connectivity to networks is a crucial element of IoT devices. There are different types of connectivity to consider. It may be wired or wireless, depending on its use case. Wired communication is usually used for stationary devices and connected via the Ethernet, such as with smart buildings or home automation. On the other hand, wireless communication includes technologies such as Wi-Fi, Bluetooth, WAN technologies (such as LoRa), NB-IoT, and cellular networks. Don’t worry if you don’t know these terms; we’ll talk more about them in the upcoming chapters and ensure that you have a thorough understanding of them and how to make the best use of them depending on your individual use case!

In connecting such devices together over a network, there are two main methods of communication: serial and parallel. With serial communication, data is transmitted one bit at a time over a singular communication line. Serial communication is usually used when the distance that the communication must be based on is relatively long or when the data rate is relatively low. Furthermore, it is used when there are a limited number of available communication lines or when the complexity of the system needs to be minimized. It uses protocols such as the RS-232 or the RS-422 protocols. Some examples of when serial communication would be used are as follows:

  • Communication between a microcontroller and a sensor
  • When two computers are located at a long distance from one another

In parallel communication, multiple bits are transmitted at the same time through multiple communication lines. It is normally used when the communication distance is short and the data rate is high. Furthermore, it is often seen in systems where the number of bits that are transmitted simultaneously is huge. It includes protocols such as IEEE, 1284, and PCI. Some examples of parallel communication’s uses are as follows:

  • Communication between two computers that need to exchange large amounts of data quickly
  • Communication between a computer and a printer

We will cover connectivity in more detail in Chapter 4, Examining Communication and Connectivity Technologies, when we talk about connectivity and communication solutions.

Power management

Power management is a critical consideration within any IoT network. This is particularly true for devices that rely on a wireless power source, which usually depends on batteries or solar cells. There are mainly three main power consumption factors: the sensor, the microcontroller unit, and the wireless backhaul. Aspects that we need to consider include the cost, performance, and battery life of a device. There are multiple approaches that are often used to manage this effectively:

  • Cloud computing: Letting the cloud handle processing and storage is often a great solution for reducing the power consumption of the device, as it will allow it to process data minimally when communicating with the cloud or to simply just perform its data collection when needed and sleep when it is not required for usage at a particular moment.
  • Sleep modes: Microcontrollers and other types of hardware can often enter a sleep mode when there’s low power consumption. It often is up to the user to configure the device to sleep and wake at certain times, which necessitates them to know the periods of high consumption and low consumption or simply to set a threshold and let the device detect on its own. This often reduces power consumption significantly.
  • Power-efficient hardware: Using power-efficient hardware is a very important consideration and may be why some pick one microcontroller over another. This factor is listed on the specifications of the microcontroller, sensor, or other peripherals, as choosing such efficient devices would minimize costs, especially when working with a network filled with them. However, this may come with performance trade-offs, which is why it is important to look at all the specifications carefully to see whether the trade-offs are ones you can afford to make and consider what you really would like to prioritize.
  • Power management integrated circuits (PMICs): PMICs are chips that are used to manage the power consumption of a device. They are used to regulate the power supply to various components within the system, ensuring that only the portion that is allocated to the components gets through. This can be a powerful tool to regulate your system.
  • Energy harvesting: Some energy harvesting methods, such as solar panels, are also effective ways of making use of power in a natural and cost-effective way. This would help you extend the device’s battery life while also reducing the need to purchase batteries. However, this would depend on the environment of the device, as not all environments are conducive to this practice. For instance, not all areas have constant sunlight; solar panels would not work in these cases, and alternative means must be considered.

As can be seen from this section, all of the outlined factors depend on one another. This also leads to certain trade-offs, as it is often not possible to find the ideal device that can satisfy all four factors perfectly while still saving costs. It all depends on what your use case is and to what extent you would like your IoT system to meet it.

With this, you will have understood much more about selecting IoT hardware. As can be seen, sometimes some decisions are not as easily made when there are important trade-offs to consider, but it is often important to prioritize what you want to get out of it instead of trying to achieve the best of everything. In the next section, we will discuss how we can start designing simple IoT system diagrams.