Book Image

Developing IoT Projects with ESP32

By : Vedat Ozan Oner
Book Image

Developing IoT Projects with ESP32

By: Vedat Ozan Oner

Overview of this book

Developing IoT Projects with ESP32 provides end-to-end coverage of secure data communication techniques from sensors to cloud platforms that will help you to develop production-grade IoT solutions by using the ESP32 SoC. You'll learn how to employ ESP32 in your IoT projects by interfacing with different sensors and actuators using different types of serial protocols. This book will show you how some projects require immediate output for end-users, and cover different display technologies as well as examples of driving different types of displays. The book features a dedicated chapter on cybersecurity packed with hands-on examples. As you progress, you'll get to grips with BLE technologies and BLE mesh networking and work on a complete smart home project where all nodes communicate over a BLE mesh. Later chapters will show you how IoT requires cloud connectivity most of the time and remote access to smart devices. You'll also see how cloud platforms and third-party integrations enable endless possibilities for your end-users, such as insights with big data analytics and predictive maintenance to minimize costs. By the end of this book, you'll have developed the skills you need to start using ESP32 in your next wireless IoT project and meet the project's requirements by building effective, efficient, and secure solutions.
Table of Contents (17 chapters)
1
Section 1: Using ESP32
7
Section 2: Local Network Communication
12
Section 3: Cloud Communication

IoT as an emerging technology

When I started my career 20 years ago, my first project involved collecting data regarding radio and TV stations by measuring some Radio Frequency (RF) parameters of broadcasted channels. The task was to design and develop a system in order to understand whether the stations comply with the existing regulations in the country. As a solution for this engineering problem, the technical leaders in the team designed a van with various equipment, including the following:

  • A spectrum analyzer
  • A TV demodulator
  • Different types of antennas to measure those parameters
  • An industrial PC to run the application software
  • A radio transmitter to upload the measurements and some basic analysis to a data center

I was lucky that I participated in such a project in my very first job and saw how a complete data acquisition system was designed and developed to solve a real-world problem. This project was in the year just after Kevin Ashton introduced the term Internet of Things to technology literature in 1999.

When I first heard this term and was trying to understand what it actually means, I quickly noticed the similarities between an IoT solution and our monitoring van. We collected data from the environment by using some sensing devices, we had a processing unit, and we also transferred information to a central data storage and processing center. This last part was to access more processing and spot correlation between data coming from multiple vans. So, why not call it an IoT product? Well, not exactly. From that perspective, you could easily call any SCADA or PLC product an IoT system as well, so IoT would only then constitute a rebranding of existing technologies.

What is IoT?

Although the definition of IoT might change slightly from different viewpoints, there are some key concepts in the IoT world that differentiate it from other types of technologies:

  • Connectivity: An IoT device is connected, either to the internet or to a local network. An old-style thermostat on the wall waiting for manual operation with basic programming features doesn't count as an IoT device.
  • Identification: An IoT device is uniquely identified in the network so that data has a context identified by that device. In addition, the device itself is available for remote update, remote management, and diagnostics.
  • Autonomous operation: IoT systems are designed for minimal or no human intervention. Each device collects data from the environment where it is installed, and it can then communicate the data with other devices to detect the current status of the system and respond as configured. This response can be in the form of an action, a log, or an alert if required.
  • Interoperability: Devices in an IoT solution talk to one another, but they don't necessarily belong to a single vendor. When devices designed by different vendors share a common application-level protocol, adding a new device to that heterogeneous network is as easy as clicking on a few buttons on the device or on the management software.
  • Scalability: IoT systems are capable of horizontal scalability to respond to an increasing workload. A new device is added when necessary to increase capacity instead of replacing the existing one with a superior device (vertical scalability).
  • Security: I wish I could say that every IoT solution implements at least the minimal set of mandatory security measures, but unfortunately, this is not the case, despite a number of bad experiences, including the infamous Mirai botnet attack. On a positive note, I can say that IoT devices mostly have secure boot, secure update, and secure communication features to ensure confidentiality, integrity, and availability the (CIA triad).

Gartner added IoT in the 2011 hype cycle, with the expectation of more than 10 years to mainstream adoption. However, many related technologies, such as RFID, mesh networking, and Bluetooth, were already on the list many years before 2011, along with enablers such as mobile and cloud technologies. Since then, Gartner has added several other IoT technologies and applications to its list, including the following:

  • IoT platform
  • Connected home
  • Smart dust
  • Edge computing
  • Low-cost, single-board computers at the edge

5G and embedded AI are other revolutionary technologies on the Gartner list that support IoT and expand its area of application.

Where do we apply IoT?

