Book Image

Arduino IoT Cloud for Developers

By : Muhammad Afzal
Book Image

Arduino IoT Cloud for Developers

By: Muhammad Afzal

Overview of this book

The Arduino IoT Cloud offers a variety of features for building modern IoT solutions while reducing time and costs for prototyping and deployment. This book is a step-by-step guide, helping you master the powerful Arduino IoT Cloud ecosystem. This book begins by introducing you to the IoT landscape including its architecture, communication technologies, and protocols and then to the capabilities of the Arduino IoT Cloud platform and the Cloud Editor. With practical projects, such as monitoring air quality, building a portable asset tracker, and creating a remote alarm system using the LoRaWAN specification, you'll learn how to implement real-world IoT applications. Next, you'll explore communication between IoT devices and cloud platforms as well as the implementation of the Arduino IoT Cloud SDK and JavaScript for advanced customization. You'll also find out how to program IoT nodes, analyze the surrounding environment data, and visualize it on dashboards. Additionally, you’ll get to grips with advanced features such as task scheduling, synchronization, remote over-the-air updates for IoT nodes, and scripting with CCLI, through hands-on examples. By the end of this book, you’ll have learned how to work with the Arduino IoT Cloud platform and related hardware devices and will be able to develop industry-specific and cost-effective IoT solutions, such as smart homes and smart agriculture.
Table of Contents (21 chapters)
1
Part 1: Introduction to IoT and Communication Technologies and the Arduino IoT Cloud
5
Part 2: Getting Hands-On with Different Communication Technologies
9
Part 3: Exchanging Data between Nodes and Cloud Applications
14
Part 4: Learning Advanced Features of the Arduino IoT Cloud and Looking Ahead

What is the Internet of Things?

There is not a single official definition of the IoT, but the following sentence covers the concept in its entirety:

The Internet of Things or, briefly, IoT is the concept of connecting physical objects to a network and other devices to let them interact with each other and with human beings to share information and take action through the Internet.

These physical objects are electronic devices using different telecommunication technologies to connect to a network. It’s not surprising that the choice of network falls to the internet, not only because of the name of this technology but the characteristics of the internet itself:

  • A digital network
  • Worldwide coverage
  • Standardized specifications
  • Widely used for personal and professional communications

IoT devices are often called IoT Nodes because they are part of this network.

They feature sensors to detect or measure a physical property, such as the temperature of the environment or the speed of a vehicle. In other cases, they are connected to external machinery, devices, or appliances, always with the same purpose: collecting the values of physical properties, often called Telemetry Elements, and transmitting them to the internet. Once the values have reached the internet, they can arrive almost everywhere in the world in a few hundredths of a second.

You may think about interfacing an IoT node to an industrial machine to remotely transmit the information about its running conditions, and eventually alert a maintenance operator, in case of a fault. Or, connecting the node to your coffee machine to measure the level of the coffee grounds with the possibility to check it remotely while you are at the supermarket so that you can buy another pack only if required.

As a matter of fact, the IoT opens up the possibility to virtually infinite applications because connecting a device to the internet implies the possibility to both monitor the environment and send commands to the node remotely.

In fact, the telecommunication technologies used in the IoT are bidirectional and information can flow from the IoT node to the internet and vice versa. The interaction among IoT nodes is mainly related to the exchange of digital information by using the internet as the communication media.

Intelligence at the edge versus on the cloud

It’s important to underline that IoT nodes also have processing capabilities to different extents; they can be programmed to receive information from the internet and implement some logic accordingly.

Another example might help. You can interface IoT Node #1 to a weather station, collect information about the forecast, and transmit it to IoT Node #2 connected to your automatic irrigation unit. You may program Node #2 to prevent a waste of water in case rain is expected in the next few hours. Another node, Node #3, can embed a sensor and share the soil moisture value with Node #2 through the internet so that irrigation is activated, if necessary, when the forecast is good and the soil requires water.

This may not be relevant to my small garden, but you might consider the benefits in the case of extensive fields, where different areas may be irrigated depending on the crop’s requirements.

When the control logic is programmed directly on a node, we say that it is at the edge, referring to the edge between the physical and the digital world.

The logic can also be programmed on the cloud. In this case, there is an application running on a computer connected to the internet. In fact, the cloud empowers a huge number of computers connected together and to the internet with the aim of sharing computational and storage power, as well as balancing the computational load across multiple systems. With the on-the-cloud approach, the application on the cloud receives telemetry elements from one or more IoT nodes, aggregates the information, and defines the commands to send back to the same or other IoT nodes.

I talk about commands because IoT nodes can also be interfaced with actuators, such as motors, pumps, electro valves, electrical relays, and any other device responsible for moving and controlling a mechanism. This means that an IoT node can interact with the physical world by performing physical, programmed actions as a reaction to certain measures.

Considering the example of irrigation, the IoT node is electrically connected to a hydraulic servo valve and drives it to control the flow of water to the nozzles.

IoT nodes always implement embedded control logic to some extent, even when the intelligence of the application resides on the cloud. This is required to receive, interpret, and react to the commands from the application server on the cloud.

The distinction between on the edge and on the cloud is mainly related to the real intelligence of the application, such as the capability to understand when it’s necessary to irrigate on the basis of the forecast and the moisture of the soil.

So, intelligence on the edge is completely programmed on the node by writing software code in a structured language such as C++ or MicroPython, or adopting artificial intelligence models based on neural networks. With the on-the-cloud approach, it is the responsibility of application software running on a cloud server to decide to automatically trigger a valve.

The choice between on-the-edge and on-the-cloud implementations is mainly driven by the application and the required response time. Implementations on the cloud allow more freedom in terms of programmable features. This is because the cloud is composed of multiple servers working together and it has virtually no constraints of memory and computational power. On the other hand, deployments on the edge remove some bottlenecks related to the latency of communication networks, reducing the response time of an IoT node and allowing it to interact with the physical world in real time.

It’s worth noting that an implementation on the edge doesn’t preclude the benefit of implementing manual remote control of the nodes in addition to automatic control. For example, an operator could interact with the devices in the field through a graphical user interface visualized on a web page (called a dashboard). They would see the actual values of environmental conditions and could trigger the valve as they liked.

The programmer of the application is responsible for defining and configuring the dashboards, which can be as complex as required, with widgets to visualize and insert data such as graphs and textboxes, and trigger commands such as switches, sliders, pushbuttons, and many others.

The market sees an increasing number of on-the-edge applications for various use cases where microcontroller devices can be successfully adopted as control units of IoT nodes. This trend has led to the continuous, fast improvements in hardware components, with augmented computational capabilities and a consequent decrease in their cost, as well as the mass availability of wireless telecommunication technologies characterized by very low power consumption and long-distance transmission range.

When we consider the installation of IoT nodes in remote and not easily accessible areas, energy autonomy is a very important aspect: we want to reduce the need for battery recharging as much as possible to decrease the costs of human intervention. Ideally, a good IoT application is supposed to be fully autonomous!

When you adopt one of the Low-Power Wide Area Network (LPWAN) technologies, you need to consider that a decreased power consumption comes at the expense of a reduced quantity of data that can be transmitted with a single message and a higher interval between messages. It’s like considering data as a form of energy and applying the energy conservation law: if you decrease the power, you decrease the amount of data, not only the transmission range.

A decreased amount of data per message and a longer interval between two transmissions mean that you need to reduce the information exchanged with the cloud so that the cloud needs less time to collect all the values to process.

When this duration, which we may call Cloud Latency Time, is too long, then it’s worth implementing intelligence on the edge.

The Arduino ecosystem

It’s not possible to connect a single device to every type of sensor, actuator, external machinery, and device in the same way, because each element implements different electrical interfaces and ways to communicate.

Manufacturers produce IoT nodes, or components suitable for building IoT nodes, focusing on defined use cases and technologies, and adopting some of the various standards available on the market. Every person developing an IoT project has the responsibility to select the nodes with the best characteristics for their application. When a complete product with the required features is not readily available in the market, you may use electronic modules to build your IoT nodes as you like. This is where Arduino comes in handy.

We assume you know what Arduino is since you’re reading this book. Anyway, I think it’s worth mentioning that Arduino is not only a technology but an ecosystem maintained by the commercial business of the same name. The modular ecosystem is composed of electronic microcontroller based development boards, firmware, software libraries and tools to program boards and the cloud platform described in this book.

The Arduino team engineers every single component with particular attention to its usability and the user experience, according to the mission of the company, which is to “enable anyone to innovate by making complex technologies open and simple to use.” (M. Banzi, cofounder of Arduino).

It’s not surprising that the Arduino Cloud also follows the same approach, and you’ll see how easy it is to develop an IoT cloud application with the Arduino Cloud, without programming but configuring it. The ease of use of the Arduino Cloud is related to the native on-the-edge model: Arduino follows the technology trend of implementing the intelligence on the nodes, leaving the data storage and visualization tasks to the cloud.

You may still deploy an IoT solution on the cloud with the Arduino Cloud when you interface the Arduino Cloud with third-party services where the application logic and the intelligence are implemented.

Besides officially Arduino-compatible development boards, you can also use popular development boards such as the ESP32 & ESP8266 series development boards with the Arduino IoT Cloud. This feature helps the developer to use existing hardware solutions to migrate their products to the Arduino IoT Cloud without changing existing hardware technologies.