The application areas are vast, but conceptually speaking, we can group them into two basic categories:

  • In the consumer IoT category, we can see mainly smart home and security systems, personal healthcare products, wearable technologies, and asset tracking applications.
  • The industrial IoT category has more application areas, as you might expect. Every year, IoT Analytics publishes a top-10 trend list for industrial applications by reviewing thousands of new projects and the 2020 list contains manufacturing, transportation, energy, retail, cities, healthcare, supply chain, agriculture, and building applications in that order (https://iot-analytics.com/top-10-iot-applications-in-2020).

Since we have limited space in this book, I don't want to waste pages talking about each of these application areas. Instead, I'd like to share more interesting cases to show how the IoT technology can provide powerful solutions when incorporated with other cutting-edge technologies.

AI/ML on the edge

AI has been around for a long time and there are many successful examples of machine vision, Natural Language Processing (NLP), speech recognition, and ML projects. However, they all require energy-hungry powerful hardware to be able to cope with CPU and memory-intensive calculations, which is not possible with humble sensor devices that have much less memory and processing power. TensorFlow Lite addresses this problem. Its converter can output a model, a set of rules to make predictions by running data through them, with a size as low as 14 KB to fit into any modern microcontroller, such as an ARM Cortex-M3 device with a very low power consumption, which enables you to have battery-operated sensor devices with ML capabilities. One interesting project comes from Benjamin Cabé (on Twitter: @kartben). In his project, he managed to train a model to discern different types of spirits with an accuracy of 92%. He used a Wio Terminal from SeeedStudio as the computing board, which has an ARM Cortex-M4F core running at 120 MHz.

Implications are enormous. Instead of a dummy sensor device, now we have the capability of developing a real smart device such that it can add meaning to data it collects and can react based not only on data, but also the meaning. Benjamin employed a simple gas sensor to detect various gases, such as carbon monoxide (CO), nitrogen dioxide (NO2), ethyl alcohol (C2H5CH), and some other types. But the device itself can understand what it actually smells, thanks to the ML model it uses in its firmware. Without such a capability, the device would have to send its data to another more powerful machine or a cloud to make this analysis and then wait for a reply to decide what to do next. Moreover, if it loses its network connectivity somehow, nothing could be done more until connectivity is restored.

This subject definitely deserves another book, but if you want to do some experiments, ESP32 is also on the list of supported platforms on the TensorFlow Lite website.

Important note

You can have a look at the supported platforms for TensorFlow Lite at the following link: https://www.tensorflow.org/lite/microcontrollers.

Energy harvesting

A vital discussion and research subject for Wireless Sensor Networks (WSNs) has always been the energy consumption of sensor nodes. Obviously, less is better. If you have some experience with the development of battery-operated wireless devices, you know the concept of run to sleep, which means do the job and go into sleep mode as soon as possible to preserve the most valuable resource, energy. Nonetheless, whatever you do, sensor nodes must consume energy and the user will have to replace the batteries after a while. An interesting technology comes to your aid at this point – energy harvesting, which has been around since the days of Nikola Tesla. The energy can be harvested from various ambient sources, including light, vibration, and wireless energy sources. To do that, a harvesting solution first needs to access that ambient energy by means of various components, depending on the energy type.

It is an RF antenna if the energy comes from an RF source, or a photovoltaic cell if light is the source. Then, this raw electrical energy has to be converted with the help of an integrated circuit in order to store it in a capacitor or a battery. But you know that this is easier said than done. Although there are several Power Management Integrated Circuits (PMICs) from different silicon vendors on the market, it is hard to say whether they solve this problem efficiently. The major challenges are very low levels of energy to harvest, the need to boost the very low voltage to higher logic levels, the need for multiple external components to operate, and a large chip footprint on the PCB. Therefore, these challenges have prevented vendors from producing high-performance energy harvesting chips. One product does sound promising, though.

Nowi Energy promotes its NH2D0245 PMIC as the most efficient and the smallest footprint power management IC compared to other semiconductor giants on the market. To prove their arguments, they launched a hybrid smartwatch module together with the module company MMT, such that a watch with that module requires no charge to operate during its lifetime. Energy harvesting is a hot topic, so there are, of course, competitors, such as e-peas semiconductors from Belgium. You might want to try one of those PMICs in your next WSN project.

Nanorobotics

Before we move on, we should look at one last project, a research project from Cornell University. The result of this research has been published in Nature Journal in August 2020 as an article named Electronically integrated, mass-manufactured, microscopic robots. They invented actuators on a nano scale that you literally cannot see with your eyes. The super tiny structure has two solar cells on it to move the legs, and when laser beams are dropped on those solar cells, they generate enough voltage to activate the legs. Although not ready for any practical application as yet, this research is definitely on my follow-up list as a technologist and IoT expert.

Important note

If you want to see them in action, there is a video on YouTube: https://www.youtube.com/watch?v=2TjdGuBK9mI.

These examples are certainly extremes in terms of technology application, but I hope they provide a glimpse of the future in terms of IoT technologies and inspire you in your next IoT project. Let's now continue with some common features of IoT solutions.