The other important aspect of the Arduino ecosystem is related to making technologies open. Most of the hardware and software produced by Arduino is publicly released under open source licenses, and by the end of this chapter, you will know the benefits and the obligations related to open source licenses and how to protect your intellectual property. Arduino also provides professional hardware devices for industry use, such as the Portenta series, which is specially designed for IoT and AI solutions. Arduino Opta Programmable Logic Controllers (PLCs) are the new product line in the PRO series, which is designed for industry deployment. For more details regarding the PRO series, please visit https://store-usa.arduino.cc/collections/pro-family.

The IoT, big data, artificial intelligence, and machine learning

We have seen that an IoT application involves the connection between the physical and digital worlds to create some sort of digital automation of physical processes. The outcome is the result of the following:

  • Connecting devices to the internet
  • Allowing devices to share information to interact and collaborate
  • Implementing smart applications that can take intelligent actions

When we talk about digitalization, other buzzwords are often used together with the IoT: big data, artificial intelligence, and machine learning. These are complementary sciences that can be used to realize complex digital projects. We’ll describe what they are and how they are used in conjunction with the IoT next.

Big data refers to extremely large and complex datasets and to the science that studies how to process them. Traditional data processing software is unable to handle big data in a reasonable amount of time due to the size of the datasets and their unstructured and disaggregated nature, so dedicated technologies are necessary to extract valuable insights and knowledge used to support decision-making and strategic planning.

When we consider hundreds or thousands of IoT nodes sharing different values in real time, collected from the physical world, you may understand that the size and variety of the data require much more than a traditional database.

Big data involves an implementation of logic on the cloud. Even when an on-the-edge model is used for a fast response time in the physical world, data can be sent to the cloud for long-term processing without time constraints. Here, big data can be supportive.

For example, with reference to our example of smart irrigation, a node can use values from soil moisture sensors to control a hydraulic valve on the edge and also share information with a cloud application that uses data from multiple nodes to adapt a model for weather forecast considering, and also additional information from national weather stations.

You may consider big data as the cloud application processing raw data to extract and store valuable information.

Artificial intelligence and machine learning are often referred to as being the same science, but they are not. Artificial Intelligence (AI), is a broad field that encompasses many different subdisciplines, including Machine Learning (ML).

AI is the broader concept of machines being able to carry out tasks in a way that would normally require human intelligence, such as visual perception, speech recognition, decision-making, language translation, and others.

ML is a specific subfield of AI that focuses on enabling computers to learn from data and make predictions or decisions without being explicitly programmed to do so. Usually, ML involves training a model on a dataset and using the trained model to make predictions or decisions on new data.

In summary, AI is the broader concept of the mimicking of human intelligence by machines, while ML is a specific method/technique to achieve AI, which allows the machine to learn from data, instead of being explicitly programmed.

AI and ML models can be trained by using the data collected by big data tools and used to interpret other new data from the same or another big data platform.

Once trained, the models can be deployed on the cloud and on the edge as well, depending on their size and the technical features of the nodes.

While big data tools processes the data directly with analytical models, AI/ML works on patterns in data in order to recognize situations and trends.

For example, you can use big data to extract the trends of soil moisture in a wide region where thousands of sensors collect values every hour and big data can support you in distinguishing between daily, monthly, and seasonal changes over a period of years.

ML works differently; it ingests values of different types, such as weather forecast parameters, and identifies patterns that affect your observations. You may create an ML model by training a neural network with temperature, atmospheric pressure, humidity, wind speed, and soil moisture values across a period. Then you provide another set of data from a different period, without the soil moisture values, and the model is able to suggest indications about irrigation needs.

With reference to the following diagram, you may see the complete dataflow of a complex application, where the IoT senses the physical world, reacts immediately on the edge when required, and forwards the values to big data for offline or batch processing (not in real time):

Figure 1.1 – Data integration with other technologies

Figure 1.1 – Data integration with other technologies

Big data stores and aggregates the values that are used to train and run AI/ML models. These models make decisions and send commands back to IoT nodes that interact with the physical world.

The IoT, IIoT, and I4.0

The IoT concept has been widely applied in different aspects of our lives and some applications are already part of our daily routines.

For example, you may buy a smart doorbell online for tens of dollars. This device integrates a microphone and a loudspeaker and connects to your Wi-Fi. This IoT node remotely alerts you on your mobile when someone rings, and it allows you to have a conversation with the visitor in front of your door, even if you are miles away from your house. With some models, you may even unlock the door.

Have you ever switched on a light in your house by asking Alexa®, Google Assistant™, or Apple’s Siri to do so? All those IoT nodes are examples of applications in the smart building and home vertical.

Advanced solutions manage air conditioning, windows, and curtains depending on the environmental situation, measured by presence detection, temperature, and sunlight sensors.

We’ve already introduced an application in the agriculture market, with others related to tracking live animals and their conditions by localizing them with GPS technologies and measuring their vital parameters. For example, a rapid heartbeat can be a symptom of stress due to overheating or the presence of a predator.

We all like to receive frequently updated tracking information about the shipping of our last online purchase. The online tracking of deliveries is also useful to freight forwarding companies to reduce the risks of complaints and the associated operative costs. All this is possible thanks to the usage of handheld devices connected to the internet and small IoT nodes attached to valuable goods, capable of sending their location wirelessly to a cloud application. Logistics is definitely one of the sectors where the IoT is successfully adopted, but the healthcare, retail, smart infrastructure, security, and surveillance markets also offer many examples of IoT applications.

The deployment of an IoT application in the industrial environment is commonly referred to as the IIoT.

IIoT applications mainly focus on collecting data from the physical world to better understand how to improve industrial processes, make better use of plants, and optimize the consumption of energy, water, human work, and other resources involved in activities.

The main target is an increase in performance and a reduction of costs in all departments.

Important note

This is not the place to cover the implications in terms of the workforce, but I would like to say that the IIoT doesn’t directly imply the reduction of operators, but their training and technical growth can be managed from a cost-reduction perspective when good, fair employment policies are adopted.

The adoption of the IoT principles in the industrial environment requires particular attention in the implementation and deployment of nodes because the environment can be harsher in terms of temperatures, vibrations, and electromagnetic pollution.

The overheating caused by higher temperatures in certain industrial environments causes failures in the electronic components of nodes and reduces their lifespan.

Vibration fatigue is another main cause of failures of electronic devices. The vibrations transfer to the electronic board when a node is installed in contact with a machine, and they apply stress to the components, resulting in early failure.

Industrial environments are quite dense with industrial motors in machinery, power cables, the cellular devices of operators, and other sources of electromagnetic fields.

The preceding aspects affect IIoT nodes only, while the application of the IoT to the industrial environment has other implications on the cloud side:

  • Scalability: Cloud infrastructures for the IIoT typically require it to easily handle and store large amounts of data from a vast number of IoT devices
  • Data security: The industrial market requires improved cloud security measures to protect against cyber threats to cloud applications and IIoT devices
  • Data localization: One of the frequent requests from the industrial market is that all data remains confidential and confined to the local country

Several reasons justify a request for cloud data to remain in the local country. Data privacy and security concerns are evident when you consider that keeping data within a country ensures that it is subject to the jurisdiction and protection of local laws.

Furthermore, some countries have strict regulations regarding the storage and handling of sensitive data, and keeping it within the country helps organizations comply with these regulations.

Last but not least are considerations related to performance and cost-effectiveness: accessing data and applications stored in a remote location can result in slower performance and higher latency. Likewise, transferring data across international borders can be expensive and complex, making it more cost-effective to store data within a country.

Industry 4.0, known as the Fourth Industrial Revolution, is a broader concept than the IIoT and refers to the application of the IIoT specifically in smart factories for the production of consumer goods.

In this way, production processes are controlled and monitored in real time and digitalization empowers machines and devices to make decisions, freeing up human workers for higher-level tasks. This is a decentralized decision-making approach, where production is driven by data collected and analyzed by machines and devices in order to speed up a continuous improvement of the production processes.

Flexible manufacturing processes allow the mass production of customized products in batches of one pace having features defined by every single customer at the time of online shopping.

Industry 4.0 means connecting a fully automated factory to the internet to improve the customer experience and optimize the overall business performance.

Customers can go to their preferred online store to buy a pair of running shoes, select the model, choose the materials, configure the colors of the different parts, and place an order. After payment by credit card, the order digitally arrives at the factory, where robots and machinery are configured in real time to get material from the warehouse, produce your custom shoes, including printing your name on them and the box, and then return the box to the warehouse ready for shipment.

Not a single piece of paper has been printed throughout the whole process. The facility managers can consult metrics online regarding the performance of the factory and the customer receives their personalized shoes delivered at home.

This is not a dream, and it’s already possible with the manufacturer Nike®, famous worldwide.

Industry 4.0 requires a wider software architecture than the IIoT cloud.

You may consider that the IIoT cloud is already interfaced with the machinery and devices of a production plant in an IIoT application. Industry 4.0 additionally connects digital systems from the different departments of the business, including the following:

  • Enterprise Resource Planning (ERP): To automate and manage core business processes for optimal performance
  • Computerized Maintenance Management System (CMMS): To manage assets, schedule maintenance, and track work orders
  • Warehouse Management Systems (WMSs): To support inventory and manage supply chain fulfillment operations

Here, we have discussed the IoT in detail, as well as cloud versus edge processing and AI implementations. We have covered some details about the Arduino ecosystem, including their PRO line of products. Later, we discussed the IoT, big data, artificial intelligence, and machine learning, including the IIoT, as they all are very important pillars in high-level projects. In the next section, we will discuss what benefits there are for users by implementing the IoT in daily life as well as in industry.