Arduino IoT Cloud for Developers
Arduino IoT Cloud for Developers
Contributors
Preface
Part 1: Introduction to IoT and Communication
Technologies and the Arduino IoT Cloud
3
Insights into the Arduino IoT Cloud Platform and
Web Editor
Technical requirements
Introducing the Arduino IoT Cloud interface
Devices and things
Dashboards
Integrations and templates
Exploring input controls
Switch, push button, slider, and stepper
Color, dimmed light, and colored light
Time picker (configuration)
Scheduler (configuration)
Delving into output controls
Value, status, gauge, percentage, and LED
Maps and charts
Messenger and sticky notes
Understanding the Arduino Web Editor
Sketchbook
Examples
Libraries and the Library Manager
Monitor AKA the Serial Monitor
Reference, help, and preferences
Arduino IoT Web Editor features
Assignments
Assignment 1
Assignment 2
Assignment 3
Summary
Part 2: Getting Hands-On with Different
Communication Technologies
5
Project #2 – Creating a Portable Thing Tracker
Using MKR GSM 1400
Technical requirements
Enhancing operations with IoT asset tracking and
remote control
Exploring the advantages of GSM/LTE/NB-IoT
communication technologies
Seamless global connectivity with IoT SIM cards
Building blocks – sensors and development boards for
IoT
Designing the project architecture
Schematic design and assembly
Testing GPS module data
Activating SIM cards for IoT deployment
Configuring the Thing, network credentials, cloud
variables, and code
Cloud variables
Associating a device
Network
Coding
Creating comprehensive web and mobile dashboards
What next?
Summary
8
Working with the Arduino IoT Cloud SDK and
JavaScript
Technical requirements
Demystifying the Arduino IoT Cloud SDK –
functionality and operation
Securing access – unveiling API keys and
authentication
Initial exploration – test drive using Postman
Diverse platform compatibility – SDKs for various
environments
Step-by-step – installing the Arduino Node.js SDK
client
Interacting with devices – hands-on with the Node.js
SDK
Creating a device
Updating a device
Deleting a device
Listing devices
Showing a device
Device properties/variables
Engaging with Things – Node.js SDK implementation
guide
Creating a Thing
Updating a Thing
Creating a Thing sketch
Deleting a Thing
Listing Things
Showing a Thing
Exploring properties – Node.js SDK interaction
techniques
Creating a property
Updating a property
Deleting a property
Listing properties
Crafting dashboards – unleashing potential via the
Node.js SDK
Creating a dashboard
Updating a dashboard
Deleting a dashboard
Listing dashboards
Fine-tuning with the Node.js SDK – property value
management
Get a property value
Set a property value
Assignment
Summary
10
11
12
14
Index
Sensors:
DHT22/DHT11
MQT-135
The NEO 6-M u-blox GPS module
Capacitive soil moisture sensors
DS18B20 waterproof probes with long wires
The WS2812 RGB ring
A pulse sensor
If you are using the digital version of this book, we advise you to type the code
yourself or access the code from the book’s GitHub repository (a link is available
in the next section). Doing so will help you avoid any potential errors related to
the copying and pasting of code.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: 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: “This cloud variable declaration is available in the
thingProperties.h file.”
TinyGPSPlus gps;
unsigned long previousMillis = 0;
const long interval = 30000; //milliseconds
Any command-line input or output is written as follows:
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at
customercare@packtpub.com and mention the book title in the subject of your
message.
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/support/errata and fill in
the form.
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 copyright@packtpub.com 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.
Share Your Thoughts
Once you’ve read Arduino IoT Cloud for Developers, we’d love to hear your thoughts!
Please click here to go straight to the Amazon review page for this book and share
your feedback.
Your review is important to us and the tech community and will help us make sure
we’re delivering excellent quality content.
https://packt.link/free-ebook/9781837637171
2. Submit your proof of purchase
3. That’s it! We’ll send your free PDF and other benefits to your email directly
Part 1: Introduction to IoT and Communication
Technologies and the Arduino IoT Cloud
This first part describes the principles of the Internet of Things (IoT), gives an
overview of the Arduino IoT Cloud platform, and shows how to use it for the first
time. It then provides a detailed description of its functionalities.
This part has the following chapters:
Chapter 1, Introduction to IoT and Arduino
Chapter 2, First Look at the Arduino IoT Cloud
Chapter 3, Insights into the Arduino IoT Cloud Platform and Cloud Editor
1
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.
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):
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.
However, it’s worth mentioning that wireless IoT nodes may suffer from interference
from other wireless devices, limited range, and potential security issues, so it’s
important to consider these limitations when choosing between wired and wireless IoT
nodes.
For example, the IoT nodes for the load, vibrations, and structural monitoring of a
bridge over a river, which respectively provide useful information about the
maintenance, traffic balance, and improvement requirements, don’t need to be
wireless. Many smart agriculture applications, on the other hand, benefit from long-
range wireless technologies because of the difficulties and the installation costs of a
wired network covering huge areas.
Considering the Kids park has a lot of IoT nodes, we can roughly divide the
applications in the different market verticals into four main groups:
Consumer devices with a very short transmission range: Wearables, safety devices, remote
controls, and toys that typically use a Bluetooth or a Bluetooth Low Energy (BLE)
connection to a mobile phone that shares the connectivity to the internet. This approach
demonstrates the possibility of daisy-chaining multiple gateways with different technologies to
reach the required connectivity.
Consumer devices with a short transmission range: This is the case for home automation
devices, such as the thermostat of your house or appliances, entertainment devices, personal
instruments, and healthcare devices connected to the internet through a cabled Wi-Fi access
point.
Wireless professional devices: Automotive, smart agriculture, mining, and some logistics and
outdoor industrial applications require very long-distance transmission ranges provided by the
latest cellular technologies, which includes 3G/4G/5G or LPWAN.
Wired professional devices: Some infrastructural projects, such as the monitoring of bridges
and dams or indoor industrial projects, require wired nodes to increase reliability, increase the
data throughput of the transmission, reduce the maintenance required for battery replacement,
and increase data security.
The gateway-to-cloud link is wired in most IoT applications and, eventually, the
gateway provides a backhaul wireless connectivity to the internet. This is the case of
professional Wi-Fi and LoRa gateways that implement an Ethernet interface and also a
cellular modem: the gateway automatically swaps to cellular if the Ethernet connection
fails.
Defining the nature of the cloud-to-cloud communication path is a little bit trickier
because we need to consider that cloud apps run on cloud platforms, and these are
composed of servers interconnected to each other. The physical connection among the
servers is definitely wired, but we may consider the logical connection between cloud
applications wireless because, when compared to applications installed on a single
server on the internet, wireless and wired IoT nodes offer the same benefits.
Hardware security
Attackers can exploit security vulnerabilities due to outdated or unpatched software,
and this is even more probable when nodes are based on microcomputers running
common operating systems. The probability decreases significantly when the node
features a microcontroller that runs on bare metal as firmware, like in the case of the
Arduino ecosystem. This is because the software running on the device is reduced to
the minimum strictly necessary to run the device.
The adoption of strong data encryption algorithms on nodes protects the data
transmitted over the network, making it less vulnerable to eavesdropping or tampering.
In this case, too, the Arduino ecosystem demonstrates that it is a good choice for the
implementation of an IoT application: Arduino devices for IoT embed secure
elements, called crypto-chips, able to generate and manage security keys at the
hardware level, without the need to include a password in the source code of the node
application. We’ll see what this means and how it works toward the end of this section,
but it’s now necessary to talk about another security risk related to IoT nodes.
That is inadequate access controls: some IoT devices with inadequate access controls
may allow unauthorized individuals to access or control the device, potentially
compromising the security of the system as a whole.
The access can be remote or even direct to the device to extract the original firmware
from the device and overwrite it with a different version programmed by hackers. The
extraction of the firmware could also be used just for replicating the functionalities of
an original device on compatible but cloned hardware, threatening the results of an IoT
business.
Arduino has engineered a safe version of their traditional bootloader to prevent these
risks. A bootloader is the first software that is executed on the device and is
responsible for loading the firmware and initializing the device’s hardware.
The Arduino Safe Bootloader adds a secure environment to the traditional bootloader
by implementing mechanisms for firmware fail-safe authentication and secure updates.
These prevent unauthorized access to the device’s firmware and ensure that only
authorized firmware can be executed on the device.
An authenticity check of the firmware is based on digital signatures and guarantees
security: the bootloader checks the digital signature of the firmware before loading it
into the device’s memory and doesn’t proceed in the case of unauthorized or wrongly
signed firmware, preventing the device from booting. In the same way, the safe
bootloader protects against tampering, data corruption, and reverse engineering: it
validates a new version of the firmware before overwriting the old one and can be
configured to prevent the reading of the actual firmware from the device.
The programmer of the IoT node generates and manages their digital signatures,
maintaining full control of the device, but excluding others at the same time.
I recommend the adoption of the secure bootloader in any IoT project because the
minimal effort required to implement it is repaid immediately in terms of the security
and integrity of the device and data.
Microcontroller-based nodes, with strong hardware encryption capabilities and secure
boot mechanisms, address most of the security concerns on the node. Regular security
audits ensure that the data exchanged between IoT devices and the backend systems is
protected, while the providers of cloud platforms and cloud applications are
responsible for securing the backend systems on the cloud that process and store the
data by implementing secure data storage practices and regular backups, as well as
regularly monitoring the systems to detect and respond promptly to potential security
incidents.
In SSL/TLS, the initial handshake between the client and the server is performed using
asymmetric encryption. The client and the server agree on a shared secret key, which is
then used for symmetric encryption of the data transmitted between them. This
approach provides both security and performance, making it a suitable encryption
protocol for securing communications in IoT environments.
In the end, the device needs to know the public key for the SSL/TLS handshake and
the cloud needs to know a unique device key or device identity to recognize the
connection from a legitimate device. This data shall be configured during the
provisioning phase for each IoT device that we want to deploy for our application.
The provisioning for a limited number of devices is usually manual or semi-automatic
and is performed during the programming of each single device. In this phase, the
programmer defines the unique identifier of their device and registers it on the cloud,
then generates the security key on the cloud, and copies it to the device. It’s not a
difficult process, but it may become complicated because different clouds have
different architectures and ways to do this.
Open source
The concept of open source software and open source licenses was first introduced in
the late 1960s and early 1970s by computer scientists and programmers who believed
that the sharing and collaboration of software code would lead to better, more reliable,
and more innovative software.
Arduino is considered to be one of the first companies in the world to adopt open
source licenses for hardware engineering too. The company released the first version
of the Arduino board in 2005, along with schematics for the board and the source code
of the core firmware under an open source license.
This allowed anyone to use, modify, and redistribute the design freely, which greatly
contributed to the success and popularity of the Arduino platform. The open source
approach also enabled a community of developers and makers to collaborate and
improve the platform, creating a wide range of libraries, tutorials, and projects that are
still used today.
Summary
We have seen that two electronic devices can use the internet to interact with each
other and exchange information, without the need for a direct physical connection
between them. Nodes can be interfaced with other objects and cloud applications and
this architecture allows the implementation of smart solutions in different markets and
with huge benefits for users.
We’ve seen the architecture of an IoT solution, the different telecommunication
technologies, and the security aspects involved.
We have talked about methods to protect your intellectual property against the
duplication of your product and how to adopt open source libraries without the need to
release your source code.
Finally, please respect the Arduino trademarks when implementing a commercial
solution based on the Arduino ecosystem.
All this information is necessary to understand how things behind an IoT application
work and for you to consider the right approach for your next IoT solution.
Before stepping into the next chapter, with the first example of an IoT project based on
the Arduino IoT Cloud, it’s worth recapping the main steps to engineer a good IoT
solution:
1. Identify the application and define the business model.
2. Determine the requirements and goals of the IoT application.
3. Identify on the edge versus on the cloud and structured code versus AI/ML model
requirements.
4. Select the most appropriate telecommunication technologies.
5. Choose the appropriate hardware for the IoT node.
6. Select the provisioning mode according to the size of the project.
7. Develop the software for the node and configure the cloud, as we’ll see in the following
chapters.
8. Deploy the application and periodically monitor performance and security.
2
Technical requirements
Before we start, we first need to set up an Arduino IoT Cloud-compatible board. I
recommend the Arduino MKR Wi-Fi 1010, but there is a complete list of compatible
boards at https://docs.arduino.cc/arduino-cloud/getting-started/technical-
reference#compatible-hardware, which you can choose according to your
requirements.
Second, you should have an Arduino IoT Cloud account. If you don’t, then sign up at
https://cloud.arduino.cc/ and select a plan according to your requirements.
Third, we need to download and install the Arduino Create Agent. Arduino has
created a beautiful web-based guide for installation at https://create.arduino.cc/getting-
started/plugin/welcome.
The second part of the chapter is related to Node-RED, which will be used for devices
that are not officially supported by the Arduino IoT Cloud such as Raspberry Pi and
older versions of Arduino development boards. Download and install Node-RED
according to your operating system from https://nodered.org/docs/getting-started/local.
IMPORTANT NOTE
All the Arduino IoT Cloud plans are available on the Arduino IoT Cloud website. You can
visit the following link for updated plans, pricing, and features:
https://cloud.arduino.cc/plans/. If you are from an educational institute, then there are
plenty of good plans for students and faculties. Arduino also offers customized plans to
business organizations according to their requirements.
In this section, we have created the Thing and named it. Three further steps are
required adding a device, network configuration, and adding cloud variables. We are
going to cover the remaining steps in the following subsections.
Adding a device
After assigning a name to the Thing, we need to attach a device to it. When you click
on the Select Device button, you will see a popup that shows you an available device
and the option to add a new device. If there is no device, then you will see the
following figure to set up a new device:
Figure 2.6 – Associating a device
In our case, we don’t have any device in the portal, so we will just click on SET UP
NEW DEVICE to configure a new device in the account.
Next, you will see the two options in the popup. The first option is Arduino board,
and the second option is Third party device. Here, you will see an icon in front of
both names, which means you need to use compatible devices with the Arduino IoT
Cloud. Next, you will see two options: one for the Arduino official development
boards and a second option for the third-party development boards.
Figure 2.7 – Choosing a development device
Select one option from the popup according to the available device. For this chapter,
we will click on Arduino board, as in this chapter, we will use the MKR Wi-Fi 1010
board. Before adding the device, make sure that the Arduino Create Agent is running
on your machine.
IMPORTANT NOTE
You can find the Arduino IoT Cloud-compatible boards at https://store-
usa.arduino.cc/pages/cloud-compatible-boards, and for third-party devices, we have three
options, which are ESP8266, ESP32, and LoRaWAN devices. For some devices, we
have API access, which will be discussed in the second part of this chapter.
Next, you will see the Setup Device popup, which will start searching for your device.
So, make sure the device is properly connected to your machine. When the Arduino
Create Agent detects the compatible development board device, the following popup
will be shown:
IMPORTANT NOTE
The device and the Thing have a one-to-one relationship. If you want to use a device with
a new Thing, then make sure it’s not associated with another one.
As we have added the device, let us move toward network configuration.
Configuring the network
After attaching the device to the Thing, we can see that the device is offline. To bring
it online, we need to provide Wi-Fi details. The following figure represents the
network configuration popup, which only consists of two fields:
Figure 2.11 – Network configuration
On the Thing page shown in Figure 2.5, under the Network tab, click on the
CONFIGURE button, which will take you to the Configure network popup with two
fields, Wi-Fi Name and Password. Type the Wi-Fi SSID and password, and then click
on the SAVE button.
In this section, we have configured the network for our device, which is MKR Wi-Fi
1010, and in the next sub section, we will create the cloud variable.
Adding a cloud variable
The final part is adding a cloud variable. Before adding a variable, you have to have an
idea of what type of variables you need for your project, including the variable type,
the variable permission, and the variable update policy.
For the current example, we need one variable to control the built-in LED, so the
variable type will be Boolean (either on/off):
Figure 2.12 – Adding a variable
This way, we will control the LED via the dashboard:
1. Assign a meaningful name to the variable, related to the sensor/actuator type. Remember that
spaces and special characters are not allowed in the name.
2. If you want to sync the variable with other Things’ variables, then click on the Sync with
other Things option. The sync option is very beneficial if you want to share data across other
Things. Sync will be explained in later chapters alongside a practical demonstration.
3. Select the variable type from the dropdown; the platform provides dozens of variable types.
For this example, we need a Boolean variable type for LED control.
4. After selecting the variable type, you will see the variable declaration that will be used during
coding. You can see here that our variable name is LED, but the system has converted the first
letter to lowercase and the rest of the characters are left as is, making the name lED. This
declaration part is very important; you can change the declaration according to your
requirements, but keep the declaration in mind, as it will be used in coding.
5. The variable permission provides two options, Read & Write and Read Only. The permission
provides an extra layer of security for the Thing’s control. If a sensor only senses data such as
temperature/humidity, then choose the Read Only option. If you want to control actuators such
as the relay and the LED, then choose the Read & Write option. For our example, we need to
write data to the variable to control the LED, so we will simply choose Read & Write.
6. Finally, we need to choose an update policy according to our requirements. One option is
event-driven (shown onscreen as On change), which only works when there is a change. It
works when prompted by commands such as turning on/off a relay or LED. The second option
is Periodically, which means taking data from a variable, such as temperature, humidity, air
pressure, or a Light Dependent Resistor (LDR) value after a specific time. When you change
the option to Periodically, it will ask you for a time measured in seconds, whereas for On
change, there is a threshold option.
After adding the variable, our Thing now has all the mandatory ingredients. The
following figure describes all the settings and configurations when we are done with
the cloud variable, device, and network settings. Next, we need to jump to the Sketch
tab for coding:
Figure 2.13 – The Thing after configuration
The preceding screenshot illustrates the device association, network configuration, and
variable settings, which are essential components of the Thing. Next, click the Sketch
tab, where you will open the Arduino Web Editor for coding. Here, we will add the
code that will be associated with the LED variable. In this section, we have completed
all the tasks via drag and drop, but now it’s time to do some work by putting some
coding into our development board. In the next section, we will explore sketches.
Writing a sketch
Most Things are set up in the cloud via a graphical user interface (GUI), but we still
need to do some coding. The following figure describes all the options of the mini web
editor, such as verifying and uploading the code, selecting the development board on
specific ports, and the code area for writing and editing.
Figure 2.14 – Mini web editor
The code will associate a variable with physical sensors/actuators to make it work
properly. Please see the following steps:
1. Here, you will see two buttons, like with the Arduino IDE. The tick button is used to verify
code, while the arrow icon button is used to upload the code to the development board.
2. This part shows whether your device is connected to your machine or not. If the development
board is connected, then it will show the device name with the port.
3. The Arduino Cloud Editor has two variants – one is basic and the other is full. In the Thing tab
shown in Figure 2.14, we can see the mini version of the editor, but if you want to move to the
full editor for the installation of libraries or other stuff, then click on the </> button.
4. Scroll down the editor, and at the bottom, you will see the OnLEDChange() function, which
is associated with the LED variable. In this function, we need to write the code that will
provide connectivity to the sensor/physical pins of the development board.
if(lED==1)
{
digitalWrite(LED_BUILTIN,1);
}else{
digitalWrite(LED_BUILTIN,0);
}
First, let’s recall the declaration used during variable creation, which is shown in
Figure 2.12. What the code does is turn the built-in LED on if the lED variable
contains a true value; otherwise, it turns the built-in LED off.
To write Boolean values on development board pins, we have a method called
digitalWrite, which takes two parameters. The first parameter is a pin number and
in the second parameter we will place true/false or 1/0, while we are using
LED_BUILTIN, which is a constant and contains PIN #13. The second parameter is a
value, which is either 1 or 0. This parameter changes according to the lED variable
state. Here we are done with our coding exercise. Now it’s time to create a graphical
user interface from where we turn on/off the LED. In the following section, we will set
up the dashboard to control the LED.
Now that we have created the dashboard, it’s time to put a widget on it. Widgets will
help us to control/view the sensors/actuators. When you click on the Add button, you
will see the list of widgets. Here you can select a widget by scrolling through the list or
by searching the widgets via the search bar, as shown in the following figure:
Figure 2.16 – The widgets list
Select the Switch widget control for the current example project. After selecting the
widget control, a popup will appear, where we need to link the Thing variable with the
widget control to read/write the data to the device sensors. This is because the variable
is the bridge between the dashboard widget controls and the Thing sensors to read and
write data.
In the widget popup, we have different settings, as shown in the following figure:
Figure 2.17 – Widget settings
The widget settings are detailed as follows:
1. Firstly, we need to assign a name to our widget. Make sure to give it a proper name that
represents the sensor’s name. Here, I used the name LED-Switch.
2. Hide or show the widget frame content, which is at the top and bottom of the widget.
3. Click on Link Variable to attach the Thing variable to the widget control, which will be
explained in the next figure.
4. Hide/show the widget label to hide the text that overlays the widget control. In the preceding
figure, it switches the ON/OFF button text.
It’s time to attach the widget control to the variables. Note that we can add multiple
controls on the same dashboard that are linked to different Things’ variables, which
shows the versatility of Arduino IoT Cloud dashboards, as shown in the following
figure:
After selecting the variable from the specific Thing, click on the LINK VARIABLE
button, and you will see the variable details in the widget control popup. From there,
you can change or detach the variable. Finally, click on the DONE button; now, our
dashboard is ready, with a widget control to send commands to the Thing. Just click on
the eye icon on the dashboard to make it operational. After that, start testing the
dashboard controls.
Here we are done with our first example project with Arduino MKR1010 and the
Arduino IoT Cloud. Next, you need to solve Assignment 1 of this section. After that,
you will jump into the second section of this chapter, where you will learn how to use
the Arduino IoT Cloud with non-compatible devices, such as Arduino Uno, Raspberry
Pi, and so on via Node-RED.
Assignment 1
Congratulations! You have completed the first part of this chapter successfully, and I
hope you enjoyed that journey. Now, it’s time to verify what you have learned so far
by giving you a small assignment:
1. Attach three differently colored LEDs of any color (preferably, red, yellow, and green) to the
Arduino MKR1010 development board on pin numbers 1, 2, and 3, respectively.
2. Set up a new Thing with the name IoT-Based Traffic Lights Control.
3. Associate the device, configure its network settings, and create variables according to the
number of LEDs. Variable names should be based on LED colors such as LED_Red.
4. Write the code that will turn the LED on/off according to the variable value. After writing the
code for each LED, verify and upload the code to the development board.
5. Finally, set up the dashboard with the name Traffic Light Control Dashboard.
6. Add the Switch buttons according to the number of LEDs, and link them with their associated
variables.
7. Test the LEDs by switching them on/off via a dashboard.
IMPORTANT NOTE
Try the Push Button widget control along with the Switch button widget control. Verify
whether one variable allows you to connect with more than one widget. Also, verify the
behavior of the Push Button widget control by turning the Switch button on/off.
Our world is full of different types of technologies. Whenever a new innovation comes
on the market, it always provides compatibility with older devices. In the Arduino IoT
Cloud, we have a list of devices that are currently supported, but there are millions of
devices that are not compatible with the Arduino IoT Cloud. So, while in the previous
section of the chapter, we practiced an example with Arduino IoT Cloud-compatible
development boards, next, we are going to look at how we can connect/use non-
compatible devices with the Arduino IoT Cloud, such as Arduino UNO, Raspberry Pi,
BeagleBone, and so on.
Introducing Node-RED
Node-RED is a free, open source visual programming tool for IoT and other
applications. It was developed by IBM Emerging Technology and was first released in
2013. Node-RED provides a web-based interface to wire together hardware devices,
APIs, and online services in new and interesting ways. The tool uses a graphical flow-
based programming language, making it easy for users with little or no programming
experience to build complex IoT systems. Node-RED has become popular in the IoT
and smart home communities for its ease of use and ability to integrate with a wide
range of devices and services.
Node-RED is a flow-based development tool for IoT and other applications. It
provides a visual, drag-and-drop interface to connect different devices, APIs, and
online services. With Node-RED, users can wire together inputs, outputs, and
functions to create sophisticated IoT solutions. As well as being open source and free
to use, Node-RED has a large user community and a library of pre-built components.
With all Node-RED’s aforementioned benefits, the following question arises: why do
we need to use the Arduino IoT Cloud? At the start of the chapter, I mentioned that the
Arduino IoT Cloud only supports a few development boards natively. Even Arduino
doesn’t support all of their development boards, especially Arduino UNO, Arduino
Mega, and Raspberry Pi from the Raspberry Pi Foundation, which are very famous
among makers and hobbyists and used by industry. The solution to this is Node-RED,
which is compatible with most development boards and has an Arduino IoT Cloud
module, making it easier for developers to integrate non-compatible devices with the
Arduino IoT Cloud.
Node-RED can be used with the Arduino IoT Cloud with several benefits:
Ease of development: Node-RED’s visual, drag-and-drop interface makes it easy for users to
connect Arduino boards to the cloud and build IoT applications quickly
Integration with the Arduino IoT Cloud: Node-RED has built-in support for the Arduino
IoT Cloud, allowing users to easily connect their Arduino boards, as well as other development
boards, and send data to the cloud
Flexibility: The flow-based programming model of Node-RED makes it easy to build and
modify complex systems
Flow-based programming: Node-RED’s flow-based programming model is well suited to
building IoT applications, as it allows users to quickly connect inputs, outputs, and functions to
create sophisticated systems
Open source: Node-RED is open source, allowing users to access the source code and make
modifications if necessary
Large user community: Node-RED has a large and active user community, providing access
to a wealth of information and pre-built components
These benefits make Node-RED a good choice for developing Arduino-based IoT
applications and connecting them to the cloud. By using Node-RED, users can
leverage the power of the cloud to store, analyze, and visualize data from their IoT
systems. In this section, we have discussed the features and benefits of Node-RED.
Now it’s time to take a practical look by implementing the example project. The
following sections will take you through the implementation of the project step by
step.
Here we have discussed the interface of Node-RED with all the main options. In the
following section, we will look at how to install the Arduino IoT Cloud module for
Node-RED, and in the subsequent sections, we will see its implementation.
Installing the Arduino IoT Cloud module for Node-
RED
For Node-RED to communicate with the Arduino IoT Cloud, we need to install the
Arduino IoT Cloud module, which was officially developed by the Arduino team.
Click on the navigation icon in the top-right corner of the app and then click on
Manage palette. After that, you will see a popup like the one in the following figure:
Now that we have installed the module, it’s time to have a look at what type of nodes
are available in the Arduino IoT Cloud module. Close the installation palette, scroll
down through the nodes to the bottom, and you will arrive at the Arduino IoT Cloud
section, as shown in the following figure:
In this section, we have discussed the nodes to work with the Arduino IoT Cloud, that
are available to developers from the Arduino IoT Cloud module. Next, we will set up
the API, cloud variables, and dashboard to proceed further.
The following is a complete flow of nodes. It shows the entire workflow, from getting
variable values to the final node, which sends a value to the cloud based on input:
Figure 2.24 – A complete flow of the Node-RED project
The node workflow is broken down as follows:
1. The first node is the IN node. Select the variable that you want to read; I selected the LED
variable.
2. Add the switch node (node 2) to the flow; it can be found in the Functions tab on the left
sidebar of the page. This node is responsible for taking the value from node 1 and selecting the
specific node from 3 or 4, according to the value. Link the Arduino IN node to the switch node.
After linking, double-click on the switch node, where we need to specify the switch cases.
Figure 2.25 – Switch node options
To edit the switch node, follow these steps:
1. Firstly, assign a name to the node and then add the switch cases.
2. In our current exercise, we have two switch statements: the LED is either true or false, which
means on or off. By default, there is only one option – click on the small +add button to insert
a new case. Input the values 1 and 0, and we will then have two flows.
The change nodes (3 and 4) are responsible for sending content to the next node,
which is 5. Drag 3 and link it with the switch node, as shown in Figure 2.24. Node 3
represents the True/1/On value. Double-click on this node. Now, click on the drop-
down icon, which is marked by a red box in the following figure, select the Boolean
type, and then select true.
Finally, we are done with all the node configurations and linkage. Click on the Deploy
button shown in Figure 2.19 and move back to the device dashboard in the Arduino
IoT Cloud. Remember to keep MKR1010 on and connected to the internet. Now, click
on the switch button to turn the LED on/off, and wait for a few seconds to get an
updated value from Node-RED. In the background, Node-RED will send the value to
the LEDStatus Arduino IoT Cloud variable according to the Node-RED LED
variable, and the status widget will be changed accordingly.
In the second part of the chapter, we have explored how to connect non-compatible
IoT development boards with the Arduino IoT Cloud using Node-RED. Next up is
Assignment 2, which is specially designed for you to practice with different
experiments.
Assignment 2
Continue the previous assignment, where you connected three LEDs to MKR Wi-Fi
1010 and the Arduino IoT Cloud setup:
1. Create three status variables in the Thing, according to the LED name such as Red, Yellow and
Green, to the previously-set-up Thing.
2. Add three status widgets to the previously-set-up dashboard and attach newly created status
variables to them.
3. Set up three different flows for each LED and deploy the flows.
4. Verify the status widgets by turning the LEDs on/off with the Switch button widget.
Summary
This chapter is the first chapter where we explored how to connect devices with the
Arduino IoT Cloud using a basic LED on/off example. In the first part, we used an
Arduino IoT Cloud-compatible development board, which was the MKR Wi-Fi 1010
board, where we learned how to create Things and cloud variables, how to associate
devices, how to configure networks, and how to create sketches. At the end of that
section, there was an assignment for you to practice on.
In the second part of this chapter, we explored how to connect non-compatible
development boards, such as Arduino UNO, Arduino Mega, and Raspberry Pi, with
the Arduino IoT Cloud, using Node-RED and the Arduino API interface. Here we
have explored Node-RED, the Node-RED module for the Arduino IoT Cloud, and
generating API keys in the cloud. This part of the chapter helped teach you how to use
non-compatible existing technologies with the Arduino IoT Cloud.
Arduino has a lot of options in the Arduino IoT Cloud, such as Things, devices,
dashboards, and a lot of widgets for dashboards and the Arduino Web Editor. So, in the
next chapter, we will explore all those options in detail before moving on. Chapter 3 is
very important for you to better understand all of the Arduino IoT Cloud options.
3
Technical requirements
For this chapter only, Arduino IoT Cloud access is required to explore the different
functionalities and dashboard control widgets we’ll cover in this chapter.
Dashboards
The Arduino IoT Cloud offers very versatile dashboards with lots of options, providing
an awesome experience for users. Dashboards consist of different features, including
widgets, which are categorized into input and output, responsive design options for
mobile and web, and lots of other features. The following figure summarizes all the
features of a dashboard, which will be discussed in detail step by step in the following
sections:
CloudTimeVariable = ArduinoCloud.getLocalTime();
After fetching the local time, you can use CloudTimeVariable to sync your Thing
operations. Use the preceding code in the setup method.
In this section, we discussed the time picker widget, including how to set the time for
this widget control by using the Time cloud variable type. Now, we will discuss
another configuration widget control, the Scheduler Widget control, which helps you
set the time to automate your operations on IoT devices.
Scheduler (configuration)
Scheduler is another important utility in Arduino IoT Cloud to automate a process.
With this widget, we can automate lots of operations without human intervention, just
like a cron job that executes processes/methods at a specific time.
So, where we can use this Scheduler feature in our IoT solutions? There are many use
cases, including outdoor light automation, watering systems in agriculture, and animal
feeders for poultry farms.
The following screenshot of the Scheduler widget shows the many options to schedule
our processes/methods:
if (scheduleVariable.isActive()) {
digitalWrite(LED, HIGH); // whenever the job is "active",
turn on the LED
}
else{
digitalWrite(LED, LOW); // whenever the job is "not active",
turn off the LED
}
We can get the active/not active status of every Schedule cloud variable by accessing
its isActive() method. Use the aforementioned code in a device loop – if the
Schedule cloud variable is active, then execute the given processes/methods;
otherwise, stop them. Why do we need to execute the preceding code snippet in a
loop? Because the loop() method is the main method in Arduino, which always
executes.
In this section, we discussed Scheduler in detail, what type of cloud variable is used by
this widget, and how to access the Scheduler status to perform a specific job. This is
the last control in input widgets. Now, we will look at the output control widgets. In
the following section, all the output controls will be discussed in detail to give you a
better understanding of how to implement these controls in your professional projects.
valueCloudVariable = analogRead(A0);
Here, we discussed the value widget control, which is used for both input and output
purposes. Now, we will explore the status and LED control widgets.
Status and LED
Our next widgets are status and LED, as shown in Figure 3.9. Both widgets work
very similarly but are different in UI/UX. These widgets have only two states to
display either true or false. These widgets only display the state; they don’t provide
any option to control them, and they both work with the bool type cloud variable. Use
cases for these widgets include indicating the Thing status (on/off) – for example, a
water pump’s status in smart agriculture, or whether a door is open or closed in a smart
home. Just assign true/false to the bool cloud variable type, which is linked to the
status widget after performing a specific task.
The following example code demonstrates how we can change the value of
statusCloudVariable to change the status/LED widgets’ appearance:
Void loop(){
digitalWrite(1,HIGH);
statusCloudVariable=true; //Assign true to Status Widget
delay(5000);
digitalWrite(1,LOW);
statusCloudVariable=false;//Assign false to Status Widget
delay(500);
}
The preceding code shows how, after performing the digitalWrite operation, we
change the value of statusCloudVariable according to the current condition to
update the status widget.
Gauge and percentage
Finally, we have the gauge and percentage widgets shown in Figure 3.9, which can be
used to make your dashboard spicy and provide a stunning information display
experience to your users. Both of these widgets can be linked to the integer or
float cloud variable types. Comparing the gauge and percentage widgets, we can see
a clear difference in UI/UX design – gauge uses a half-circle to display a sensor
reading, while the percentage widget uses a full circle featuring icons, for which you
can specify the color if a value goes below or above a given threshold. However, the
working of both widgets is essentially the same. Gauge can be used to display gas-
related readings, such as air quality, carbon dioxide levels, and temperature, while the
percentage widget is best for displaying humidity, battery level, Light-Dependent
Resistor (LDR) values, and so on.
Here, I haven’t provided the sample code for the gauge and percentage widgets, as it’s
very similar to the preceding example – just assign the values of the sensors to the
gauge- and percentage-linked cloud variables.
IMPORTANT NOTE
As a little exercise, create an integer type variable named MultiDimmVariable, and
drop a gauge, percentage, and slider widget on the dashboard. Link these three widgets
with the same MultiDimmVariable cloud variable you created. Now, you can have a bit
of fun; just change the slider position and see how the gauge and percentage widgets
react.
In this section, we discussed all the major output controls, which include value, status,
gauge, percentage, and LED, step by step, and their usage and code. Now, we will look
at maps and charts widgets, which are the most important widgets to display for
location and time-series data.
location=Location(32.045948421308715, 72.72505696868048);
The preceding code is used to assign a location whenever your device receives data
from a GPS module. This map widget is only capable of showing one location at a
time. If you have multiple objects for which you want to display tracking, then each
object will need its own map widget.
Chart
So, we can use the gauge or percentage widgets to display the current value of a
sensor, but what if we want to display the current value as well as historical data? For
this, chart is your best option, which is used to display current readings alongside
historical readings for better visualization and comparison.
The Chart widget shown in Figure 3.10 uses the integer or float cloud variable
types, which as discussed previously are appropriate to monitor temperature, humidity,
air quality, and so on. Just link any cloud variable with the chart widget for data
visualization. Other use cases include light levels, energy consumption, and levels of
different gases in industry.
IMPORTANT NOTE
For quick testing, just drop the slider and chart widgets on a dashboard and link both of
them with the same integer cloud variable type. After that, just change the value of the
slider, and you can observe how charts work.
Here, we discussed both the map and chart widget controls in detail. Now, we will
explore messenger and sticky note controls.
stringMessengerVariable = PropertyActions::CLEAR;
You can also integrate the messenger widget with third-party tools such as Slack and
Discord, via either an API or Zapier integration.
Sticky notes
The sticky note widget works just like simple Windows OS Sticky Notes. It helps you
to write down your project progress, or you can write anything on a sticky note to
maintain your dashboards. It helps you in a situation where you have dozens of
dashboards and you want to add some comments about specific dashboards.
For the latest updates and details about dashboard widget controls, please visit
https://docs.arduino.cc/arduino-cloud/getting-started/dashboard-widgets.
In this section, we discussed both the messenger and sticky note widgets. Sticky notes
make it easy to maintain projects and write down comments about project progress or
maintenance, while messenger has a broader use. We also discussed how sensor data is
related to AI. We have now completed all of our input and output widget controls,
Now, we will dive deep into the Arduino Web Editor, where we will explore all the
options step by step.
Here, we discussed the Arduino Web Editor interface. Now, we will discuss
Sketchbook, Examples, Libraries, Monitor, References, and Help, as well as the
Preferences and Features menus in detail. We will discuss all the options in depth so
you will get a broader overview of the Arduino Web Editor, allowing you to utilize its
features fully during your development.
Sketchbook
This menu option is responsible for sketch organization, creation, code download and
upload, and so on.
Figure 3.13 – The Arduino Web Editor sketchbook
The numbers in the preceding screenshot correspond to the following elements of the
sketchbook screen:
1. The NEW SKETCH button is used to initialize a new set of files for a new project. To the
right of this button are two icons – the first is used to create a folder for project organization,
and the second is used to import any existing Arduino IDE code/libraries into the Web Editor if
required.
2. Here is where you will find all of your sketches/folders, and you can also search your
sketchbooks with the help of the search bar.
3. The tick icon is used to verify the code, while the arrow icon is used to upload the code to the
development board. From the dropdown to the right of these icons, you can select the
development board and port. Finally, the ellipses button contains a range of options regarding
sketches, such as Save, Save as, Rename Sketch, and Download Sketch.
4. This area is a playground for developers to write code for their devices. Here, you will find two
icons to the right of the screen, the first of which is used to make the code editor full-screen,
while the second is used for code indentation.
5. This is the output terminal where you can get all the information about code compilation
progress and any errors found in your code.
Examples
One of the top features of Arduino IDE is Examples, which is a great resource for
beginners, who can benefit from examples provided by library and sensor developers.
This is presented as a separate menu in the Arduino Web Editor. Figure 3.14 shows the
Example menu with two different tabs. The first tab shows the BUILT IN examples,
while the second tab shows the FROM LIBRARIES examples.
Assignments
This chapter is longer in length than the previous ones, as we want to give you an in-
depth overview of Arduino IoT Cloud and its main pillars, which include Things,
devices, dashboards, integrations and templates, progressing to further chapters. In this
chapter, we have discussed dashboards, input and output widget controls, as well as the
Arduino Web Editor in detail. To consolidate what you have learned in this chapter, we
have created three different assignments for you. These assignments will help you to
understand the core concepts necessary to proceed with the book, as well as in your
professional projects.
Make sure to attempt all the assignments given ahead.
Assignment 1
ASNA Group is a leading ISO-certified salt supplier organization in Pakistan. The
organization processes salt according to international standards, but they are facing
issues in warehouse monitoring, where they want to maintain the
temperature/humidity in line with the standards, to avoid issues with the finished
product. Right now, they have five warehouses to monitor. They want multiple views
for data monitoring and analysis. You need to keep the following questions in mind
while developing a solution for ASNA Group:
1. Firstly, identify what type of industrial-grade sensors/development boards are required for this
monitoring scenario.
2. Is there any calibration required for the sensors? If so, how will you calibrate the sensors? If
not, provide a reason why it’s not mandatory.
3. What type of widgets are required to visualize the information on a dashboard?
4. How you could visualize readings from five warehouses on one dashboard?
5. What type of widgets will be used on the dashboard to allow users to analyze readings
covering a long period of time?
6. By what means will you give the company access to the dashboard?
Assignment 2
Imzlab Technologies Private Limited is a leading smart agriculture solution provider.
The company has deployed custom-designed sensors in the field, using ESP32 and the
Arduino IoT Cloud, to measure soil moisture, soil temperature, and outdoor
temperature/humidity. On the dashboard, they have different widgets for data
visualization. They now have a new requirement from a customer to integrate a water
pump control and display its status history (on/off). The customer also requires that on
Monday and Thursday, the water pump will run from 5:00 p.m. to 7:00 p.m., and on
Sunday, from 4:00 a.m. to 6:00 a.m., in the GMT+5 time zone. On other days, the
pump status will be controlled manually. You need to keep the following questions in
mind while developing a solution for Imzlab Technologies Private Limited:
1. What type of control widgets are required to display and control the water pump status?
2. How can you provide a solution for automatic pump control on specific days and at specific
times?
3. Is it possible to visualize the water pump on/off status history using charts? If so, how? If it’s
not possible, provide an alternative solution to meet the customer’s requirements.
Assignment 3
A group of researchers at Imzlab Technologies Private Limited is working on a
monitoring system to monitor carbon dioxide levels. They are using MKR 1010 and
the Arduino IoT Cloud, but they are trying to use a custom sensor developed by
Tingstack LLC. In the Arduino Web Editor, there is no library for this sensor, but
Tingstack LLC has developed an in-house library for the Arduino platform. The
researchers also want to share their code with the Tingstack LLC team for review.
Identify the problems from the preceding paragraph, and write down their solutions.
Summary
This chapter was just like understanding the ingredients and kitchen tools we have
before we start cooking. Firstly, we learned about how the Arduino IoT Cloud
components work, including Things, devices, dashboards, integrations, and templates.
Then, we studied all the input/output widget controls to get a proper idea of their
potential usage, including some example code and the cloud variable types. In the
following section, we examined what the Arduino Web Editor is and how its different
features work, including examples, libraries, and the Serial Monitor. You should now
have a good understanding of all the different ingredients of the Arduino IoT Cloud
and the Web Editor and how to employ them appropriately.
This chapter was most important before starting the next chapters, as it gives you an
in-depth overview of all the main pillars of the Arduino IoT Cloud and how they work
in real time, which will help you to understand how the Arduino IoT Cloud works.
Arduino dashboard widgets are also very important to us, as we will use different
widgets in different projects throughout the book, so giving you an overview here has
prepared you for upcoming chapters, helping you to understand what types of things
are mandatory for professional projects and what type of controls make your project
more robust and professional.
In the following chapter, we will start work on our first project, where we will build an
air-quality monitoring system from scratch to deployment. You will learn why air-
quality monitoring is necessary and what types of development boards/sensors are
required. We will also use a Printed Circuit Board (PCB) for proper deployment,
which will be explained in depth. After a section on the necessary hardware, we will
set up Things, cloud variables, devices, and network configurations and coding for a
device, as well as a dashboard for proper data visualization. So, gear up for the
upcoming chapter, which will be fun for all of you.
Part 2: Getting Hands-On with Different
Communication Technologies
The second part of the book describes the different communication technologies
involved in IoT projects and provides four different practical projects to demonstrate
their usage and how third-party components can be adopted in combination with the
Arduino IoT Cloud.
This part has the following chapters:
Chapter 4, Project #1 – A Smarter Setup for Sensing the Environment
Chapter 5, Project #2 – Creating a Portable Thing Tracker Using MKR GSM 1400
Chapter 6, Project #3 – A Remote Alarming Application with LoRaWAN
4
Technical requirements
The following hardware components are required to understand this chapter:
WeMos D1 MINI ESP8266
A DHT11/DHT22 sensor/module
The MQ-135 air quality module
A PCB (a link is available in the PCB design and assembling hardware components section)
Female headers
Jumper cables
For coding, we will use the Arduino Web Editor, which includes a large collection of
development boards and sensor libraries, and the Arduino IoT Cloud for Thing and
dashboard setup. To develop hardware and sensor designs, we will need Fritzing
desktop software.
The code for this chapter is available at the book’s official GitHub repository, or you
can directly download the code by following this link:
https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-
Developers/tree/main/Chapter%234%20Project%231%20Sensing%20and%20Monitor
ing%20the%20Air%20for%20Clean%20Environment.
Overall, air quality monitoring is an essential tool to protect public health, preserve the
environment, and promote sustainable economic development. Now we’ve had a
theoretical review of air quality monitoring, it’s time to explore the project practically.
Firstly, we will start with the hardware, where we will explore all the required
components such as development boards, sensors, design diagrams, and PCB design
for implementation. Later, we will set up the Thing and cloud variables, upload code to
the development board, and set up the dashboard for data visualization.
5V VCC VCC
A0 A0 -
D1 - Data
Table 4.2 – Pin configuration table for sensors
According to the design (Figure 4.4 and Table 4.2), we have a common 5V output and
GND from the development board to both sensors. The MQ-135 sensor is an analog
sensor, so we connected its AO pin to the AO pin of the WeMos development board,
while DHT11/DHT22 are digital sensors, and their Pin 2 is connected to the D1 pin of
the development board.
Here, we have given an overview of the Thing and we also discussed the required
steps that will be carried out to complete the Thing setup.
Cloud variables
The following table explains all the properties of the variable that we need to use when
we create the cloud variable. An integer is a very famous data type, but we will use
two new variable types for humidity (CloudRelativeHumidity) and temperature
(CloudTemperatureSensor), which measure data in percentage and Celsius,
respectively. Next, make sure to declare the variables exactly as stated in the given
table, including case-sensitive names and variable types. If the example code does not
match your naming, you will need to modify it accordingly.
After setting up the device and associating it with the Thing, it’s time to configure the
device network settings. The following sections will cover all the steps to configure
your device for a Wi-Fi network.
Network
After associating the device with the Thing, it is time to configure the Wi-Fi settings
for device communication. Fill in the form with Wi-Fi Name and Password:
Figure 4.9 – The network configuration for the Thing
In Figure 4.9, you will find a new field for Secret Key. Paste the secret key that we
received from the system during the device association process, which is explained in
step 6 in the preceding subsection.
Now, we are done with the device association to the Thing as well as with network
settings. The next step is to understand and upload the code. The following section will
guide you through the code.
Coding
The chapter’s code is available at the book’s official GitHub repository, or you can
directly download the code by following this link:
https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-
Developers/tree/main/Chapter%234%20Project%231%20Sensing%20and%20Monitor
ing%20the%20Air%20for%20Clean%20Environment/Sense_the_Environment_feb24
a
You can download the code and put it into your Thing by navigating to the Sketch tab.
We will not discuss the code any further, as you will get an idea of how it works after
reading it. Instead, we will explain the main workflow, which involves initializing all
the things in the setup method and using milliseconds to calculate the delay time.
Remember to never try using the delay method, as it will block the
ArduinoCloud.update() method and then call the STHAM method every five
minutes. The following code is demonstrating how to fetch Temperature and Humidity
values from dht object, and for airQuality we are simply using analogRead()
method.
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
temperature=0;
}
else {
//Send Temperature to Cloud
temperature=event.temperature;
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
humidity=0;
}
else {
//Send Humidity to Cloud
humidity=event.relative_humidity;
}
//Send Air Quality to Cloud
airQuality=analogRead(A0);
The preceding code snippet was taken from the STHAM method; here, we just modified
the code to show you how we send values to the Arduino IoT Cloud after taking values
from the sensors.
In a previous section, we created the cloud variables. Just recall the cloud variable
declaration and assign the sensor readings to those variables. This cloud variable
declaration is available in the thingProperties.h file. So, when you assign the
values to these variables, the ArduinoCloud.update() method in the loop will
automatically send data to the cloud.
Upload the code to the device and verify the connectivity and readings. If you want to
change the reading time, then just modify the interval variable value. Make sure you
provide the time in milliseconds, where 1 second equals 1,000 milliseconds.
IMPORTANT NOTE
If you used different naming in the variable declaration, then update the code according to
your naming scheme. However, it’s better that you first follow all the steps according to the
book and later change the cloud variable names and modify your code, in that order.
Never try to use delay method, which will create a block for the
ArduinoCloud.update() method. Always use milliseconds to calculate the waiting
time. Review the loop() method to understand how we call the method after 5 minutes.
The Arduino IoT Cloud only updates the value on the dashboard whenever a variable
value is changed. For example, if the temperature is 30 and is still the same after 5
minutes, then the Arduino IoT Cloud will not record the value, so don’t get confused if
values don’t change on a graph. This is another benefit of the Arduino IoT Cloud: you will
not get duplicated data when you export the content.
We have successfully set up the Thing, which includes cloud variables, device
association, network configuration, and code, and uploaded it to the development
board. Now, it’s time to explore the dashboard and sensor values visualization in the
following section.
What’s next?
We still have a lot of options available to explore, but now it’s your turn to use
different sensors and development boards to do some more experiments and learn from
them. In this chapter, we have only used two sensors, which only offer three
parameters, but there are a lot of sensors on the market that provide a wide variety of
functionalities, such as air pressure and measurements for different gases.
Try out the following sensors to enhance your practical knowledge and compare them
with other sensors in terms of features, range, and cost:
The BMP280 (pressure and temperature) sensor
The MH-Z19C/D/E series sensors for carbon dioxide monitoring
The MQ series sensors, which are designed to sense different specific gases, including MQ-2,
MQ-3, MQ-4, MQ-5, MQ-7, MQ-8, and MQ-9
Seeed Studio SCD30 (temperature, humidity, and CO2)
Summary
In this chapter, we explored how to develop a low-cost air quality monitoring system
using DHT11, MQ-135, and the WeMos D1 Mini development board. We set up the
Thing, which involved creating cloud variables, associating the device, configuring the
network, and coding the development board. Later, we created a dashboard to visualize
the Thing’s sensor readings with different types of widgets, displaying the current
readings as well as historical data with the help of graphs. Through this project, you
will get the confidence to set up the Thing practically and deploy it in the field using a
PCB. You have learned about new types of cloud variables for sensor readings and
storage, as well as dealing with different types of dashboard widgets.
In the next chapter, we will study GSM technology for IoT. We will learn about
different types of global IoT SIM cards and their usage. This project will also
demonstrate a Smart Assets tracing example, where we will track the asset with a GPS
module and send the data to the Arduino IoT Cloud via global IoT SIM cards. In the
end, you will also learn about new widgets in the Arduino IoT Cloud to visualize the
location of your assets on the basis of GPS coordinates.
5
Technical requirements
The following are the hardware components required to complete this chapter:
MKR GSM 1400/MKR NB 1500
A Hologram global IoT SIM card
A NEO-6M GPS module
A breadboard
Jumper cables
For coding, we will use the Arduino Web Editor, which includes a large collection of
development boards and sensor libraries, as well as Arduino IoT Cloud for Thing and
dashboard setup. To develop hardware and sensor designs, we need the Fritzing
desktop software, and we need Arduino IDE for GPS module testing.
In this chapter, we will use the Arduino IoT SIM card for communication instead of
local SIM providers. Arduino provides a wide variety of data plans for global IoT sim
cards that can be chosen according to requirements. The code for this chapter is
available at the book’s official GitHub repository at this link:
https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-Developers.
Overall, GSM, LTE, and NB-IoT are widely used communication technologies that
offer reliable connectivity, high data rates, security, and compatibility with existing
infrastructure. Here, we have discussed the benefits of GSM/LTE/NB-IoT
communication technologies over other wireless communication technologies. In the
next section, we are going to cover global IoT SIM cards, which is the main pillar of
this chapter.
Global IoT SIM cards provide a cost-effective and flexible solution for companies,
allowing them to deploy IoT devices worldwide. They allow seamless connectivity,
ensuring that devices are always connected to the best available network, regardless of
location.
There are many IoT global SIM service providers. Here is a list of some of them:
Hologram
Soracom
Arduino SIM
Twilio
Emnify
Aeris
KORE Wireless
Sierra Wireless
Teleena
Thales Group
Truphone
UROS
1oT
IMPORTANT NOTE
Before buying an IoT global SIM card from any service provider, please verify whether it
works in your region or not and, if so, what type of services it offers, such as GSM, 3G/4G,
or NB-IoT, as there are many regions where, for example, NB-IoT services are still not
available.
Please note that this is not a complete list, and there are many other IoT SIM providers
available in the market. It’s important to research and compare different providers based
on your specific requirements and needs before making a decision.
Here, we have discussed global IoT SIM cards in detail and listed all the top global
IoT SIM card service providers. Next, we are going to cover what types of hardware
and sensors are required to complete the chapter’s project.
Figure 5.2 – The NEO-6M u-blox GY-GPS6MV2 GPS module and a pinout diagram
The preceding figure illustrates the pinout layout of the GPS module. Pin #1 is a
ground (GND) pin that connects with the onboard GND, while Pin #2 and Pin #3 are
transmit (TX) and receive (RX) pins, respectively, and connect to Pin #13 and Pin
#14 of MKR GSM 1400, respectively. Pin #4 – the voltage common collector (VCC)
– works with both onboard VCC and 5V pins. You can solder the male headers with
the GPS module or directly solder the cables without any header pins.
IMPORTANT NOTE
The GPS module works optimally in an outdoor environment. Make sure there is no
rooftop during testing and deployment to receive a proper signal from satellites.
If you are using the module in a lab, then there will be a chance that the GPS module will
not work properly. Remember that there is a built-in light in the GPS module that blinks
when you start receiving signals from satellites.
In this section, we discussed the MKR GSM 1400 development board, which is a SIM-
enabled board, and the NEO-6M u-blox GPS module, which will provide the GPS
coordinates to the development board. We also discussed their pin layouts. Next, we
will discuss how to connect the GPS module with the MKR GSM 1400 development
board.
5V VCC
GND GND
14 TX RX
13 RX TX
Table 5.1 – MKR GSM 1400 and the GPS module pin connections list
The preceding design provides a full overview of how you can connect a module to a
development board. According to our design, we have 5V and GND from the
development board to the GPS module. The GPS module TX is connected to the RX
(Pin #13) and the GPS module RX pin is connected to the TX (Pin #14) of the
development board. Table 5.1 shows the pin information. Finally, we have built our
prototype by using a breadboard, which is shown in Figure 5.4:
Here, we have discussed what steps will be involved in the Thing creation. In the
following subsections, we will create cloud variables, associate a device to the Thing,
and network settings in separate subsections step by step.
Cloud variables
The following table explains all the properties that we need to use during cloud
variable creation. For Location, we need two different variables to store latitude and
longitude, but thanks to the Arduino IoT Cloud extended group of variables, we have a
Location type variable. Next, make sure each variable matches the declaration in the
table; otherwise, you need to modify the example code according to your naming.
In Table 5.2, during the cloud variables creation, I made the permission read-only.
Although we have the read/write option, in this project, we only want to receive data
from the device instead of modifying it on the dashboard. That’s why read-only mode
is used – to prevent issues with data consistency. Update Policy is set to On change,
as the device will send the data when the GPS module receives new data from
satellites.
Associating a device
After creating the variables, it’s time to add the device and associate it with the Thing.
Before adding the device, connect the development board to the computer and open
the Arduino Create Agent application. Figure 5.8 shows a popup in which we have
options to either select the existing device for association or set up a new device that is
not available in the list:
Figure 5.8 – Associate device
In our case, we already have different devices in the portal, but we want to add a new
MKR GSM 1400 device, so just click on SET UP NEW DEVICE to configure the
new device in the account.
Then, you will see two options in the popup (Figure 5.9). The first option is to set up
an Arduino board, and the second option is to set up a third party device. Here, you
will see a note under both options, Compatible devices ( ), which means you can
only use certain types of Arduino devices as well as third-party devices in the Arduino
IoT Cloud.
Network
After associating the device with the Thing, it is time to configure the network settings
for device communication. These network settings are different from the Wi-Fi
network settings. Both the MKR GSM 1400 and MKR NB 1500 development boards
use SIM technology for communication. For that reason, their network configurations
are different and will vary according to the IoT SIM card service provider. The
following figure (Figure 5.10) shows the Configure network popup for the MKR
GSM 1400, which is totally different to the Wi-Fi configuration due to cellular
communication:
Figure 5.10 – The network configuration for the MKR GSM 1400
Currently, we are using the Hologram global IoT SIM card, and only need to mention
hologram under APN; there is no requirement for the PIN, Username, and Password
details. However, if you use the Arduino SIM, then APN will be prepay.pelion,
PIN will be 0000, and Username and Password will both be arduino. Before using
any other global IoT SIM card, first, take its APN information to set up the network
properly.
Here, we have discussed the network configuration for the Arduino MKR GSM 1400,
which includes the APN, PIN, username, and password. In the next section, we will
cover the code for the development board.
Coding
The chapter’s code is available at the book’s official GitHub repository. Download
A_portable_thing_tracker_using_MKR_GSM1400_apr07a.zip and import it
into the Arduino Web Editor.
You can download the code and put it into your Thing by navigating to the Sketch tab.
Here, I will explain the main workflow instead of all code, we are initializing all the
objects and variables in the setup() method; remember to never try to use the delay
method, as it will block the ArduinoCloud.update() method:
TinyGPSPlus gps;
unsigned long previousMillis = 0;
const long interval = 30000; //milliseconds
In the preceding code snippet, we declare the gps instance and two variables, which
will be used to wait for 30,000 milliseconds (30 seconds) before taking the next
readings without blocking the code.
Next, we will move toward the loop method. Here, we call the FetchGPS() method
after every 30 minutes, which is carried out by comparing currentMillis and
previousMillis without the use of delay:
What next?
We still have a lot of options available to explore, but now it’s your time to use
different sensors and development boards to do some more experiments and learn from
them. In the current chapter, we only used one GPS module, which gave us only four
parameters but, on the market, there are a lot of GPS modules that provide a wide
variety of functionalities; they work under the roof as well as under clear sky, and have
several accuracy features.
While monitoring an asset’s location, there are some other parameters that are very
important to monitor in different industries, such as temperature and humidity, which
are very important in food and medical products. CO2 and LPG gases are very
important to monitor during fuel transportation. Try different sensors with a GPS
module to set up different tracking prototypes for different industries.
Summary
In this chapter, we explored how to develop a GPS-based tracking system using a
global IoT SIM card and GPS module. We set up the Thing, which included cloud
variable creation, device association, GSM network configuration, and coding a
development board. Later, we created a dashboard to visualize the Thing readings with
different types of widgets to display current readings, with the most important widget
of the chapter being the Map widget. It is a very interesting and important widget to
display the location of IoT devices using GPS coordinates.
GPS tracking is a very important aspect that we covered in this chapter, and it helps us
to develop a device for our asset tracking, which will help us in asset tracking and
monitoring. This chapter demonstrated how we can display the location of a device on
the dashboard, which gives you the confidence to build more solutions regarding asset
tracking. In the next chapter, we will explore another long-range communication
technology, called LoRaWAN. We will use this technology to build a solution for
remote monitoring distant areas as well as compare this technology with GSM/4G/LTE
and NB-IoT technology for proper guidance.
6
Technical requirements
The following hardware components are required to complete the exercise in this
chapter:
MKR WAN 1300 or MKR WAN 1310
The Things Indoor Gateway
The NEO-6M u-blox GPS module
A breadboard
Jumper cables
To code, we will use the Arduino Web Editor, which includes a large collection of
development boards and sensor libraries, and the Arduino IoT Cloud for the Thing and
dashboard setup. To develop hardware and sensor designs, we need the Fritzing
desktop software, and we need the Arduino IDE for GPS module testing.
In this chapter, we will use the The Things Indoor Gateway for LoRaWAN
communication. The code used in the chapter is available in the book’s official GitHub
repository by following this link: https://github.com/PacktPublishing/Arduino-IoT-
Cloud-for-Developers.
Usage in IoT
LoRaWAN has been widely adopted in various IoT applications due to its unique
features. Some common use cases include the following:
Smart agriculture: LoRaWAN can be used for soil moisture monitoring, crop health
monitoring, livestock tracking, and precision farming, allowing farmers to optimize their
operations and increase yield
Smart cities: LoRaWAN can enable smart street lighting, waste management, parking
management, and environmental monitoring, helping cities become more efficient and
sustainable
Industrial monitoring: LoRaWAN can monitor equipment health, track assets, and improve
supply chain management in industrial settings, leading to better maintenance practices and
reduced downtime
Utilities: LoRaWAN can be used for smart meters and to remotely monitor utility
infrastructure, such as water and gas meters, improving billing accuracy and resource
management
Environmental monitoring: LoRaWAN can support applications such as air quality
monitoring, water quality monitoring, and wildlife tracking, helping researchers and
organizations gather valuable environmental data
Asset tracking: LoRaWAN enables real-time tracking of assets, such as shipping containers,
vehicles, and valuable equipment, ensuring their security and efficient utilization
While LoRaWAN offers these advantages, it’s important to note that no single
communication technology is universally superior. The choice between LoRaWAN
and other technologies (such as cellular, Wi-Fi, Bluetooth, or Zigbee) depends on the
specific requirements of the IoT application, including factors such as range, power
consumption, data rate, cost, and scalability. Each technology has its strengths and
weaknesses, and the selection should be based on a careful analysis of a project’s
needs.
In this section, we have discussed the benefits of using LoRaWAN. In the next section,
we will explore the important components of LoRaWAN.
In this section, we have discussed LoRaWAN components in detail, and in the next
section, we are going to explore the hardware and sensors that are required to execute
the practical exercise of this chapter.
14 (TX) RX
13 (RX) TX
VCC VCC
GND GND
Figure 6.5 – The final prototype MKR WAN 1300 and GPS module
After soldering the male headers to the GPS module, connect the pins according to the
schematic diagram. There is only one sensor, so there is no requirement for the
Veroboard. Next, we will test the GPS module using Arduino’s Serial Monitor tool to
verify that our GPS module works properly and gets values from GPS satellites.
In the setup, we have initialized Serial and Serial1. Serial is used to display the
content to the Serial Monitor (the magnifier icon in the top right of the Arduino IDE)
on screen, while Serial1 is the hardware serial that is used to communicate with the
GPS module. The preceding code belongs to the loop() method.
First, the GPS module will read data from satellites using the Serial1.read()
method and encode it via the gps.encode() method. Serial1 only reads one
character at a time, so it will take a little bit of time for the updated values. Then, we
will verify whether there is any update in Latitude and Longitude coordinates by
using the gps.location.isUpdated() method. If there is a change, then the data
will be printed on the Serial Monitor.
IMPORTANT NOTE
Make sure your GPS module is placed in an open environment where you have a clear
sky, without any obstruction such as a roof or anything that stops you from receiving
proper signals from satellites.
The GPS module has an onboard built-in LED that starts blinking when it starts receiving
data from GPS satellites.
The same code will work with the MKR WAN 1310 without any modification.
Figure 6.7 shows the Serial Monitor with values from the GPS, which includes
Latitude, Longitude, and other parameters:
Figure 6.7 – The GPS module data on the Serial Monitor
The preceding figure shows the data that is received by the GPS module from GPS
satellites and printed on the Serial Monitor. The data includes the satellite count, the
latitude and longitude that represent the location coordinates, the speed in MPH based
on current and previous GPS coordinates, and the altitude in feet.
In this section, we tested the NEO-6M u-blox GPS module in the Arduino IDE. First,
we installed the TinyGPSPlus library for the module, and later, we used the
aforementioned code for the development board, which shows the readings on the
Serial Monitor. In the next section, we will start with the Thing setup in the Arduino
IoT Cloud.
Cloud variables
The following table explains all the properties of the variables that we need to create.
For the location, we need two different variables to store the latitude and longitude, but
thanks to the Arduino IoT Cloud extended group of variables, we have a Location-
type variable. Then, make sure each variable matches the declaration in the table;
otherwise, you will need to modify the example code according to your naming.
As shown in Table 6.2, when creating the cloud variables, we set the permission to
Read-Only. Although we have the Read/Write option, in this project, we only want to
receive data from the device instead of modifying the data via the dashboard. That’s
why read-only mode is used – to avoid issues in data consistency. Update policy is
set to On Change, as the device will send the data when the GPS module receives new
data from satellites.
Associating a device
After creating the variables, it’s time to add the device and associate it with the Thing:
1. Before adding the device, connect the development board to the computer and open the
Arduino Create Agent application. Figure 6.9 shows a popup in which we have options to
either select the existing device for association or set up a new device that is not available on
the list.
Figure 6.9 – Associate device – selecting a device
In our case, we already have different devices in the portal, but we want to add a new
one, MKR WAN 1300, so just click on SET UP NEW DEVICE to configure the new
device in the account.
2. Then, you will see three options in the popup. The first option is Arduino board, the second
option is Third party device, and the third option is Any Device, which is for non-compatible
devices. This means you can now use all types of Arduino devices as well as third-party
devices with the Arduino IoT Cloud, which supports Python, MicroPython, and JavaScript.
Coding
The code for this chapter is available in the book’s official GitHub repository.
Download the A_remote_asset_tracking_using_LoRaWAN_aug30a.zip file and
import it into your Arduino Web Editor.
You can download the code and put it into your Thing by navigating to the Sketch tab.
Here, I will explain the main workflow in which we are initializing all the variables
and serial instances in the setup() method. Remember to never try to use the
delay() method, as it will block the ArduinoCloud.update() method:
TinyGPSPlus gps;
unsigned long previousMillis = 0;
const long interval = 30000; //milliseconds
In the preceding code snippet, we declare the gps instance and two variables, which
wait for 30000 milliseconds (30 seconds) before the next readings are taken without
blocking the code.
Now, we will explore the loop() method. Here, we call the FetchGPS() method
every 30 minutes, which will be carried out by comparing currentMillis and
previousMillis without the use of delay():
Figure 6.23 – The LoRaWAN gateway successfully registered on The Things Network
In this section, we explored how to set up the The Things Indoor Gateway step by step.
In the next section, we will create a dashboard for our Thing on mobile and web to
track our assets.
What next?
We still have a lot of options available to explore, but now it’s your turn to use
different sensors and development boards to do some more experiments and learn from
them. In this chapter, we only used one GPS module, which gave us only four
parameters, but there are a lot of GPS modules on the market that provide a wide
variety of functionalities, such as working under a roof and accuracy features.
While monitoring the location of assets, some other parameters are very important to
monitor in different industries, such as temperature and humidity, which are very
important in food and medical products. CO2 and liquefied petroleum gas (LPG)
gases are very important to monitor during fuel transportation. Try using different
sensors with a GPS module to set up different tracking prototypes for different
industries.
Summary
In this chapter, we explored how to develop an asset-tracking system using LoRaWAN
and a GPS module. We set up the Thing, which included cloud variable creation,
device association, the The Things Indoor Gateway, and coding a development board.
Then, we created a dashboard to visualize the Thing readings with different types of
widgets to display current readings. The most important widget of the chapter is the
map widget, which is very interesting and important for plotting the current location of
the device.
GPS tracking is a very important topic that helps us to develop a device for our assets,
assisting us in asset tracking and monitoring. We can use LoRaWAN for a specific
region, as it has a longer range, but that range only operates in a specific area, unlike
other wireless technologies. This chapter demonstrated how we can display the
location of a device on a dashboard, giving you more confidence to build more asset-
tracking solutions.
In the next chapter, Enabling Communication between Different Devices, we will
explore how the Arduino IoT Cloud makes it easy to send data between devices. Using
this method, we will sync IoT nodes with each other for seamless operations.
Part 3: Exchanging Data between Nodes and
Cloud Applications
This third part of the book describes how to exchange data between IoT nodes
provisioned on the Arduino IoT Cloud and between the Arduino IoT Cloud and
external cloud applications.
These functionalities are required in many real cases to build a distributed and reliable
network, to implement some interdependent visualization and logic on the IoT
application, and to expand the functionalities of the Arduino IoT Cloud with external
tools.
This part has the following chapters:
Chapter 7, Enabling Communication between Different Devices
Chapter 8, Working with the Arduino IoT Cloud SDK and JavaScript
Chapter 9, Project #4 – Collecting Data from the Soil and Environment for Smart Farming
Chapter 10, Project #5 – Making Your Homes Smarter with a Voice Assistant
7
We will use the Arduino Web Editor for coding, which includes a large collection of
development boards and sensor libraries, and Arduino IoT Cloud for thing and
dashboard setup. The chapter code is available in the official book GitHub repository
by following this link: https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-
Developers.
In summary, Arduino IoT Cloud simplifies TTC in IoT projects, providing features
such as ease of integration, scalability, reduced latency, energy efficiency, offline
operation, customization, security, cost efficiency, and broad hardware compatibility.
These features make it a valuable platform for developing and managing IoT systems
that rely on direct communication between devices.
In this section, we have discussed the benefits of Arduino IoT Cloud TTC. In the next
section, we will explore what hardware components we require to do this chapter’s
exercise.
Project architecture
In this section, we will discuss how cloud variable synchronization works. As shown
in Figure 7.1, we have taken the project from Chapter 4. In that project, we set up a
device that monitors outdoor temperature, humidity, and air quality. Now, we want to
share the outdoor temperature with our indoor device, which is the MKR Wi-Fi 1010.
To make things easier, we just used LEDs with MKR Wi-Fi 1010, which is shown in
Figure 7.2. Our indoor device will turn on the red LED if the temperature exceeds the
specified threshold and turn on the green LED if it comes down below a specified
threshold. You can also use relays instead of LEDs to control the heating and cooling
system of your room.
We already have one complete thing in Arduino IoT Cloud that is working, but now
we need to create another thing for MKR Wi-Fi 1010 named Indoor MKR Wi-Fi
1010 with a bunch of cloud variables. We will then sync the temperature cloud
variable of the Indoor MKR Wi-Fi 1010 thing with the Sense the Environment thing,
which was created in Chapter 4.
In the preceding sections, we discussed the module and development board in detail.
Now, it’s time to begin the exercise. In hardware development, before we start working
with sensors and development boards, we need to develop design concepts to get a
better understanding of how things will connect. There is a lot of software available
for designing and developing design concepts for an electronics project, but in this
case, we will use Fritzing.
In the following subsection, we will talk about the schematics of a project while
explaining how to connect pins with a development board.
Setting up a Thing
After setting up the hardware, it’s time to set up a thing in Arduino IoT Cloud. For this
project, we need three cloud variables. Later on, we will associate MKR Wi-Fi 1010
with our thing. Next, we will perform the Wi-Fi network configuration. Figure 7.3
shows a complete overview of the Thing:
We have discussed the process of setting up a thing, and all these steps will be
explained in detail in the proceeding subsections. We will start with the Cloud
variables subsection, where we will create cloud variables for our thing as well as
synchronize them.
Cloud variables
The following table describes all the properties of the cloud variables that we need to
configure. For this project, we need three cloud variables, as listed in Table 7.1. Next,
make sure each variable matches the Declaration in the table; otherwise, you need to
modify the example code according to your naming.
When we created the cloud variables, we made the permission read-only for all
variables except Temperature because we need this cloud variable to sync with the
Temperature cloud variable of the Sense the Environment thing in Chapter 4. That’s
why this variable’s permissions are set to Read & Write. Update Policy is set to On
change for all variables.
Associating a device
After creating the variables, it’s time to add the device and associate it with the Thing:
1. Before adding the device, connect the development board to the computer and open the
Arduino Create Agent application. Figure 7.7 shows a popup where we have two options:
either select the existing device for association or set up the new device if it is not available in
the list:
Figure 7.7 – Associate device – select device
In our case, we already have different devices in the portal, but we want to add a new
MKR Wi-Fi 1010. Just click on SET UP NEW DEVICE to configure a new device in
the account.
2. Next, you will see the three options in the popup. The first option is Arduino board and the
second option is Third party device. The third option is Any Device, which is for non-
compatible devices. It means you can use any type of Arduino device, as well as third-party
devices with Arduino IoT Cloud, which supports Python, MicroPython, and JavaScript.
In this section, we associated the MKR Wi-Fi 1010 device with our thing, and in the
upcoming sections, we will talk about the network and code.
Network
After attaching the device to the Thing, we can see that the device is offline. To bring
it online, we need to provide Wi-Fi details. The following screenshot shows the
network configuration popup, which only consists of two fields:
Coding
This chapter’s code is available in the official GitHub repository for the book.
Download Indoor_Device_MKR_Wi-Fi_1010_sep07a.zip and import it into your
Arduino Web Editor.
You can download the code and put it into your thing by navigating to the Sketch tab.
Here, I will explain the main workflow. First, we have defined two constants for the
red and green LED pins called RLED and GLED in the following snippet and assigned
them pin numbers 6 and 7, respectively:
#define RLED 6
#define GLED 7
Then, we initialize all the required pins and methods in the setup() method.
Specifically, we are changing the modes of the pins to output by using the pinMode()
method:
void setup() {
pinMode(RLED, OUTPUT);
pinMode(GLED, OUTPUT);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor
without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
The next important method is onTemperatureChange(). Whenever the value of the
Temperature cloud variable changes on the Sense the Environment thing, it will be
automatically synced with the Temperature cloud variable of the Indoor Device
MKR Wi-Fi 1010 thing. Then, when the value changes, this method will be called:
void onTemperatureChange() {
// Add your code here to act upon Temperature change
if(temperature>30)
{
//if Temperature is more then 30 then turn on the Red LED
and turn off Green LED
redLed=true;
greenLed=false;
}else{
//If Temperature is 30 or less then turn on Green LED and
turn off Red LED
redLed=false;
greenLed=true;
}
digitalWrite(RLED,redLed);
digitalWrite(GLED,greenLed);
}
In the preceding code snippet, we have defined the manual threshold for
temperature. If the temperature value is greater than 30 degrees Celsius, then
assign redLed the true value and greenLed the false value; otherwise, assign
redLed with false and greenLed with true. At the end of the method, we are
controlling the LEDs according to the redLed and greenLed values. Here, you can
use relays instead of LEDs to control the heating and cooling system of your indoor
environment.
Upload the code to the device and you will see that either the red or green LED will be
turned on, depending on the temperature. After successfully uploading data to the
cloud, it’s time to set up a beautiful dashboard for web and mobile for the users. This
time, we will create a dashboard that will show the values of two things’ cloud
variables.
IMPORTANT NOTE
If you used different naming in the variable declaration, then update the code according to
your naming scheme. But it’s better if you first follow all the steps according to the book
and later change the cloud variable names and modify your code.
Never try to use the delay() method, which will create a block for the
ArduinoCloud.update() method. Also, don’t put the code in an end-of-loop method
as it will create a delay in the pulse sensor readings.
In this section, we have explored the code, and we are using the Temperature cloud
variable, which is synced with the Temperature cloud variable in Chapter 4, and we
are turning on and off the LEDs according to temperature value. In the next section,
we will explore how to display the cloud variables of multiple things on a single
dashboard.
When considering Arduino IoT Cloud for TTC in your IoT project, it’s essential to
weigh these drawbacks against the platform’s benefits and assess whether it aligns
with your specific project requirements and constraints. Additionally, exploring
alternative IoT platforms and communication solutions may be necessary to ensure the
best fit for your needs.
In this section, we have discussed in detail the limitations of Arduino IoT Cloud TTC.
In the next section, we will explore how you can use TTC for different types of cloud
variables.
What next?
We still have a lot of options available to explore, but now it’s your turn to use
different sensors and development boards to do some more experiments and learn from
them. In this chapter, we have only used one Temperature cloud variable synced
between two things, but you can try using this feature to sync multiple cloud variables
with multiple things. Next, create a dashboard for multiple things to visualize all the
values in one place. We configured simple LEDs to turn on and off according to the
temperature, but you can also use relays to control the heating/cooling system of your
indoor home/office and warehouse environment, or you can create an alarm in case of
a temperature increase using this TTC feature.
Summary
In this chapter, we explored D2D communication and the benefits of Arduino IoT
Cloud for thing-to-thing communication. We discussed how to develop a solution for
thing-to-thing communication. We also explored how easy it is to sync the cloud
variable with other things just using a GUI. We set up a dashboard, where we linked
the widget controls with multiple thing cloud variables. Finally, we discussed the
limits of Arduino IoT Cloud thing-to-thing communication in detail.
In the next chapter, we are going to explore how to use the Arduino IoT Cloud SDK.
This chapter is for developers who are eager to learn how to use Arduino IoT Cloud
programmatically and develop custom solutions using Arduino IoT Cloud or integrate
Arduino IoT Cloud with third-party platforms.
8
Technical requirements
There are no specific hardware requirements for this chapter as we are focusing on the
SDK and will work through different coding exercises to perform different operations
on the Arduino IoT Cloud platform using the Node.js SDK. To follow along with the
coding and testing exercises, the following software is required:
Node.js
The Node.js Arduino IoT Cloud module installed
The VSCode editor
Postman
An Arduino IoT Cloud account
Postman will be used for cURL testing and authentication, which will help other
developers when doing request and response testing. For SDK coding, we will use
Node.js and the VSCode editor. The code for this chapter is available from the book’s
official GitHub repository at https://github.com/PacktPublishing/Arduino-IoT-Cloud-
for-Developers.
Open the integrated terminal in VSCode and type the following command; Node will
execute the main.js code and provide a response in the console:
node main.js
You will receive the following response in the console if everything works fine:
Creating a device
Firstly, we will start with device creation. The documentation on device creation can
be found at https://www.arduino.cc/reference/en/iot/api/#api-DevicesV2-
devicesV2Create. Open create-device.js under the device folder in VSCode.
There are two methods in the code: one is getToken(), which is the same method as
in all our coding exercises and helps us to fetch the authentication token for requests.
The second method is CreateDevice(), which is responsible for device creation.
Consulting the documentation, we can see we need to initiate the api variable with the
AiotApi.DevicesV2Api() object, which is related to devices:
var DeviceProperties = {
'name':'Sense Home XIAO Series',
'connection_type':'wifi',
'fqbn':'esp32:esp32:XIAO_ESP32C3',
'type':'login_and_secretkey_wifi'
};
var options = {
};
api.devicesV2Create(DeviceProperties,
options).then(function(data) {
console.log('Device Created successfully. Returned data: '
+ util.inspect(data));
}, function(error) {
console.error(error);
});
api.devicesV2Create is the method responsible for device creation and takes two
parameters as input. DeviceProperties covers things such as the device name, type,
and Fully Qualified Board Name (FQBN). Let’s start with name first – this could be
anything you fancy, but avoid using special characters. Next, we need to provide a
choice for connection_type, such as Wi-Fi, GSM, LoRa WAN, and so on. All
available types are provided by the documentation. For fqbn, we need to provide the
details of the development board. Taking the XIAO ESP32C3 board as an example, it
belongs to the ESP32 family, so its FQBN would be esp32:esp32:XIAO_ESP32C3.
options are optional, so I left it blank, but you can provide the X-Organization
value according to your requirements. Both arrays are passed to the
api.devicesV2Create method, which will return the response. The util.inspect
method is used to display the JSON response on the console with proper formatting.
Type the following command to execute the create-device.js program:
node create-device.js
After successful execution of the script, it will print a response like the following:
Updating a device
In this section, we are going to explore how we can update a device using the device
ID. Let’s suppose we mistakenly added a device with the wrong FQBN and name. We
will update both properties using the device ID. The documentation on updating
devices is available at https://www.arduino.cc/reference/en/iot/api/#api-DevicesV2-
devicesV2Update. Open the update-device.js file under the device folder in
VSCode:
The preceding code is almost the same as the create-device code. Here we have
one extra variable, DeviceID, with which we will update the specific device. The rest
of the code has the same device properties and options as previously. Now, fill in the
correct fqbn and name values in the DeviceProperties variable. Lastly, we call the
api.devicesV2Update() method. Execute the following command in the Terminal:
node update-device.js
After successful execution of the script, it will print a response like the following:
Deleting a device
In this section, we are going to explore how we can delete a device using the device
ID. The documentation for deleting devices is available at
https://www.arduino.cc/reference/en/iot/api/#api-DevicesV2-devicesV2Delete.
Open the delete-device.js file under the device folder in VSCode:
node delete-device.js
After successful execution of the script, it will print a response to the console reporting
that the device has been deleted successfully.
Listing devices
In this section, we will list all the devices. Note that there is a difference between
listing devices and showing devices: listing devices means displaying all the devices
with their properties, while showing a device only returns a specific device’s properties
based on the device ID.
The documentation on listing devices is available at
https://www.arduino.cc/reference/en/iot/api/#api-DevicesV2-devicesV2List. Open the
list-device.js file under the device folder in VSCode. The following code
snippet is taken from the ListDevice() method from the list-device.js file:
node list-device.js
After successful execution of the script, it will print a response in JSON format with
the device properties, which will clog up the Terminal console with extensive output.
I modified the code to only display the device ID and device name on the console:
Device ID:04d8025a-4270-4d7e-aa04-45db87a594f5
Device Name:SmartAgriESP32-Sargodha
Device ID:5aae7e1f-940b-4426-80ac-1c953839cdb2
Device Name:MKR-GSM-1400
Device ID:fae0951d-3169-4d6a-a8e5-739c347eafc1
Device Name:MKR1500
Device ID:ca711f68-6de9-497a-ac45-780219ad2bb8
Device Name:Wemos d1 Mini by API Update
Device ID:64990519-1833-4bba-b035-978fcaa33466
Device Name:MKR1010-Device
Device ID:62e8600b-2733-4f24-9654-1fac549af27f
Device Name:XIAO-ESP32C3-Pulse-Sensor
Device ID:e88b84a7-7ad7-4c2b-b79c-ab426e47dc67
Device Name:Sense Home WeMos D1 Mini Series
Device ID:b9f3ff20-ebf1-4260-ad16-f434466458ac
Device Name:ArduinoNanoRP2040
Device ID:047d8316-dcdb-4bf5-af30-4319bb5a5eb0
Device Name:Delly
In the preceding code, we are displaying two parameters on the console, but you can
choose whichever and however many you want by specifying their names in the for
loop. Using this, we can send the output in JSON format to a web/mobile client, which
will display the information either in a list box or in menus.
Showing a device
This is the second-to-last subsection of the Interacting with devices – hands-on with
the Node.js SDK section. Here we will fetch all the properties of a specific device by
providing the device ID. The documentation on showing devices is available at
https://www.arduino.cc/reference/en/iot/api/#api-DevicesV2-devicesV2Show.
Open the show-device.js file under the device folder in VSCode. The following
code snippet is taken from the ShowDevice() method from the show-device.js
file:
node show-device.js
After successful execution of the script, it will print the response in JSON format with
the device properties as well as the details of any cloud variables if any associated
variable is present:
ArduinoDevicev2 {
id: '62e8600b-2733-4f24-9654-1fac549af27f',
label: 'Login and secret key for wifi device',
name: 'XIAO-ESP32C3-Pulse-Sensor',
……………………………………..
thing: ArduinoThing {
id: '6b6cd076-5859-4a6d-9b4e-18879893c6cb',
name: 'Tracking and notifying Your Heart Rate',
……………………………………..
webhook_active: true,
webhook_uri:
'https://hooks.zapier.com/hooks/catch/14930971/324me7k/'
}
}
The preceding code is the edited response of the script regarding device properties,
which includes all the details of the given device such as last activity, the cloud
variables count, the Thing ID associated with the device, webhook details (if active),
sketch ID, and so on.
In this sub-section, we have explored how to get all the devices list from the Arduino
IoT Cloud using the Node.js SDK. Next, let’s explore how to get the list of cloud
variables/properties associated with the device.
Device properties/variables
Here, we will fetch all the cloud variable details for a specific device by providing the
device ID. The documentation on showing devices is available at
https://www.arduino.cc/reference/en/iot/api/#api-DevicesV2-devicesV2GetProperties.
To begin, open the properties-device.js file under the device folder in VSCode.
The following code snippet is taken from the ListPropDevice() method in the
properties-device.js file:
node properties-device.js
After successful execution of the script, it will print a response in JSON format
containing the cloud variable details associated with that particular device ID:
Properties: [
ArduinoProperty {
href: '/iot/v1/things/6b6cd076-5859-4a6d-9b4e-
18879893c6cb/properties/b357a513-ad2b-4e1f-a76b-6dac078e36d5',
id: 'b357a513-ad2b-4e1f-a76b-6dac078e36d5',
name: 'BPM',
permission: 'READ_ONLY',
thing_id: '6b6cd076-5859-4a6d-9b4e-18879893c6cb',
type: 'HEART_BEATS',
update_strategy: 'ON_CHANGE',
created_at: 2023-03-31T16:41:33.103Z,
persist: true,
tag: 1,
thing_name: 'Tracking and notifying Your Heart Rate',
update_parameter: 0,
updated_at: 2023-03-31T17:05:19.564Z,
variable_name: 'bPM'
}
]
The preceding response is the edited response of the script regarding the device cloud
variables, including variable_name, type, permission, thing_id,
update_strategy, and so on. We have now seen how to get the cloud variable
details, and in the next section we’ll move on to cover Things.
Creating a Thing
Firstly, we will start with Thing creation. The relevant documentation can be found at
https://www.arduino.cc/reference/en/iot/api/#api-ThingsV2-thingsV2Createe. Open the
create-thing.js file under the thing folder in VSCode.
There are two methods in this code: one is getToken(), which is the same method as
in all our coding exercises and helps us to fetch an authentication token for our
requests. The second method is CreateThing(), which is responsible for Thing
creation. Referring to the documentation, we can see that we need to initiate the api
variable with the AiotApi.ThingsV2Api() object, which relates to the Arduino IoT
Cloud Thing. This object is responsible for performing operations on the Thing:
api.thingsV2Create is the method responsible for Thing creation and takes two
parameters as input: name and opts. Firstly, we start with name, which can be
anything you like, but make sure to avoid special characters. For now, we provide just
the Thing name in the variable, but in the upcoming update section, we will
additionally pass the time zone and device ID parameters.
opts here is optional, hence I left it blank, but you can provide the X-Organization
value if required. Both variables are passed to the api.thingsV2Create method,
which will return the response. The util.inspect method is used to display the
JSON response on the console with proper formatting. Type the following command to
execute the create-device.js script:
node create-thing.js
Updating a Thing
In this section, we are going to explore how to update a Thing using the Thing ID.
Let’s suppose we mistakenly added the Thing without setting the proper time zone and
without device association. In this scenario, we have the option to update the Thing
with new properties. The documentation covering updating devices is available at
https://www.arduino.cc/reference/en/iot/api/#api-ThingsV2-thingsV2Update. Open the
update-thing.js file under the device folder in VSCode:
node update-thing.js
After successful execution of the script, it will print a response like the following:
node create-sketch-thing.js
After successful execution of the script, it will print the following response:
Deleting a Thing
In this section, we are going to explore how we can delete a Thing using the Thing ID.
The documentation covering Thing deletion is available at
https://www.arduino.cc/reference/en/iot/api/#api-ThingsV2-thingsV2Delete. Open the
delete-thing.js file under the thing folder in VSCode:
node delete-thing.js
After successful execution of the script, it will print a response on the console
indicating that the device was deleted successfully.
Listing Things
In this section, we will list all the Things. Note that there is a difference between
listing Things and showing a Thing: listing Things will display all the Things with
their properties, while showing a Thing only shows the specific Thing properties
related to a given Thing ID.
The relevant documentation on listing Things is available at
https://www.arduino.cc/reference/en/iot/api/#api-ThingsV2-thingsV2List. Open the
list-thing.js file under the thing folder in VSCode. The following code snippet
is taken from the ListThing() method:
node list-thing.js
After successful execution of the script, it will print the response in JSON format with
the Thing properties, which will fill the console with an extensive output. I modified
the code to only display the Thing ID and Thing name on the console:
As can be seen in the preceding output, I am only displaying two parameters on the
console but you can choose whichever parameters you would like to be displayed by
specifying their names in the for loop. This way we can send the output in JSON
format to a web/mobile client where the information will be displayed in either a list
box or in menus.
Showing a Thing
This is the last subsection of the Engaging with things – Node.js SDK implementation
guide section. Here we will fetch all the properties regarding a specific Thing by
providing the Thing ID. The documentation covering showing Things is available at
https://www.arduino.cc/reference/en/iot/api/#api-ThingsV2-thingsV2Show. Open the
show-thing.js file under the thing folder in VSCode. The following code snippet
is taken from the ShowThing() method:
node show-thing.js
After successful execution of the script, it will print the response in JSON format
containing the device properties as well as the details of cloud variables, if any
associated variable is present:
The preceding code snippet shows an edited section from the output response
regarding the Thing properties, which includes all the details of the Thing, the device
properties, cloud variables such as last value, webhook details (if active), the sketch
ID, and so on.
In this section, we explored how we can get the complete details of a specific Arduino
IoT Cloud Thing using the Thing ID in JSON format. Next, we will start playing with
cloud variables/properties.
node create-property.js
After successful execution of the script, it will print the following response:
Updating a property
In this section, we are going to explore how we can update a cloud variable using the
cloud variable ID. Suppose we mistakenly added a cloud variable with the wrong data
type and some other parameters – in the event of this scenario, we have the option to
update it. The documentation covering updating properties is available at
https://www.arduino.cc/reference/en/iot/api/#api-PropertiesV2-propertiesV2Update.
Open the update-property.js file under the property folder in VSCode:
node update-property.js
After successful execution of the script, it will print a response something like the
following:
Deleting a property
In this section, we are going to explore how to delete a property using the Thing ID
and property ID. The documentation covering deleting a property is available at
https://www.arduino.cc/reference/en/iot/api/#api-PropertiesV2-propertiesV2Delete.
Open the delete-property.js file under the property folder in VSCode:
node delete-property.js
After successful execution of the script, it will print a response on the console reading
that the property has been deleted successfully.
Listing properties
In this section, we will list all the properties for a given Thing using the Thing ID. As
previously outlined with devices and Things, there is a difference between listing
properties and showing a property. Listing properties means displaying all the cloud
variables of a Thing, while showing a property only shows the specific cloud variable
properties related to the given Thing ID and property ID.
The documentation on listing properties is available at
https://www.arduino.cc/reference/en/iot/api/#api-PropertiesV2-propertiesV2List. Open
the list-property.js file under the property folder in VSCode. The following
code snippet is taken from the ListProperty() method:
node list-property.js
After successful execution of the script, it will print the response in JSON format with
the cloud variable’s properties. I chose a Thing that only has a single cloud variable:
Returned data: [
ArduinoProperty {
href: '/iot/v1/things/6b6cd076-5859-4a6d-9b4e-
18879893c6cb/properties/b357a513-ad2b-4e1f-a76b-6dac078e36d5',
id: 'b357a513-ad2b-4e1f-a76b-6dac078e36d5',
name: 'BPM',
permission: 'READ_ONLY',
thing_id: '6b6cd076-5859-4a6d-9b4e-18879893c6cb',
type: 'HEART_BEATS',
update_strategy: 'ON_CHANGE',
created_at: 2023-03-31T16:41:33.103Z,
last_value: 50,
persist: true,
tag: 1,
thing_name: 'Tracking and notifying Your Heart Rate',
update_parameter: 0,
updated_at: 2023-03-31T17:05:19.564Z,
value_updated_at: 2023-04-01T16:43:12.293Z,
variable_name: 'bPM'
}
]
The preceding response contains all the values related to the cloud variable, such as
last value, updated time, and so on. If you want to fetch the last value of a cloud
variable then this method could be used in your application to do so.
Next, we have another API endpoint related to showing the properties of a single cloud
variable. The code is available in the property folder, and the execution of the code
along with checking out how it works is left to you as an exercise.
In this section, we discussed in depth how to get the complete details of a cloud
variable/property in JSON format using the Arduino IoT Cloud API, which provides
lot of data including last_value and value_update_at. In the next section, we will
start working with dashboards and learn how to perform operations on them using the
Node.js SDK.
Creating a dashboard
Let’s start first with dashboard creation. The relevant documentation can be found at
https://www.arduino.cc/reference/en/iot/api/#api-DashboardsV2-dashboardsV2Create.
Open the create-dashboard.js file under the dashboard folder in VSCode.
There are two methods in this code: one is getToken(), which is the same method as
in all our coding exercises to fetch the authentication token for our requests. The
second method is CreateDashboard(), which is responsible for dashboard creation.
Referring to the documentation, we can see we need to initiate the api variable with
the AiotApi.DashboardV2Api() object, which is used to perform operations on
dashboard objects:
node create-dashboard.js
After successful execution of the script, it will print a response like the following:
Updating a dashboard
In this section, we are going to explore how to update a dashboard using the dashboard
ID. There is an option to add widgets to a dashboard via an API but it will make the
code significantly more complex due to the JSON data involved. For this reason, we
will just update the dashboard name instead of adding widgets. The documentation for
updating properties is available at https://www.arduino.cc/reference/en/iot/api/#api-
DashboardsV2-dashboardsV2Update. Open the update-dashboard.js file under the
dashboard folder in VSCode:
node update-dashboard.js
After successful execution of the script, it will print a response like the following:
After our update, the response will return the new content, reflecting the updated data
for the name that we provided.
Deleting a dashboard
In this section, we are going to explore how to delete a dashboard using the dashboard
ID. The relevant documentation on deleting dashboards is available at
https://www.arduino.cc/reference/en/iot/api/#api-DashboardsV2-dashboardsV2Delete.
Open the delete-dashboard.js file under the dashboard folder in VSCode:
node delete-dashboard.js
After successful execution of the script, it will print the response on the console
indicating that the dashboard was deleted successfully.
Listing dashboards
In this section, we will list all the dashboards with complete details and widgets. The
difference between listing dashboards and showing a dashboard is that listing
dashboards will display all the dashboards available in the Arduino IoT Cloud, while
showing a dashboard only shows the specific dashboard properties and widgets related
to the given dashboard ID.
The documentation for listing dashboards is available at
https://www.arduino.cc/reference/en/iot/api/#api-DashboardsV2-dashboardsV2List.
Open list-dashboard.js under the dashboard folder in VSCode. The following
code snippet is taken from the ListDashboard() method:
node list-dashboard.js
After successful execution of the script, it will print the response in JSON format
containing the dashboard properties and widgets:
[
ArduinoDashboardv2 {
id: '36287c03-5034-4a64-b40a-102740c998c6',
name: 'SmartAgri-Sargodha',
updated_at: 2023-03-05T11:00:18.395Z,
created_by: ArduinoDashboardowner {
user_id: 'f067c1e9-3ff8-4b9f-a9b4-f8c5c1d0ceb4',
username: 'mafzalattari'
},
widgets: [
]
},
ArduinoDashboardv2 {
id: '28ea7839-7a81-460e-a871-368d45d82cee',
name: 'Tracking and notifying Your Heart Rate Dashboard',
updated_at: 2023-04-19T16:41:36.604Z,
created_by: ArduinoDashboardowner {
user_id: 'f067c1e9-3ff8-4b9f-a9b4-f8c5c1d0ceb4',
username: 'mafzalattari'
},
widgets: [ [ArduinoWidgetv2], [ArduinoWidgetv2] ]
},
]
The preceding response contains all the properties related to dashboards such as
widgets, creation date, update time, and so on. Next, we have another API endpoint
related to showing a dashboard, which is used to display all the information regarding
a single dashboard. The code is available in the dashboard folder; the execution of
the code and checking out how it works is left to you as an independent exercise.
In these sub-sections, we discussed how to work programmatically with dashboards,
including actions such as dashboard creation, updating, deletion, and showing the list
of dashboards via the Arduino IoT Cloud Node.js SDK. In the next section, we will
explore how we can use the Node.js SDK to fine-tune our cloud variables/properties.
node get-prop.js
After successful execution, you will get the response with the value.
node set-prop.js
After successful execution, you will get a response indicating that the value has been
updated successfully.
In the section, we discussed in detail how to get/set the value of a cloud variable
programmatically. This helps developers to fetch values and display them in their
custom dashboards, or set the values of cloud variables to control device operations.
Next, you have an assignment of an example project for practice, which will help you
to refine your skills and chapter study.
Assignment
After playing with SDK, it’s now time to do some more experiments so you can apply
your learning in new scenarios and solidify your learning. For this assignment, you
will create a script for Thing automation with the following properties:
1. Set up a method for WeMos D1 Mini device creation. This device belongs to the ESP8266
category.
2. Set up a Thing named Sense Environment and create a sketch for a Thing. Then,
associate the previously created device with the Thing.
3. Create three cloud variables/properties for temperature, humidity, and air quality and attach
these variables to the previously created Thing.
Create the required script in one file containing all the methods, where we just provide
the Thing name and it will automatically set up the device, Thing, and sketch, handle
device association with the Thing, and take care of variable creation. Successfully
completing this task will teach you to automate workflows and processes efficiently
and effectively.
Summary
In this chapter, we covered API endpoints, SDKs, and the types of SDK platforms
available to us on the Arduino IoT Cloud. We also learned how to test APIs with
Postman. Next, we explored the Node.js SDK by performing different types of
operations, particularly CRUD operations, on devices, Things, properties, and
dashboards. Finally, we saw how to get and set the value of a cloud variable.
This chapter was specially designed for backend developers seeking to use the
Arduino IoT Cloud as a foundation and wanting to develop a custom frontend for their
solution, which is possible when you know how to interact with the Arduino IoT
Cloud programmatically using the Node.js SDK. Likewise, the ability to create custom
services allows us to integrate with third party cloud services and applications.
The next chapter will be more interesting as we are going to dive into smart
agriculture, implementation a project where you will learn how to measure the soil
moisture, soil temperature, and outdoor temperature and humidity. We will design a
device that will allow us to monitor four different crops/plants. You could use this
project to monitor your home plants as well as helping your friends working in the
field of agriculture.
9
Technical requirements
The following hardware components are required to complete this chapter:
ESP32 development board
ADS1115 ADC module
DHT22 module
Soil moisture sensor x4
DS18B20 x4
PCB (link is available in the PCB design and the assembly of hardware components section)
2.54 mm three-pin connectors
Female headers
Jumper cables
For coding, we will use the Arduino Web Editor, which includes a large collection of
development board and sensor libraries, and we will use the Arduino IoT Cloud for Thing
and dashboard setup. To develop hardware and sensor designs, we need the Fritzing desktop
software.
The chapter code is available in the book’s official GitHub repository, or you can directly
download the code at https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-Developers.
Overall, IoT technology is transforming the way that agriculture is practiced. By using real-
time data and analytics, farmers can make better decisions and achieve better outcomes,
ultimately leading to a more sustainable food supply for the world.
In this section, we have discussed smart agriculture and different terms and techniques that
are common in smart agriculture. In the next section, we will discuss the hardware
components that we are going to use in this chapter’s project.
Feature DS18B20
ESP32 DHT22
GND GND
3.3V VCC
Table 9.3: ESP32 and DHT22 pinout table
Table 9.4 contains the pin configuration for DS18B20 temperature probes with ESP32. Here,
we are using four DS18B20 temperature probes, and in each column of sensors, we have
mentioned the ESP32 pin number that will connect with the DS18B20 data pin. GND and
VCC pins of ESP32 development board will be common to all sensors:
Data pin with ESP32 Data pin with ESP32 Data pin with ESP32 Data pin with ESP32
(D32) (D33) (D25) (D26)
ESP32 GND to GND ESP32 GND to GND ESP32 GND to GND ESP32 GND to GND
ESP32 3.3V to VCC ESP32 3.3V to VCC ESP32 3.3V to VCC ESP32 3.3V to VCC
Table 9.4: ESP32 and DS18B20 temperature probes pinout table
Table 9.5 illustrates ESP32 to ADS1115 pin configuration. The rest of the soil moisture
sensors will connect to the system via ADS1115 analog pins, which are explained in Table
9.6:
ESP32 ADS1115
D22 SCL
D21 SDA
3.3V VCC
GND GND
Soil moisture analog Soil moisture analog Soil moisture analog Soil moisture analog
pin to ADS1115 (A0) pin to ADS1115 (A1) pin to ADS1115 (A2) pin to ADS1115 (A3)
ESP32 GND to GND ESP32 GND to GND ESP32 GND to GND ESP32 GND to GND
ESP32 VCC to VCC ESP32 VCC to VCC ESP32 VCC to VCC ESP32 VCC to VCC
Table 9.6: ADS1115 and soil moisture sensors pinout table
The preceding design provides a full overview showing how you can connect the sensors to
the development board. According to the design, we have only one 5V and one GND from
the development board, which will be used across all the sensors. Soil moisture sensors are
analog sensors, so we connected all the sensors with ADS1115 module pins from the AO pin
to the A4 pin, as shown in Figure 9.5 and Table 9.6, while the DHT22 module and DS18B20
are digital sensors and are connected to the D12, D32, D33, D25, and D26 pins of ESP32, as
shown in Figure 9.5 and in Table 9.3 and Table 9.4, respectively. The ESP32 to ADS1115
pinout is shown in Table 9.5 as well as in Figure 9.5.
Figure 9.8: Smart agriculture system with all sensors and modules
The preceding figure shows all the components stacked on the PCB. We can see that soil
moisture sensors are extended with custom cabling with the help of connectors, while the
DS18B20 naked terminal is connected to female connectors, and the same for the DHT22
module. After hardware assembly, we need to calibrate the soil moisture and DS18B20
temperature before deploying the node into the field.
int AirValue[]={0,0,0,0};
int WaterValue[]={0,0,0,0};
The preceding code snippet contains two arrays: one for air values and one for sensor values
when they are dipped into the water. For soil sensor calibration, we need to get AirValue and
then WaterValue values only by one time. Upload the code to the development board and
make sure your soil moisture sensors are dry. Open the serial monitor and note down the
AirValue value for each sensor. After that, dip the sensors into a pot of water and note down
the WaterValue value of the sensors.
Let’s look at the AirValues of AIN0, AIN1, AIN2, and AIN3, as shown in Figure 9.10. AIN
is short for Analog Input and the proceeding 0, 1, 2, and 3 are the pin numbers of the
ADC1115 module where soil moisture sensors are connected:
Figure 9.10: Air values of soil moisture sensors
Now let’s look at the WaterValues after putting the soil moisture sensors in the water:
Figure 9.11: Water values of soil moisture sensors
Wait for some time and note down the values when they become stable. After fetching the
Air and Water values, put these values into the preceding arrays and upload the code again
to the development board. Verify the values of the soil moisture percentage levels by putting
the sensors into the water and then cleaning them. Here, you will get 100% when sensors are
deeply in water and 0% when they are dry.
After the soil moisture levels, it’s time to verify the DS18B20 temperature probe sensor
readings. Firstly, we need to install a library for the DS18B20 temperature sensor. Navigate to
Sketch | Include Library | Manage Libraries…, type Dallas Temperature by Miles
Burton, and install the latest version. After installation of the library, download the code
from the official GitHub book repository and open the code from the DS18B20-
Calibration folder:
Here, we have discussed the different steps that help us to set up our thing. In the proceeding
section, we will start looking into cloud variables.
Cloud variables
The following table explains all the properties of variables that we need to use during cloud
variable creation. An integer (int) is a very famous data type, but here you will observe two
new variable types regarding humidity and temperature, which take values in percentage and
Celsius, respectively. Also, ensure you have the same variable declaration as per the table;
otherwise, you will need to modify the example code according to your naming.
We have set the permission of all cloud variables to Read Only, but we also have the
Read/Write option. In this project, we only want to receive data from the device instead of
sending data from dashboard, which is why Read Only mode is used, to avoid issues with
data consistency. Update Policy is set to On change, as the device will send the data after
five minutes, so this option is more appropriate compared to Periodically update:
Network configuration
After associating the device with the Thing, it is time to configure the Wi-Fi settings for
device communication, as shown in Figure 9.14, in the area marked 3. Under Network, you
will find the option to fill in the form with the Wi-Fi name and password. In the last field, you
will find a new field for the secret key. Paste the secret key that we received from the system
during device creation.
Figure 9.16: Network configuration for the Thing
After network configuration, we are done with our main task; now, the coding task remains,
and in the next section, we will go through it.
Coding
The project code is available in the book’s official GitHub repository in a ZIP file named
AgriStack_mar05a. Download it and import it to your Arduino Web Editor.
You can download the code and put it into your thing by navigating to the Sketch tab. I am
not going to discuss that code as you will get the idea after reading it. But here, I will explain
the main workflow: we initialize all the things in the setup method and use the timer library
to delay calling; remember, never try to use the delay method as it will block the
ArduinoCloud.update() method. Then, a method called SmartAgri() is called every five
minutes. The following is the complete SmartAgri() method. After this, we will explore
what operations are carried out by this method:
In this project, we have divided all the operations into different methods for easiness. So,
firstly, we are calling FetchSoilMoisture(), which is responsible for fetching soil
moisture readings from sensors and storing them in an array. Before storing the data in an
array, it maps the value for the percentage. Next, we have the FetchTemperature()
method, which is responsible for fetching the temperatures from all DS18B20 sensors and
saving them into the soil temperature array for further usage. Finally, we call
FetchDHTTempHum() to fetch the outdoor temperature and humidity values from the DHT22
module, which will be stored in two variables. Now, we will explore how we get the values
from the soil moisture sensors in the following method:
What next?
We still have a lot of options available to explore, but now it’s your turn to use different
sensors and development boards to do some more experiments and learn from them. In this
chapter, we used 10 sensors but only 3 different types, that is, moisture, temperature, and
outdoor temperature and humidity. However, on the market, there are a lot of sensors that
provide a wide variety of functionalities for soil, such as NPK (which stands for nitrogen,
phosphorus, and potassium), EC (which stands for electrical conductivity), and pH
sensors and different gas sensors for outdoor measurement.
Try the following sensors to enhance your practical knowledge and compare them with other
sensors in terms of features, ranges, and cost:
NPK sensor
Soil EC sensor
Soil pH sensor
MQ series sensors, which are designed to sense specific gases, including MQ-2, MQ-3, MQ-4, MQ-5,
MQ-7, MQ-8, and MQ-9, to find the correlation of gases and their effects on soil and crops
Seeed Studio SCD30 (temperature, humidity, and CO2) for outdoor monitoring
Summary
In this chapter, we explored how to develop a smart agriculture monitoring system using
DHT22, capacitive soil moisture sensors, a DS18B20 probe for soil temperature, and an
ESP32 development board along with the ADS1115 ADC module. We calibrated soil
moisture and temperature sensors in the lab before using them in the field. We also set up a
thing, which included creating cloud variables, device association, network configuration,
and coding of the development board. Then, we created a dashboard to visualize the Thing’s
sensor readings with different types of widgets to display current readings as well as
historical data with the help of graphs.
This project will help you and give you the confidence to collaborate with agriculture
researchers and soil scientists to work on a more advanced level. It will help you to add IoT
systems to real fields and tunnel farms, as well as help you in home gardening.
In the next chapter, we will work on a smart home project where we will develop a smart
RGB LED light that will be connected to the Amazon Alexa Voice assistant and help you to
understand and develop smart home solutions.
10
Technical requirements
The following hardware components are required to complete this chapter’s exercise:
Seeed Studio XIAO ESP32C3
USB type-C cable for XIAO ESP32C3
WS2812 RGB LED ring
Male headers, female headers, and a veroboard
Jumper cables
Soldering iron
Amazon Echo Dot and the Amazon Alexa mobile app
For coding, we will use the Arduino Web Editor, which includes a large collection of
development boards and sensor libraries, and the Arduino IoT Cloud for the Thing and
dashboard setup. To develop hardware and sensor designs, we need the Fritzing
desktop software and the Arduino IDE for testing the WS2812 ring.
Here, we will use the Amazon Echo Dot as a voice assistant for voice commands to
control the smart bulb. If you don’t have an Echo Dot, then you can use the Amazon
Alexa app for Android/iOS. The chapter’s code is available in the official GitHub
repository for the book by following this link:
https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-Developers.
It’s important to note that while IoT technology brings numerous benefits to smart
homes, it also introduces potential security and privacy risks. Homeowners should take
measures to secure their IoT devices, such as using strong passwords, keeping
firmware up to date, and ensuring proper network security configurations.
Here, we have discussed in detail how IoT is reshaping the lives of human beings in
homes and offices. Next, we are going to talk about the hardware and components that
we require to carry on with this chapter’s project.
A3 Data Input
5V Power 5V DC
#include <Adafruit_NeoPixel.h>
#define LED_PIN D3
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 16
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB +
NEO_KHZ800);
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object
(REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max =
255)
}
Change the LED_PIN constant to D3 or D5. Next, assign the number of pixels to the
LED_COUNT constant. Right now, I have 16 pixels in the WS2812 – that’s why I am
inserting 16. After making modifications, upload the code to the board. Later, you will
see the color white on the LED and a moving animation in a circular form. In the
setup() method, we initialized NeoPixel strip and set the brightness to 50%:
Cloud variables
The following table provides all the properties of the variables that we need to use
during cloud variable creation. For the WS2812, we can use the integer and bool data
types, which creates a lot of mess, but thanks to the Arduino IoT Cloud’s extended
group of variables, we have the Dimmed light, Color, and Colored Light type
variables. Next, make sure the same variables are declared as shown in Table 10.2,
otherwise, you’ll need to modify the example code according to your naming.
Here, I made the permission read and write, as this time we will send commands from
the cloud dashboard or voice assistant, so it’s mandatory to give cloud variables
permission to read and write.
Associating a device
After variable creation, it’s time to add a device associated with the Thing. Before
adding the device, connect the development board to the computer and open the
Arduino Create Agent application. The following figure shows how to select the
ESP32 and then the XIAO_ESP32C3 development board in the popup.
Network
After associating the device with the Thing, it is time to configure the Wi-Fi settings
for device communication. The following figure shows the network configuration
popup with the Wi-Fi Name and Password fields.
Figure 10.10 – Network configuration for the Thing
You will find a new field – Secret Key. Paste the secret key that we received from the
system during device creation.
Coding
The chapter’s code is available at the official GitHub repository for the book.
Download the Voice_Controlled_Smart_Lamp_may13a code from the repository
and import it to the Arduino Web Editor.
You can download the code and put it into your Thing by navigating to the Sketch tab.
I am not going to discuss that code as you will get the idea after reading it. But here, I
will explain the main workflow that initializes all the things in the setup. Remember,
never try to use the delay() method – it will block the ArduinoCloud.update()
method. But before moving forward, at the start of the code, we need to change the
Pin# of the LED_PIN constant to 5 and assign a value to LED_COUNT according to the
number of pixels in the ring/strip. Here, I am assigning the value 16 as I am using a
16-pixel ring:
#define LED_PIN 5
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 16
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB +
NEO_KHZ800);
//Sync Variables
bool swi;
float bright;
float sat;
float hue;
If we review the preceding code for the constant, then we will see there is one
NeoPixel strip object and four global variables for the switch (swi), brightness
(bright), saturation (sat), and hue that will be used later to sync the values from one
widget control to another widget control to enable the synchronization between
widgets.
After filling the preceding constants with appropriate values, it’s time to explore some
other methods. If we talk about the setup, then there are only a few lines that initiate
the NeoPixel strip object as well as the Arduino IoT Cloud and some other
operations. In this project, our loop() method will include one line regarding an
Arduino Cloud update and nothing else. Actually, in this project, code will be executed
where any change happens on the widget side.
In the project, we have four more methods. Three are event-oriented and one is a
common helper method that will be used by three event-oriented methods to perform
operations on WS2812. Here, the onLightBrightnessChange(),
onRGBLightColorChange(), and onTableLightChange() methods are event-
oriented and the ControlTheWS2812() method is a common helper method. Next,
we are going to explore all the methods step by step:
void onLightBrightnessChange() {
// Add your code here to act upon LightBrightness change
swi=lightBrightness.getSwitch();
bright=lightBrightness.getBrightness();
//Sync the values to tableLight Cloud Variable
tableLight.setSwitch(swi);
tableLight.setBrightness(bright);
//Call the method for operations on WS2812
ControlTheWS2812();
}
void onRGBLightColorChange() {
// Add your code here to act upon RGBLightColor change
hue=rGBLightColor.getValue().hue;
sat=rGBLightColor.getValue().sat;
bright=rGBLightColor.getValue().bri;
//Sync the values with LightBrightness & tableLight widget
tableLight.setBrightness(bright);
tableLight.setHue(hue);
tableLight.setSaturation(sat);
lightBrightness.setBrightness(bright);
//Call the method for operations on WS2812
ControlTheWS2812();
}
The onRGBLightColorChange() method is the second method that will be called
when there is any change in the color widget control. This method fetches hue,
saturation, and brightness values from the Color type cloud variable and later assigns
these values to other cloud variables as well as global variables. The last calling
method, ControlTheWS2812(), performs the operation on the WS2812 ring
according to global variable values:
void onTableLightChange() {
// Add your code here to act upon TableLight change
swi=tableLight.getSwitch();
bright=tableLight.getBrightness();
hue=tableLight.getHue();
sat=tableLight.getSaturation();
//Sync the values with LightBrightness & RGBLightColor widget
lightBrightness.setSwitch(swi);
lightBrightness.setBrightness(bright);
rGBLightColor= Color(hue,sat,bright);
//Call the method for operations on WS2812
ControlTheWS2812();
}
The onTableLightChange() method is associated with the Colored Light control
widget and it will be called when there is any change to the switch, brightness, or
color. This method will fetch four values from the tablelight cloud variable and
assign these values to global variables as well to two other cloud variables for
synchronization. The last calling method, ControlTheWS2812(), will perform the
operation on the WS2812 ring according to global variable values:
void ControlTheWS2812(){
// declare a variable of the Color data type and define it
using the HSB values of the color variable
Color currentColor=Color(hue,sat, bright);
byte RValue;
byte GValue;
byte BValue;
currentColor.getRGB(RValue, GValue, BValue); // the variables
will contain the RGB values after the function returns
if(swi==true){
strip.setBrightness(bright);
for(int i=0; i<LED_COUNT+1; i++){
strip.setPixelColor(i, strip.Color(RValue, GValue, BValue));
// Set pixel's color (in RAM)
strip.show();
}
}else{
for(int i=0; i<LED_COUNT+1; i++){
strip.setBrightness(0);
strip.setPixelColor(i, strip.Color(0, 0, 0)); // Set
pixel's color (in RAM)
strip.show();
}
}
}
Finally, we have our last, common helper method, ControlTheWS2812(). This
method will first generate RGB color from hue, saturation, and brightness. Then it will
check the switch value – if it is true, then the condition will assign the brightness and
color to the WS2812 ring and turn on every pixel of the ring with the help of the for
loop. Otherwise, it will set the brightness to 0 and turn off all the pixels of the
WS2812.
IMPORTANT NOTE
If you used different naming in the variable declaration, then update the code according to
your naming scheme. But it’s better if you first follow all the steps according to the book
and later change the cloud variable names and modify your code respectively.
The Arduino IoT Cloud only updates the values on the dashboard whenever a variable
value is changed. For example, if the temperature is 30 and after 5 minutes it’s the same,
then the Arduino IoT Cloud will not record the value. So, don’t get confused if values are
not changed on the widget controls. Another benefit of this feature is you will not get
duplicated data when you are exporting the content.
In this section, we set up the Thing, associated the XIAO ESP32C3 with the Thing,
and set up cloud variables of different types to control LED operations. We also
discussed the code for the device in detail, step by step, according to different
methods. Now, in the next section, we will set up the dashboard.
According to the preceding list, you can create a thermostat for a room, which will
help you to change the room or kitchen temperature according to outdoor and indoor
thermostat temperature, you can control your heating and cooling system. To turn
on/off any device, we have four different types of cloud variables, which have the
same data type Boolean but different names, including light, smart plug, smart switch,
and motion detection. These four variables could be used to control any relay/magnetic
contactors to turn home appliances on/off, such as cooling/heating systems. We have
already discussed Dimmed light and Colored Light in previous sections.
In this section, we have set up the Amazon Alexa with Arduino Cloud skill and tried
different voice commands related to turning lights on and off, as well as how to change
the color and brightness of the WS2812 RGB LED ring.
What next?
We still have lots of options available to explore, but now your assignment is to use
different relays, sensors, and development boards to do some more experiments and
learn from them. In the current chapter, we have only used one WS2812 module for
light control, but you can use temperature sensors, relays, and motion sensors to
automate your devices in your home, such as automating room switches to control
fans, exhaust fans, lights, and air conditioning systems according to room temperature.
IMPORTANT NOTE
Be careful when playing with high-voltage power cables when patching the cables to
relays.
Summary
In this chapter, we have explored how to develop a low-cost, multi-color smart table
lamp for our room using the XIAO ESP32C3 and WS2812. We have set up the Thing,
which included cloud variable creation, device association, network configuration, and
coding of the development board. Later, we created a dashboard using different
widgets to control the WS2812 RGB ring. Finally, we used the Amazon Alexa voice
assistant to turn our table lamp on/off and control its color and brightness with voice
commands.
This chapter will give you the confidence to build more interesting stuff to make your
home and office smarter. In the next chapter, we will talk about Cloud Scheduler and
over-the-air update’ features. Both features are interesting and specially designed to
carry out operations on IoT nodes.
Part 4: Learning Advanced Features of the
Arduino IoT Cloud and Looking Ahead
In Part 4, the reader is guided through the advanced features of the Arduino IoT Cloud
platform, how to use them to develop professional applications, and the tools for
maintaining solutions during their life cycle. The book ends with some suggestions for
further learning, experimenting, and sourcing information.
This part has the following chapters:
Chapter 11, Implementing the Arduino IoT Cloud Scheduler and Over-the-Air Features
Chapter 12, Project #6 – Tracking and Notifying about Your Heart Rate
Chapter 13, Scripting the Arduino IoT Cloud with Cloud CLI
Chapter 14, Moving Ahead in the Arduino IoT Cloud
11
By harnessing the power of the Arduino IoT Cloud Scheduler, users can automate
tasks, remotely control devices, and establish time-based or event-driven workflows
for their Arduino-based IoT projects. This feature simplifies the management and
coordination of actions across devices, elevating the functionality and efficiency of
IoT applications.
In this section, we discussed how the Arduino IoT Cloud Scheduler provides a benefit
to schedule our tasks. In the next section, we will implement a Scheduler using MKR
Wi-Fi 1010.
Cloud variables
The following table explains all the properties of the variables that we need to use
during cloud variable creation. For the Scheduler, we will use a custom data type,
Schedule, which we have thanks to Arduino IoT Cloud’s extended group of variables.
Then, make sure you have the same declaration variable as per the table; otherwise,
you will need to modify the example code according to your naming.
S# Variable Name Variable Declaration Permission Update
Type Policy
Associating a device
After creating the variable, it’s time to add a device and associate it with the Thing:
1. Before adding the device, connect the development board to the computer and open the
Arduino Create Agent application.
2. After assigning a name to the Thing, we need to attach the device to it. When you click on the
Select Device button, you will see a popup that shows you the available devices and an option
to add a new device. In our case, we don’t have a device in the portal, so we can just click on
SET UP NEW DEVICE to configure a new device in the account.
Figure 11.3 – The associated device
3. Then, you will see two options in the popup. The first option is Set up an Arduino device, and
the second option is Set up a 3rd Party device. Here, you will see a note under both options
that says Compatible devices. This means you cannot use all types of Arduino devices and
third-party devices with the Arduino IoT Cloud.
Figure 11.4 – Choosing the device
Select one option from the popup according to the available device. For this example,
we will click on Set up an Arduino device, as in this chapter, we are using an MKR
Wi-Fi 1010 board. Before adding the device, make sure the Arduino Create Agent is
running on your machine.
IMPORTANT NOTE
Here is the link where you can find the Arduino IoT Cloud-compatible boards: https://store-
usa.arduino.cc/pages/cloud-compatible-boards. For third-party devices, we have three
options, which are ESP8266, ESP32, and LoRaWAN devices. For other devices, we have
API access, which was discussed in the second part of Chapter 2.
4. Now, you will see the Setup Device popup, which will start searching for your device. Make
sure the device is properly connected to the machine.
Figure 11.5 – Setup Device
The wizard will find and list all the connected boards with their name and port details.
Click on the CONFIGURE button to move forward. If the wizard didn’t show the
device after searching, try to plug it into a different port, and click on the refresh link
located at the bottom.
5. In the next configuration wizard, provide the device name. Spaces and special characters are
not allowed in the device name. Then, click on the NEXT button.
In this section, we associated the MKR Wi-Fi 1010 development board with our
Thing. In the next section, we will configure the Wi-Fi network configuration for the
MKR Wi-Fi 1010.
Network configuration
After the attachment of the device with the Thing, we can see that the device is offline.
To get it online, we need to provide the Wi-Fi details.
Coding
The code for this chapter is available in the book’s official GitHub repository.
Download the Cloud_Scheduler_may22a code from the repository, and import it to
your Arduino Web Editor.
You can download the code and put it into your Thing by navigating to the Sketch tab.
The whole project code is very small and simple; that’s why I will go through all the
code here and discuss it in detail. Remember, never try to use the delay() method, as
it will block the ArduinoCloud.update() method:
#define LED1 8
#define LED2 7
#define LED3 6
Here, we have very simple code. Firstly, we will define the pins’ LED1, LED2, and
LED3 constants, which will be initialized in the setup() method as output, using the
pinMode() method:
void setup() {
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor
without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
Then, we have all the code regarding Schedulers in the loop() method, which will
perform an operation when a scheduler/timer is in an active state. In the following
code, we have a separate if-else statement for each cloudScheduler cloud
variable; here, we check whether cloudScheduler is active and then turn on the
LED; otherwise, we turn off the LED. We have cloudScheduler1,
cloudScheduler2, and cloudScheduler3, plus three if-else statements to check
their values:
void loop() {
ArduinoCloud.update();
// Your code here
//Cloud Scheduler 1 Code
if(cloudScheduler1.isActive()){
digitalWrite(LED1,HIGH);
}else{
digitalWrite(LED1,LOW);
}
//Cloud Scheduler 2 Code
if(cloudScheduler2.isActive()){
digitalWrite(LED2,HIGH);
}else{
digitalWrite(LED2,LOW);
}
//Cloud Scheduler 3 Code
if(cloudScheduler3.isActive()){
digitalWrite(LED3,HIGH);
}else{
digitalWrite(LED3,LOW);
}
}
The Scheduler widget is very complex in configuration with lots of options, but its
code is very simple and straightforward. You just need to verify whether the Scheduler
state is true or false, and if it’s true, then proceed with the task; otherwise, stop the
task. So, in the loop() method, we have three if-else statements, which check
different cloud Schedulers’/timers’ states. If a specific Scheduler is active, then a
specific LED will be turned on; otherwise, it will be turned off.
I attached the LED in Pin #8 to cloudScheduler1, the LED in Pin #7 to
cloudScheduler2, and the LED in Pin #6 to cloudScheduler3. Now, set the first
widget’s time to 5 seconds for every minute, the second widget to 10 seconds for every
minute, and 15 seconds for every minute for the third widget. All the LEDs will turn
on at the same time, but the first LED will be on for 5 seconds, the second LED will be
on for 10 seconds, and the third will turn off after 15 seconds. In this example project,
we have used three different Schedulers to demonstrate how we can use multiple
Schedulers/timers to automate our tasks on a single development board.
IMPORTANT NOTE
If you used different naming in the variable declaration, then update the code according to
your naming scheme. However, it’s better at first if you follow all the steps according to the
book and later change the cloud variable names and modify your code, respectively.
Also, don’t put the code at the end of the loop() method, as it will create a delay with
pulse sensor readings.
In this section, we discussed code and how it works with the Arduino IoT Cloud
Scheduler to turn the LEDs on and off. In the following section, we will set up a
dashboard, where we will place the Scheduler widget and attach it to our cloud
variables.
For Year and Month in the Repeat every section, we have different options in the
Scheduler. The following figures show all the details regarding both options. First,
let’s look at Month:
In this section, we outlined an assignment that will test your skills with different
scenarios and help you explore the usage of the Scheduler feature in different
environments. In the following section, we will start to explore the benefits of OTA,
the Arduino IoT Cloud's OTA features, supported development boards for OTA, and
how to use OTA features in the Arduino IoT Cloud. And, of, course you will also learn
about the pros and cons of the Arduino IoT Cloud OTA.
Despite these cons, OTA updates remain a valuable feature for many IoT projects.
However, it’s essential to carefully assess your project’s specific requirements and
constraints before implementing OTA updates and to address these challenges through
proper planning and security measures.
In this section, we discussed the different benefits of the Arduino IoT Cloud OTA
feature as well as its cons. In the following section, we will take a deeper look into
which hardware development boards are compatible with the Arduino IoT Cloud OTA
feature, as it is currently not supported by all hardware development boards.
Therefore, it’s necessary for you to keep this point in mind during the product
development stage if you need an OTA feature for your product.
These are the ESP32-series development boards that are ready for OTA:
ESP32-S2-DevKitC
NodeMCU-32-S2
WeMos LOLIN D32
ESP32-S3-DevKitC
ESP32-CAM
NodeMCU-32S
Freenove ESP32 WROVER
ESP32-DevKitC-32E
DOIT ESP32 DevKit v1
The good thing is that Arduino provides the latest features to ESP32-series
development boards. These boards are very popular among students/researchers and
professional developers, due to their cost and availability all around the world. I used
the XIAO ESP32-C3 series development board for various projects and tested the
OTA service for that board. From my personal experience, the OTA service works
faster on official Arduino development boards as compared to the ESP32 series, but I
hope in the future that the Arduino Cloud team will optimize the OTA feature for the
ESP32 series board for a faster and better experience.
IMPORTANT NOTE
The Arduino IoT Cloud offers the OTA feature to Wi-Fi-enabled devices. This means that
LoRaWAN is currently not compatible with the OTA feature.
In this section, we discussed the broad range of compatible boards that support the
Arduino IoT Cloud OTA feature. In the following section, we will take a look at how
we can use the OTA feature in the Arduino IoT Cloud to send firmware updates via the
internet, without any device connection to the host computer.
Implementing the OTA update on the MKR Wi-Fi
1010
Firstly, we will explore how we can use OTA, and then we will dive deep into how
OTA works behind the scenes. We need to navigate to a Thing that uses an OTA-
supported development board; we will choose a Thing that is already attached to the
MKR Wi-Fi 1010 device. Navigate to the Sketch tab in the Thing. The following
figure shows the OTA feature and port:
Figure 11.12 – The physical port connection with the OTA update feature
My device is connected to my MacBook as well as to the Arduino IoT Cloud via Wi-
Fi. That’s why you can see two options in the preceding figure for sketch uploading.
The first one is the Port option, which is only available when your development board
is directly connected to your laptop/computer, while the second option is Over-the-
Air, which is available when your code is configured on your development board with
network settings and successfully connected to the Arduino IoT Cloud over the
internet.
Select the Over-the-Air option, and click on the Sketch Uploading (the green arrow
icon) button; this will start uploading your updated code to the board via the internet
without the intervention of a physical connection. However, how can you confirm that
this works via the internet? Just unplug the development board from your computer
and power it with any adapter, but make sure your device has access to a Wi-Fi router.
Figure 11.13 – The standalone Over-the-Air update option
After disconnecting from the computer and turning on the device via the power
adapter, you will see only the Over-the-Air update option in your Sketch tab. Just
modify your code or add some extra login details, and click on Sketch Uploading (the
green arrow icon), and within a short time, your code will be on the development
board without any hassle.
Based on my experience, I've often thought we should have an option by which we can
modify/update the code of remote devices, such as devices for smart agriculture,
warehouse monitoring, and industrial monitoring, because it’s very difficult to travel to
remote places to update/modify the code. However, the Arduino IoT Cloud OTA
feature makes our lives easier overall. With the OTA feature, we can save time and
cost and provide the correct updates on time to our devices without any delay.
Summary
In this chapter, we explored the Scheduler and how we can use the Arduino IoT Cloud
to automate tasks that have different patterns or random patterns of operation. We used
simple LEDs with the MKR Wi-Fi 1010 to demonstrate multiple Scheduler/timer
operations, which helped you to understand how to use this function in real-world
projects, such as in smart agriculture and smart industry.
In the second part of the chapter, we explored OTA. Firstly, we discussed the pros and
cons of OTA and how we can save time and costs with it. Then, we used OTA-enabled
development boards to demonstrate the use of the OTA feature, and finally, we
explored how OTA works behind the scenes.
In the following chapter, we will implement a healthcare project. You will learn how to
use a heartbeat sensor as well as the Arduino IoT Cloud webhooks feature, which will
send data to a third-party service (Zapier). We will use Zapier to set up a Zap, which
will receive the heartbeat readings and send an email notification to a designated
person if the reading is over or under the threshold.
12
Technical requirements
The following hardware components are required to complete this chapter’s exercise:
Seeed Studio XIAO ESP32C3
USB Type-C cable for the XIAO ESP32C3
Pulse sensor (find the complete details and store links in the Knowing the hardware
components – sensors and development boards section)
Male headers for the development board
Jumper cables
For coding, we will use the Arduino Web Editor, which includes a large collection of
development boards and sensor libraries, along with Arduino IoT Cloud for Thing and
dashboard setup. To develop hardware and sensor designs, we need the Fritzing
desktop software and the Arduino IDE desktop software for pulse-sensor calibration
using the Serial Plotter, which is not available in the Arduino Web Editor.
We will also use Zapier to send alerts by email when our sensor detects a heart rate
above our specified beats-per-minute (BPM) threshold. You can use a Free/trial
account or buy a Zapier Professional plan according to the requirements of your
project as Zapier Professional provides more features and functions compared to a
Free account. The code used in this chapter is available from the book’s official
GitHub repository at https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-
Developers.
In conclusion, IoT can enable smart health solutions that improve patient outcomes
and reduce healthcare costs. Healthcare providers can use IoT data to provide
personalized care and make more informed decisions. As IoT technology continues to
evolve, we can expect to see even more innovative healthcare solutions in the future.
In this section, we have discussed IoT and smart healthcare and how IoT is beneficial
to us in the development of smart healthcare products. Next, we will take a look at
what types of hardware and sensors are required to carry out the exercise in this
chapter.
The preceding figure shows the pinout layout of the pulse sensor. Pin #1 is the GND
pin, which connects to the onboard GND pin. Pin #2, VCC, works with both 3.3V and
5V. Pin #3 connects to any analog pin on the board. I connect it to Pin #A1 on the
board. You can solder the male headers to the pulse sensor or directly solder the cables
without any header pins.
Measuring a pulse is a very critical and difficult task, but we can benefit from
pulsesensor.com, started by World Famous Electronics LLC as a crowd-funding
project. On this site, you can find all the official details including specifications, how
the sensor works, and development board code samples.
IMPORTANT NOTE
Chinese-made pulse sensors are good for DIY projects, but even sensors from official
stores can’t be deployed in real-world use cases without professional calibration using a
real-time electrocardiogram (ECG), BPM equipment, and a doctor’s verification.
In this section, we discussed the pulse sensor and where you can buy it, as well as
examining its pinout diagram for better understanding. Next, we will examine the
project architecture, covering how to connect the sensors to the XIAO ESP32C3.
Sensor calibration
For sensor calibration, we need the Serial Plotter to identify the pulse value threshold.
Currently, the Arduino Web Editor does not support the Serial Plotter, so we are going
to use the Arduino IDE. To work with the Arduino IDE, we need to install the Seeed
Studio XIAO ESP32C3 series development board and the pulsesensor.com library.
To install the ESP32 series development board in the Arduino IDE, firstly, add the
board’s definition file in the preferences:
1. Navigate to File > Preferences, and fill the Additional Boards Manager URLs field with the
following URL: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-
pages/package_esp32_dev_index.json.
2. Then, navigate to Tools > Board > Boards Manager..., type esp32 in the search box, select
the latest version of **esp32**, and install it.
3. Finally, select the board by navigating to Tools > Board > ESP32 Arduino and selecting
XIAO_ESP32C3. The list of boards is a little long and you will need to scroll to the bottom to
find it.
It’s time to install the pulse sensor library. Navigate to Sketch > Include Library >
Manage Libraries. Type pulsesensor playground into the search bar. Only one
library will be returned here – install it.
Now we are ready to proceed to the calibration step. Navigate to File > Examples >
PulseSensor Playground > Getting Started Project. Here, you will get the template
code for calibration, to which we will make the following changes:
// Variables
int PulseSensorPurplePin = A1; // Pulse Sensor PURPLE
WIRE connected to ANALOG PIN 0
int LED = 10; // The on-board Arduino LED
Set the PulseSensorPurplePin variable to A1. Remember to never use a simple 1 as
it will give you different values. Next, assign 10 to the LED variable. After these
modifications, upload the code to the board. To monitor the recorded values in graph
format, navigate to Tools > Serial Plotter. Figure 12.5 shows the Serial Plotter
presenting all the values in the form of a graph. The threshold values are marked by
the red box.
Figure 12.5 – Pulse sensor raw-readings graph using the Serial Plotter
Put a finger on the front side of the pulse sensor, which is marked with a white heart
shape. Wait for some time for the readings to stabilize on the Serial Plotter. After a few
seconds, you should see stable readings as shown in the preceding figure. Mark the
lowest level as the threshold. In my case, I take 3500 as the threshold value to avoid
noise.
After that, download the PulseSensor_BPM_Alternative code from the GitHub
repository under Chapter 12. This is some code modified by us that we’ll use to
display the BPM. But before uploading the code to the board, modify the values as
follows:
Figure 12.7 – Tracking and notifying about your heart rate Thing setup
Set up a new Thing with the name Tracking and notifying about your heart
rate. Then, proceed to the following sections of this chapter, which will take us
through the following steps to create the variables, associate the device, set up the
network configuration, and finally, apply the code:
1. Firstly, we need to set up one cloud variable for BPM. The complete details regarding cloud
variables are available in the following Cloud variables section.
2. After that, we need to associate the device with the Thing. In our current project, we are using
the XIAO ESP32C3, so the wizard will be different from that for Arduino boards. The
complete details are available in the Device association section.
3. Next, we need to set up the network configuration for the device, but this time, we need to
provide a security key for ESP-series boards to make the connection secure (whereas Arduino-
compatible boards are configured by the Arduino IoT Cloud automatically during the device
setup wizard).
4. Lastly, we will set up the webhook toward the end of the chapter, along with the notification
service using Zapier.
Cloud variables
The following table outlines the properties that we need to use during cloud variable
creation. For BPM, we could just use the integer data type, but thanks to the Arduino
IoT Cloud extended group of variables, we can choose the specific Heart rate
variable type. Next, make sure you use the same variable declaration as in the table;
otherwise, you will need to modify the example code according to your own naming.
For Permission, while we do have a Read/Write option, I chose Read Only as we
only want to receive data from the device, as opposed to dashboard modification, so
Read Only mode will avoid issues in data consistency. Update Policy is set to On
change as the device will send the data whenever there is any change detected in the
BPM value:
Device association
After variable creation, it’s time to add the device and associate it with the Thing.
Before adding the device, connect the development board to the computer and open
the Arduino Create Agent application. Figure 12.8 shows the device setup wizard
where we have selected ESP32 and then XIAO_ESP32C3 from the dropdown:
In this section, we associated the XIAO ESP32C3 device with the Thing. The device
association process is somewhat different to adding the Arduino MKR1010 to a Thing.
Next, let’s complete the network settings.
Network
After associating the device with the Thing, it is time to configure the Wi-Fi settings
for device communication. Fill in the form shown in Figure 12.9 with your Wi-Fi
Name and Password values. The last field here is the Secret Key field. Paste the
secret key value in here that we received from the system during device creation.
if (pulseSensor.sawNewSample()) {
if (--samplesUntilReport == (byte) 0) {
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
//pulseSensor.outputSample();
if (pulseSensor.sawStartOfBeat()) {
bPM=pulseSensor.getBeatsPerMinute();
Serial.print(bPM);
Serial.println(" bpm");
}
}
/*******
Here is a good place to add code that could take up
to a millisecond or so to run.
*******/
}
/******
Don't add code here, because it could slow the sampling
from the PulseSensor.
******/
In the loop method, the development board calls pulseSensor.sawNewSample() to
fetch new samples if they exist. Other than that, it will not call any activity, which is
why you will see a delay in readings returned if there is no change found by the system
in the BPM data. If any change occurred in the sensor readings, then BPM readings
will verify using the pulseSensor.sawStartOfBeat() method.
In the previous section where we created the cloud variable, recall the cloud variable
declaration – our pulseSensor.getBeatsPerMinute(); method assigns the sensor
reading to that bPM variable. This cloud variable declaration is available in the
thingProperties.h file. So, when you assign the values to these constants, the
ArduinoCloud.update() method in the loop will automatically send the data to the
cloud. Finally, upload the code to the device and verify the readings returned using the
Serial Monitor.
IMPORTANT NOTE
If you used different naming in the variable declaration, then update the code according to
your naming scheme. It would be better, however, if you followed the steps according to
the book first and then change the cloud variable names later and modify your code
respectively.
Never use the delay method, which will create a block for the
ArduinoCloud.update() method, and don’t put code at the end of the loop method, as
it will cause a delay in the pulse sensor readings.
The Arduino IoT Cloud only updates the value on the dashboard whenever the variable
value is changed. For example, if the heart beat is 80 and after 5 minutes it’s still the
same, then the Arduino IoT Cloud will not record the value, so don’t get confused if values
do not appear to change on the graph. Another benefit of this feature is you will not get
duplicated data when you export the content.
In this section, we discussed the code in depth and guided you through the code
operation and how to set the threshold values. In the next section, we are going to set
up the dashboard to visualize the BPM value in different formats for better
understanding.
Finally, we will use the Email by Zapier or Gmail option to send the notification. We
add multiple actions to the Zap. To keep things easy and manageable, we chose to use
a simple email notification. Alternatively, you could also use Twillo to send SMS
notifications to recipients.
Previously, we have discussed the different triggers and actions step by step that are
required for notifications to be triggered and sent. The following points will guide you
through these steps in Zapier:
1. The preceding screenshot gives a rough idea of how our setup looks in Zapier. To create a new
Zap in Zapier, click the Create button and select New Zap, which will open a new page where
you select the required triggers and actions.
2. Type Webhook in the search bar and select the Webhooks By Zapier option, which is
available under the Professional plan. Click on Event and select Catch Hook, then click
Continue. In the Trigger tab, just leave the empty Pick off a Child Key textbox as is and
proceed to the next step by clicking on the Continue button.
3. In the Test tab, you will get the webhook URL – copy that and navigate to Thing in the
Arduino IoT Cloud, then click on Set Webhook. Insert the URL into the window that pops up,
then hit the Save button.
Come back to Zapier and click the Test Trigger button to verify whether data is
arriving or not. Before you can verify this, the device must be powered on and
connected to the internet to send the values. This might not work on your first try; if
not, try again and you should see the data arriving, which means you are receiving the
data successfully from the Arduino Thing. Figure 12.12 shows a trigger test,
demonstrating the values received from the Arduino IoT Cloud pulse monitoring
Thing:
Figure 12.12 – Trigger test
The preceding screenshot shows Zapier successfully receiving the data from the
Arduino IoT Cloud Thing. In the red box, we can see bPM and value. The value
parameter will be used in the next action. Click the Continue button and a new Action
popup will appear. Here, we need to configure the filter action where we will set the
threshold for our BPM notification, as shown in Figure 12.13:
Figure 12.13 – Filter action
Type Filter in the search box and select Filter by Zapier. Click on Choose Field…
and select Values Value from the dropdown. Then, click Choose Condition, select
Number (Greater than), and put 100 in the next input field. This sets the upper
threshold value to 100 BPM. Next, click OR, and leave the value field as it is, but in
Choose Condition, select Number (Less than) and insert 60 in the next field. Lastly,
click on Continue.
Our filter is ready; now, our email notification action is required to finish the setup. We
have two options to send email notifications: either Email by Zapier or Gmail. I
opted to use Email by Zapier. Next, the Action popup window will appear; type
Email in the search box and click on Email by Zapier. Click on Event and select
Send Outbound Email. In the next window, set all the parameters for the email
receiver, subject, and body, as shown in the following screenshot:
Figure 12.14 – Email notification settings
Only three fields are mandatory here – insert the recipient email in the To field, write a
relevant entry for the Subject field, and insert a message in the Body area. It’s up to
you whether you fill the other fields or leave them blank. If you observe the preceding
screenshot, you may notice I added Values Value to both the Subject and Body fields,
which will display the values that triggered the notification in the email. Click the
Continue button at the bottom of the page and test the action – if you receive the
email with the BPM values, then publish the Zap and you are good to go.
In this section, we set up the notification services for our pulse monitor using Zapier.
We created a Zap that consists of three steps. Firstly, we set up the webhook
responsible for receiving the data. The second step deals with the threshold, and the
third and final step handles sending the email notification.
What next?
There are many more options available to explore, but these are left to you to work on,
using different health sensors and development boards to do some more experiments
and learn from them. In the current chapter, we only used one sensor that provided
only one parameter, but there are many sensors on the market that provide a wide
variety of functionalities including the monitoring of blood sugar, blood oxygen, blood
pressure, body temperature, and more.
Try the following sensors to enhance your practical knowledge and compare this
selection with other sensors in terms of features, ranges, and cost:
LilyPad temperature sensor (https://www.sparkfun.com/products/8777)
High-sensitivity pulse oximeter and heart-rate sensor for wearables
(https://www.seeedstudio.com/MAXREFDES117-HEART-RATE-AND-PULSE-OXIMETRY-
MONITOR-p-2762.html?
queryID=51de6141574a711bbe455cb4894ce3fb&objectID=411&index
Name=bazaar_retailer_products)
Fall detection module (https://www.seeedstudio.com/24GHz-mmWave-Radar-Sensor-Fall-
Detection-Module-p-5268.html)
Open source Arduino blood glucose meter shield
MIKROE series health sensors
Summary
In this chapter, we explored how to develop a low-cost wearable smart heart-rate
monitoring system using the XIAO ESP32C3 and a pulse sensor. One important thing
to note was the necessity of calibrating medical sensors before using them in the field.
We set up a Thing, which included cloud variable creation, device association, network
configuration, and coding for our development board. Later, we created a dashboard to
visualize our sensor readings with different widgets to display both current readings
and historical data with the help of graphs. Finally, we used Zapier to set up an email
notification service based on thresholds using webhooks and saw how to employ
webhooks to integrate third-party services with the Arduino IoT Cloud.
In the next chapter, we will learn about scripting in the Arduino IoT Cloud with the
Arduino Cloud CLI (CCLI). This is a command-line tool that provides access to
Arduino IoT Cloud services via terminal commands. We will use the Arduino IoT
Cloud CLI to automate bulk operations, including bulk device creation, which will
help us to minimize the time required for operations and maintenance.
13
Technical requirements
There are no specific hardware requirements for this chapter as we will focus on the
Arduino Cloud CLI and work through different command exercises to perform
operations on the Arduino IoT Cloud platform using a CLI. However, before we
proceed, we will need the following software to complete the different exercises in this
chapter:
The Arduino Cloud CLI
The Arduino IDE
An Arduino IoT Cloud account
For the commands, we need the Arduino Cloud CLI and an active Arduino IoT Cloud
account. This chapter only contains commands, so there is no folder for it on GitHub.
Here are some of the benefits of using the Arduino Cloud CLI:
Automation: The Arduino Cloud CLI can be used to automate tasks that you would otherwise
have to do manually. For example, you could use it to create a script that clones a Thing and
then performs a mass OTA upload to all of the devices that are associated with that Thing.
Efficient device management: The Arduino Cloud CLI can help you manage a large number
of devices more efficiently. For example, you could use it to list all of the devices that are
associated with a particular tag or to get the status of a particular device.
Access to advanced features: The Arduino Cloud CLI can be used to access features of the
Arduino IoT Cloud that are not available in a web interface. For example, you could use it to
create a script that checks the status of a device every minute and then sends an email alert if
the status changes.
Customization: Being open source, users have the flexibility to customize the Arduino Cloud
CLI to suit their specific needs and integrate it into their workflows.
Active development and community support: The tool is actively developed, meaning it
continually receives updates, new features, and bug fixes. Additionally, the presence of a large
community can provide assistance and support for users.
Time and effort savings: The Arduino Cloud CLI can save time and effort in managing IoT
projects, making it a valuable resource for developers working with Arduino devices.
Overall, the Arduino Cloud CLI is a powerful tool that can be used to automate tasks,
manage a large number of devices, and access features of the Arduino IoT Cloud that
are not available in a web interface.
In this section, we have discussed what the Arduino Cloud CLI is and what the
benefits of the Arduino Cloud CLI are. In the next section, we will explore how to set
up API keys and how to use API keys to authenticate the Arduino Cloud CLI with the
Arduino IoT Cloud.
arduino-cloud-cli
Then, you will see the following output on your terminal (Figure 13.2).
Figure 13.2 – The Arduino Cloud CLI terminal
This simply shows you how to use the Arduino Cloud CLI with different parameters,
as we didn’t specify any parameters during the command execution.
Now, it’s time to initiate the Arduino Cloud CLI authentication with Arduino Cloud,
using the API keys that we generated in the previous section. Type the following
command into the terminal:
Figure 13.3 – The Arduino Cloud CLI authentication process with Arduino Cloud
After successful authentication, you will see a success message on the terminal, as
shown in Figure 13.3. Congratulations! You are now ready to execute the commands
on the terminal and able to perform operations on the Arduino IoT Cloud via
commands.
In this section, we downloaded the arduino-cloud-cli file and installed it on our
operating system, and we also initialized the authentication process for the arduino-
cloud-cli tool with the Arduino IoT Cloud. In the next section, we will start playing
with devices using the command line.
Creating a device
Firstly, we will start by creating a device. The documentation on device creation can
be found at https://docs.arduino.cc/arduino-cloud/getting-started/arduino-cloud-
cli#device. Before you execute the command, connect your development board to your
computer and find out the port number and FQBN for your device from the
documentation page. The following is the syntax of the device create command:
Listing devices
In this section, we will list all the devices. Listing devices means displaying all the
devices with their properties. The documentation on listing devices is available at
https://docs.arduino.cc/arduino-cloud/getting-started/arduino-cloud-cli#list-devices.
The following is a very simple command to list all the devices:
Deleting a device
In this section, we will explore how we can delete a device using the device ID. The
documentation for deleting devices is available at https://docs.arduino.cc/arduino-
cloud/getting-started/arduino-cloud-cli#delete-a-device. The following is the command
syntax for device deletion:
arduino-cloud-cli device delete --id <deviceID>
According to the preceding command syntax, we need a device ID for deletion. You
can retrieve the device ID by using the device list command:
You might ask the question, why do we need a tag for a device? Let’s say you have a
generic product for warehouse monitoring, and you have deployed this product in
different organizations and different rooms. Now, the issue is that it’s very difficult to
assign the organization name and location in the Device Name field. So, an optimal
solution is tagging. You can use tags as many times as you want. A tag has two options
– one is a key and the other is a value.
In the following example, we will attach two tags – one for the organization name and
another for the location. Pick a device ID by using the device list command to
attach the tags. The following is the command to attach tags to a device:
Creating a Thing
After extracting the Thing template, we will now start to create the Thing. The
documentation on Thing creation can be found at https://docs.arduino.cc/arduino-
cloud/getting-started/arduino-cloud-cli#create-things. The following is the syntax of
the Thing creation command, which takes two parameters. Firstly, it will take the
name, and secondly, it will take the template filename for the Thing creation, which
contains the Thing template in JSON format that we saved in the previous section:
Cloning a Thing
After creating a Thing from a template, we will now explore how we can use the clone
operation for large-scale deployments. The documentation on the Thing clone can be
found at https://docs.arduino.cc/arduino-cloud/getting-started/arduino-cloud-cli#clone-
things. The following is the syntax of the thing clone command, which will take
two parameters. Firstly, it will take a name, and secondly, it will take a Thing ID:
Listing Things
In this section, we will list all the Things. The documentation on listing Things is
available at https://docs.arduino.cc/arduino-cloud/getting-started/arduino-cloud-
cli#list-things. The following is a very simple command to list all the Things:
Figure 13.13 – Displaying a single Thing based on a device ID, with cloud variables
In this subsection, we explored how to list Things by using different parameters. In the
next subsection, we will explore how to delete a Thing.
Deleting a Thing
In this section, we will explore how to delete a Thing using a Thing ID. The
documentation for deleting a Thing is available at https://docs.arduino.cc/arduino-
cloud/getting-started/arduino-cloud-cli#delete-things. The following is the command
syntax for Thing deletion:
According to the command syntax, we need a Thing ID for deletion. You can fetch the
Thing ID by using the thing list command:
You might question the necessity of assigning a tag to a Thing. Consider this scenario.
You have a versatile product designed for monitoring warehouses, and you’ve
deployed this product in various organizations and different rooms within those
organizations. The challenge arises when attempting to incorporate the organization’s
name and location directly into the Device Name field, which can be quite
cumbersome. In this context, a more efficient solution presents itself through the use of
tags. Tags can be applied without limitations, much like when we previously
established tags for devices. Each tag consists of two components: a key and a
corresponding value.
So, in the following example, we will attach two tags – one for the organization name
and another for the location. Pick the Thing ID by using the thing list command to
attach tags. The following is the command to attach tags to a Thing:
Deleting a dashboard
In this subsection, we will explore how to delete a dashboard using the dashboard ID.
The documentation for deleting dashboards is available at
https://docs.arduino.cc/arduino-cloud/getting-started/arduino-cloud-cli#delete-
dashboards. The following is the command syntax for dashboard deletion:
Creating a dashboard
After extracting a dashboard template, we can start to create a dashboard. The
documentation on dashboard creation can be found at https://docs.arduino.cc/arduino-
cloud/getting-started/arduino-cloud-cli#create-dashboard. The following is the syntax
of the dashboard creation command, which takes two parameters. Firstly, it takes the
name of the dashboard, and secondly, it takes the template filename for dashboard
creation, which contains the dashboard template in JSON format that we saved in the
previous section:
After executing the preceding command, you will get the following output for
successful dashboard creation (Figure 13.21):
Figure 13.21 – Dashboard creation using arduino-cloud-cli
Figure 13.21 shows the command and the output of successful dashboard creation by
the Arduino Cloud CLI. After creating the dashboard, the terminal shows the
dashboard name, id, updated_at, and widgets details.
IMPORTANT NOTE
There is a bug in the Arduino Cloud CLI for dashboard extraction, as it shows the Thing
name instead of the Thing ID in the thing_id value. Therefore, you need to replace the
text with the Thing ID; otherwise, an error will occur during the execution of the dashboard
creation command.
In this subsection, we created a dashboard in the Arduino IoT Cloud using the
command line. In the following section, we will explore how OTA updates work via a
CLI.
OTA management
In Chapter 11, we explored what OTA is and how we can easily use this feature to
send updates to remote devices. In that chapter, we used a graphical user interface,
which is a good option for a single device. However, when we have bulk Things to
send OTA, then the situation becomes complex, as we need to go through different
things one at a time to send OTA updates, which is very time consuming and a difficult
operation at the enterprise level.
That’s why the Arduino team created commands for the Arduino Cloud CLI to send
OTA updates to single or multiple devices automatically, to minimize the complexity
and operation time. So, firstly, we will explore how to export the compiled binary by
using the Arduino IDE, and then we will send an OTA update to a device using its ID.
For official documentation and updates, visit https://docs.arduino.cc/arduino-
cloud/getting-started/arduino-cloud-cli#ota-over-the-air.
What next?
After playing around with some commands, it’s now time to do some more
experiments so that you can apply your learning to new scenarios and learn new stuff.
We explored the complete list of commands available on the Arduino Cloud CLI.
However, you can check out Arduino’s official page for the latest updates and news to
keep yourself up to date with the latest features. Now, it’s your turn to create batch
scripts using the Arduino Cloud CLI to automate your operations, such as bulk device
addition in the Arduino IoT Cloud, bulk Thing creation using templates, binding
devices with Things, and creating a dashboard for every Thing from dashboard
templates.
Summary
In this chapter, we covered all the types of commands that are officially available to us
on the Arduino Cloud CLI. Firstly, we explored device-related commands, which
include device creation, listing devices, deletion, tagging, and untagging. Then, we
explored how to work with Things; in that section, we started with template extraction
and then created a Thing using a template. We also explored how to clone a Thing,
how to bind a device with a Thing, and so on. In the penultimate section, we played
around with dashboard commands, and in the last section, we explored how OTA
commands can benefit us by sending updates to devices via the command line in
different ways.
This chapter was specially designed for backend developers and administrators who
want to use the Arduino Cloud CLI to optimize their daily tasks, by using terminal
commands instead of a graphical user interface. This chapter will have helped them
interact with the Arduino IoT Cloud using a CLI. It will also have helped them to
create custom scripts, automating their daily tasks.
The following chapter is the last chapter of this book, and in this chapter, we will
explore different Arduino IoT Cloud plans for educational and enterprise
organizations. We will also explore industrial IoT hardware devices and different types
of Arduino IoT Cloud services that are especially available to enterprise organizations.
This chapter will give you a complete overview of how to scale your product from a
smaller scale to an enterprise level.
14
Number of 2 10 25 100
Things
Table 14.2 – The pricing plan for schools according to the number of students
Table 14.2 states the pricing according to student numbers and per member. Let’s
explore what features they provide to every school member. In the school plan, every
member can create up to 5 Things, with unlimited cloud variables and six-month data
retention, which is very good, especially for PhD and master’s students, as they may
want to collect data from IoT devices for further research and experiments, or are
building a prototype to solve a real-world problem. Also, the plan provides 10
notifications per day for cloud triggers and 10 requests per second for APIs.
The Arduino IoT Cloud school plan can also natively integrate with Google Classroom
users. This makes it easy for faculty members to manage their students, assignments,
and lots of other stuff in the Arduino IoT Cloud via Google Classroom. The Arduino
IoT Cloud also provides centralized billing and user management that is General Data
Protection Regulation (GDPR)-compliant.
There is another offer available to students via GitHub Education – the Student
Developer Pack. Students can visit the official GitHub page for further updates and
news: https://education.github.com/pack#offers. According to the current agreement
between Arduino and GitHub, Arduino provides six free months of the Arduino IoT
Cloud maker plan, as well as a discount on selected development boards.
In this subsection, we dived deep into educational pricing plans and their features for
each student. In the following section, we will explore the Enterprise Base Plan in
detail, which helps you to scale your product with enterprise-level features.
The Portenta X8 Manager is available as a paid add-on to the Arduino IoT Cloud
enterprise base plan, which costs USD 250 per month. For more details, refer to the
Enterprise Base Plan tab on the Arduino IoT Cloud plans page under the For
business tab.
In this subsection, we dived deep into machine learning and the Portenta X8 Manager
add-on for the Arduino IoT Cloud enterprise base plan. In the following section, we
will cover Arduino PRO hardware and software tools in detail.
Arduino PRO
Arduino PRO is a separate line of products that contain professional tools in both the
hardware and software categories. These tools are specially designed to carry out
industrial operations, such as those found in aviation, industry 4.0, healthcare,
robotics, smart cities, and smart homes/offices. We will explore both the hardware and
software tools step by step in the following subsections.
The Arduino PLC IDE interface is shown in Figure 14.5. which is totally different
from the Arduino IDE. It supports various programming interfaces, as mentioned in
the previous bullet points but one of the famous programming interfaces for PLC is the
Ladder Diagram, which is specially used by PLC engineers to program the PLC.
Figure 14.5 – The Arduino PLC IDE
The Arduino PLC IDE offers an intuitive user interface (shown in Figure 14.5),
complete with a suite of debugging tools, including watch windows, breakpoints with
step-by-step execution, triggers, oscilloscope functionality, and live debug mode. It
further extends its capabilities with rapid porting solutions and enables the integration
of PLC programming alongside Arduino sketches, through an integrated sketch editor.
This synergy permits the effortless exchange of variables between these two
environments, facilitating the inclusion of deterministic cyclic tasks and multitasking
within your software application.
The Arduino PLC IDE supports various industrial fieldbus protocols, including
Modbus RTU, Modbus TCP, and CANOpen. It offers a wide set of pre-installed
libraries and function blocks, as well as the option to create custom libraries. To
program with IEC 61131-3, you will need to unlock the hardware with a lifetime
license key, available at the Arduino Official Store.
For more information about the Arduino PLC IDE and its features, please visit the
official page at https://www.arduino.cc/pro/software-plc-ide/.
In this subsection, we discussed the Arduino PLC IDE, which is specially designed for
Arduino Opta PLC to program it. The Arduino PLC supports five different languages
to program in. In the following subsection, we will explore the Speech Recognition
Engine library.
The Speech Recognition Engine library
The Arduino Speech Recognition Engine is a powerful software library that enables
you to develop projects based on speech recognition. It allows you to interact with
machines using voice commands, without the need for vocal training or an internet
connection. The library was developed by Cyberon, a worldwide leader in speech
recognition, and is designed to be easy to use and compatible with multiple Arduino
boards and the Arduino IDE. It supports voice commands in over 40 languages,
regardless of the speaker’s voice, tone, or accent. You can configure multiple wake-up
words and sequences without retraining for different users.
The Speech Recognition Engine is ideal for various applications, such as smart
buildings and home automation, information kiosks, vending machines, smart beds in
hospitals, and emergency alert systems. It can listen to anyone speaking to it while
ignoring background noise.
To get started with the Arduino Speech Recognition Engine, you can visit the official
Arduino website: https://www.arduino.cc/pro/software-speech-recognition-engine/. It
offers a robust library featuring an integrated AI/ML engine that excels in phoneme-
based modeling. This advanced library enables the recognition of multiple wake-up
words and sequences of commands without the need for vocal training. The library is
compatible with multiple Arduino boards and requires no additional hardware,
software, or internet connectivity.
Note that there is also another Arduino board called Nicla Voice, which was discussed
in the Arduino PRO hardware section. This board implements always-on speech and
motion recognition at the edge. It integrates a neural decision processor from Syntiant
(NDP120) to run multiple AI algorithms.
In the Arduino PRO section and subsections, we explored the main Arduino PRO top-
of-the-line development boards, including the Portenta series, the Nicla series, and the
OPTA PLC series. We also explored Arduino PRO software, including the Arduino
PLC IDE and the Speech Recognition Engine library. In the following section, we will
cover some further resources for your learning.
In this section, we explored the different online resources that will help you to keep
yourself updated with new developments, as well as become part of the online maker
communities, keeping yourself engaged for further learning.
Summary
In this chapter, we explored different pricing plans for individuals, educational
institutes, and enterprise organizations. All the plans were discussed in depth, and we
also compared the plans to explore further differences. The Arduino IoT Cloud
provides features with different thresholds for different plans, according to users’
needs. Then, we explored the Arduino PRO software and hardware tools in depth,
allowing you to make informed decisions when developing industrial solutions.
Finally, we explored further resources that can provide you with the latest news and
updates about product developments, and we also shared different community
resources that a user can benefit from by becoming a member.
So, after reading this chapter, you will be able to identify which pricing plan you need
for your usage and also guide your organization or customers, according to their needs,
on which Arduino Cloud plan is suitable for them. You also now know the Arduino
PRO hardware development boards, including the Portenta, Nicla, and Opta series, as
well as Arduino PRO software, including the Arduino PLC IDE and the Speech
Recognition Engine. This Pro line will help you to identify and choose specific
hardware and software tools for your professional and industrial-grade solutions.
Finally, you now know how to keep yourself updated by following the links provided
in the Further resources and insights section.
As we reach the end of Arduino IoT Cloud for Developers, I hope this journey has
been as enlightening and rewarding for you as it has been for me. The world of IoT is
a realm of limitless possibilities, where the things around us become more intelligent,
responsive, and interconnected.
Through these pages, we explored the fundamentals of IoT, delved deep into the
capabilities of the Arduino IoT Cloud, and brought our knowledge to life through
hands-on projects. We embraced the power of data exchange, advanced scripting, and
practical applications that enhance our lives.
Remember that IoT development is a continuous adventure, with countless
opportunities waiting for you. As you move forward, keep experimenting, creating,
and innovating. The world needs your ideas, your solutions, and your vision for a
smarter, more connected future.
Whether you’re a novice or an experienced developer, I encourage you to stay curious,
keep learning, and never stop exploring. The intersection of IoT and Arduino is a place
where innovation thrives, and it’s now your playground.
Thank you for embarking on this journey with me. Here’s to the endless possibilities
that IoT and the Arduino IoT Cloud bring to our lives. The future is yours to create.
Index
As this ebook edition doesn't have fixed pagination, the page numbers below are
hyperlinked for reference only, based on the printed edition of this book.
A
access
securing 327, 328
acid rain 96
Adafruit 119
ADS module library 239
agriculture IoT system
architecting 233
assembly of hardware components 236-239
PCB design 236-239
schematics and design 234-236
agri-tech project
hardware components 229-233
air quality monitoring 96
significance, reasons 96, 97
air quality monitoring system
assembly of hardware components 102, 103
associated device 105, 106
cloud variables 105
code 107, 108
dashboard setup, for web and mobile 109, 110
hardware requirements 97-100
network configuration, for Thing 107
PCB design 102, 103
project architecture 100
schematics and design 100, 101
Thing setup 103, 104
Altium 237
Amazon Alexa 255
URL 271
used, for integrating Arduino IoT Cloud 271-274
Amazon Echo Dot 82
Analog Electrochemical Carbon Dioxide Sensor 111
Analog Input (AIN) 240
Analog Output (AO) 100
analog-to-digital converters 98
Apache License 25
API authentication keys
creating 192, 193
setting up 193
API keys
setting up 327, 328
using, to authenticate Arduino Cloud CLI 327, 328
Application Programming Interface (APIs) 69
Arduino 97
Arduino Cloud
URL 192
Arduino Cloud CLI devices 330
creating 330
deleting 332
listing 331
tagging 333
untagging 333
Arduino Cloud Command-Line Interface (CLI) 325-327
benefits 326
installing 329, 330
Arduino Create Agent 33, 34, 83, 286
download link 33
Arduino Create Agent application 105, 150, 180, 265
Arduino ecosystem 7
Arduino IDE
used, for exporting binary 347, 348
Arduino IoT Cloud 3, 95, 96, 169-171, 190, 279, 351
and MKR1010 Hello World example 32
and Node-RED Hello World example 52
API, setting up 56, 57
architecture 31
cloud variables 313
coding 316, 317
device association 314
enterprise base plan 354-356
functionality 190, 191
integrating, with Amazon Alexa 271-274
interfaces 190
network settings 315
notification service, setting up 318-322
operation 190, 191
options, for data visualization and data extraction 32
plans 351, 352
plans, for individuals 352, 353
plans, for schools 353, 354
project architecture 308
schematics design 308, 309
sensor calibration 309-311
setting up, for web and mobile 317, 318
Thing, setting up 312, 313
variable, setting up 57
working 30, 31
Arduino IoT Cloud API
reference link 196
Arduino IoT Cloud interface 64
components 64, 65
dashboards 68, 69
devices 65
integrations 69, 70
templates 69, 70
Thing 66, 67
Arduino IoT Cloud module
installing, for Node-RED 54, 55
Arduino IoT Cloud OTA feature 296
advantages 296
compatible development hardware, listing 298, 299
disadvantages 297
Arduino IoT Cloud Scheduler 281, 283
assignment tasks 295
associated device, adding with Thing 285-288
benefits 281, 282
cloud variables 284, 285
coding 289-291
network configuration 288, 289
Thing, setting up 283, 284
Arduino IoT Web Editor
features 88, 89
Arduino MKR GSM 1400 118
Arduino MKR WAN 1300 135
Arduino Nano RP2040 68
Arduino Node.js SDK client
installing 198, 199
Arduino Opta Programmable Logic Controllers (PLCs) 7
Arduino PLC IDE 361
reference link 362
Arduino PRO 357
for commercial use cases 24
Arduino PRO hardware 357
Nicla family 358, 359
Opta PLC 360, 361
Portenta family 357, 358
reference link 357
Arduino PRO software 361
Arduino CLI application 361
Arduino PLC IDE 361, 362
IDE 2 361
IoT Cloud 361
reference link 361
Speech Recognition Engine library 361-363
Arduino Safe Bootloader 22
Arduino SAMD 122
Arduino Speech Recognition Engine 363
reference link 363
Arduino trademarks
in commercial applications 27
Arduino Web Editor 96, 170, 289
elements 83
examples 85
Help menu 88
libraries 86
Library Manager 86, 87
Preferences menu 88
Reference option 88
Serial Monitor 87, 88
sketchbook 84
URL 83
Arduino webhooks 319
Artificial Intelligence (AI) 8-10, 69
asset-sharing model 15
asset tracking 16, 135
asymmetric encryption 23
automated irrigation 228
AWS S3 storage 301
AWS services 64
B
Beagle Bone 70
big data 8-10
Bluetooth Low Energy (BLE) 19, 97
Bluetooth Low Energy (BLE 5) 256, 306
BMP280 sensor 111
bootloader 21
breadboard 100, 308
BSD License 25
bulk device provisioning 23
business models
enabled, by IoT 13-17
C
Cat-M 116
chart widget 80
Circuit Maker 237
Client ID 192
Client Secret 192
Cloud Applications 17
Cloud Latency Time 6
Cloud Scheduler widget 292-294
cloud-to-cloud communication path 20
cloud variable/property synchronization
limitations 187, 188
cloud variables 199, 245, 246
adding 41-44
associated device 246, 247
cloud variable synchronization
working 173
Colored light widget 74
Color widget 73
communication technologies 18-20
Computerized Maintenance Management System (CMMS) 12
Constrained Application Protocol (CoAP) 171
Creative Commons Attribution Share-Alike license 26
cron job 75
crop monitoring 229
crypto-chips 21, 24
C-type syntax 197
cURL library 191
D
dashboard 6, 219
creating 292
dashboards, with Arduino Cloud CLI 342
creating 345, 346
deleting 345
listing 344
template, extracting from dashboard 342-344
dashboards, with Node.js SDK
creating 219, 220
deleting 221, 222
listing 222, 223
updating 220, 221
dashboard widget controls
reference link 82
data pin 99
data retention 355
data visualization 219, 342
device
adding 36-40
device operations, with Node.js SDK 199
creating 199, 200
deleting 202
displaying 204, 205
listing 202-204
properties/variables, obtaining 205, 206
updating 201, 202
Device-to-Device (D2D) communication 169
Device-to-Device (D2D) communication, in IoT cloud 170
challenges 171
direct communication 170
efficiency 170
low latency 170
offline operation 170
protocols 171
security 171
use cases 171
device-to-gateway path 19
DHT11/DHT22 sensor/module 95, 98
Digital Output (DO) 100
Dimmed light widget 73, 74
Discord 82
E
EasyEDA 237
encryption, for secure communication 22, 23
end-to-end IoT application
architecture 17, 18
Enterprise Resource Planning (ERP) 12
ESP32-DevKit V1 229
ESP-series boards 95
event-oriented methods 267
F
field-to-device path 19
fleet management 355
Fourth Industrial Revolution 11
Free Software 25
Fritzing 96, 102, 173, 233
Fully Qualified Board Name (FQBN) 65, 200
G
gateways 18
gateway-to-cloud link 20
global IoT SIM cards 116
features 116
service providers 117
GNU General Public License (GPL) 25
GNU Lesser General Public License (LGPL) 25
GoLang 70, 197
Google Assistant 82, 255
Google Looker 69
GPS module 80, 142
graphical flow-based programming language 50
graphical user interface (GUI) 44, 169, 193
ground (GND) pin 99
GSM/LTE/NB-IoT communication technologies
advantages, exploring 115
GY-GPS6MV2 GPS module 118
H
hardware components
for agri-tech project 229-233
hardware security 21, 22
Hyper EUICC IoT SIM card 124
I
IFTTT 70, 190, 318
inadequate access controls 21
Indoor MKR Wi-Fi 1010 173
Industrial Internet of Things (IIoT) 3, 10-12
Industry 4.0 3, 11, 12, 135
input controls 71
Colored light widget 72, 74
Color widget 72, 73
Dimmed light widget 72-74
push button 71
Scheduler Widget 75, 76
slider 71
stepper 71
switch 71
time picker widget 74, 75
Integrated Development Environment (IDE) 26
integrations 69
Integromat 318
intelligence at the edge
versus on-the-cloud approach 5, 6
interactive widget
used, for creating dashboard for web and mobile 46-49
Internet of Things (IoT) 3, 4, 8-12, 135, 169, 228
asset tracking 114
condition monitoring 114
enabling, business models 13-17
LoRaWAN, usage 136
OTA updates, exploring 295, 296
predictive maintenance 115
used, for creating smarter homes 254, 255
using, in smart agriculture 228
remote controlling 114, 115
remote monitoring 115
IoT building blocks
development boards 117-119
sensors 117-119
IoT cloud environment
scheduler, employing advantages 280, 281
IoT, for smart health solutions
development boards 305
exploring 304, 305
hardware components 305
predictive maintenance 305
project architecture 308
remote patient monitoring 304
sensors 305-307
smart hospital management 305
smart medication management 305
telemedicine 304
IoT Nodes 4
IoT SIM cards
activating, for deployment 124, 125
IoT solutions
device provisioning 21
security 21
J
JavaScript (Node.js) 70
JLCPCB 102
L
LED widget 78
Light Dependent Resistor (LDR) values 43, 79
livestock management 229
Logic Out LED 100
Long Range Wide Area Network (LoRaWAN) 135, 136
advantages, over other communication technologies 137, 138
usage in IoT 136
LoRaWAN devices 331
LoRaWAN IoT application
components 138, 139
LoRaWAN node 65
Low-Power Wide Area Network (LPWAN) 6, 115, 136
LTE-M 118
M
Machine Learning (ML) 8-10, 69
machine learning tools 355, 356
map widget 80
Message Queuing Telemetry Transport (MQTT) 171
messenger widget 82
meta tags 66
MH-Z19C/D/E series sensors 111
MIT License 25
MKR1010 Hello World example
and Arduino IoT Cloud 32
MKR Wi-Fi 1000 97
MKR Wi-Fi 1010 66, 97
OTA update, implementing 299, 300
MKR Wi-Fi 1010 example
used, for implementing Scheduler 282
Mozilla Public License (MPL) 25
MQ series sensors 111
N
naked REST APIs 193
NEO-6M u-blox chip 118
network
configuring 41
Nicla family 358
Nicla Vision 359
Nicla Voice 359
reference link 359
Node.js 197
URL 198
Node-RED 50, 51
Arduino IoT Cloud module, installing for 54, 55
benefits 51
project, creating with 57-61
Node-RED editor 52, 53
Node-RED Hello World example
and Arduino IoT Cloud 52
nodes 53
O
on-the-cloud approach
versus intelligence at the edge 5, 6
open source licenses
benefits 25, 26
obligations 25, 26
open source software 24
protection, of intellectual property 26, 27
Opta PLC 360
Opta Lite 360
Opta RS485 360
Opta Wi-Fi 360
reference link 361
OTA management 346, 347
OTA update
implementing, on MKR Wi-Fi 1010 299, 300
outcome-based model 15
output controls 77, 78
chart widget 79, 80
gauge widget 79
map widget 79, 80
messenger widget 81, 82
percentage widget 79
status/LED widgets 78
sticky notes widget 81, 82
value widget 78
Overall Equipment Effectiveness (OEE) 16
Over-the-Air (OTA) 279, 295, 325
benefits 296
binary, exporting with Arduino IDE 347, 348
reference link 298
sketch, uploading to 348, 349
usage, examples 295, 296
working 301
P
parts per million (ppm) 99
pay-per-usage model 15
PCBWay 102
Peer-to-Peer (P2P) communication 170
pilot SIM card 124
pin layout (pinout) 229
Portenta family 357, 358
Portenta H7 Lite 358
Portenta H7 Lite Connected 358
Portenta Machine Control 358
Portenta Max Carrier 358
Portenta X8 358
reference link 358
Portenta series 7
Portenta X8 Manager 355, 356
Postman 193
download link 193
used, for testing API call 194-197
workspace 193, 194
Power LED 100
precision farming 229
Printed Circuit Board (PCB) 95, 258
project architecture
designing 120
GPS module, assembling 120, 121
GPS module data, testing 122-124
schematic design 120, 121
properties/cloud variables 214
properties/cloud variables, with Node.js SDK
creating 214, 215
deleting 217
listing 218, 219
updating 216, 217
property value, with Node.js SDK 224
obtaining 224
setting 225
PRO series
reference link 7
protocols 18-20
pull requests 70
pull resistor 243
pulse sensor 306
push button 71
push requests 70
Python 70, 197
R
Raspberry Pi 70
razor-blade business model 16
Real-Time Clock (RTC) module 74
Red Green Blue (RGB) color 73
remote asset tracking with LoRaWAN
assembly 142-144
cloud variables, setting up 149
coding 157, 158
development board 140-142
device, associating 150-156
GPS module data, testing 144-147
mobile dashboard, creating 163, 164
network configuration 156
project architecture, designing 142
schematics design 142-144
sensors 140-142
Thing, setting up 148, 149
web dashboard, creating 163, 164
remote operation monitoring 135
Representational State Transfer (REST) API 32
role-based access control 355
S
Scheduler 279, 280
employing, advantages in IoT cloud environment 280, 281
implementing, with MKR Wi-Fi 1010 example 282
Scheduler Widget 75-77
SDKs, for programming platforms 197
GoLang 197
Node.js 197
Python 197
Secure Element 24
Seeed Studio 102, 119
Seeed Studio SCD30 111
Seeed Studio XIAO ESP32C3
reference link 256
sensing period 99
sensing range 99
sensor/actuator values 78
sensor calibration
perfecting 239-244
sensors/actuators 31
Serial Monitor 122
baud rate 88
code debugging 87
process execution 87
sensor testing 87
Serial Monitor tool 144
Serial Peripheral Interface (SPI) 141
Single Sign-On (SSO) 18
sketch
writing 44, 45
Slack 82
slider button 72
smart agriculture 227
Internet of Things (IoT), using 228
smart agriculture system
cloud variables 245, 246
cloud variables, setting up 244, 245
coding 248-250
mobile dashboard, creating 250, 251
network configuration 247, 248
networks, setting up 244, 245
things, setting up 244, 245
web dashboard, creating 250, 251
smart harvesting 229
smart home IoT project
air quality monitoring system Thing setup 263
assembly 258, 259
blueprint 258
cloud variables 264
coding 266-270
dashboards, setting up for mobile 270, 271
dashboards, setting up for web 270, 271
device, associating 265
network configuration 266
schematic design 258, 259
Thing, setting up 264
WS2812, testing with Arduino IDE 260-263
smart homes 253
creating, with IoT 254, 255
development boards 256-258
sensors 256-258
smart remote monitoring 135
smart transportation 135
Software-as-a-Service (SaaS) 318
Software Development Kits (SDKs) 31, 69
SparkFun 119
status widget 78
stepper button 72
sticky note widget 82
subscription model 16
Surface Mount Device (SMD) LEDs 100
switch button 71
symmetric encryption 23
synchronized cloud variables
used, for implementation of GUIs 186, 187
T
Tableau 69
tags 67
Telemetry Elements 4
template
extracting, from dashboard 342-344
extracting, from Thing 334, 335
Templates page 69
Thing 66, 206
associated device 127, 128
cloud variables 126, 127, 176-179
coding 130, 184, 185
comprehensive web and mobile dashboards, creating 131, 132
configuring 125, 126
creating 34, 35
device, associating 180-182
interface 66
network 182, 183
network settings 129, 130
setting up 175, 176
setting up, for Arduino IoT Cloud 312, 313
Thing CRUD operations, with Node.js SDK
creating 207, 208
deleting 211
displaying 213, 214
listing 211, 212
updating 208, 209
Things Indoor Gateway
configuring 158-163
Thing sketch
creating 209, 210
Things operations, performing with Arduino Cloud CLI 334
cloning 336, 337
creating 335, 336
deleting 339
device, associating with Thing 340
listing 337-339
tagging 340-342
template, extracting from thing 334, 335
untagging 340-342
thing-to-thing communication, Arduino IoT Cloud
benefits 171, 172
thing-to-thing communication (TTC) 169
time picker widget 74, 75
token authentication mechanism 192, 327
Trusted Platform Module (TPM) 24
Twillo 319
U
User Interface/User Experience (UI/UX) field 71
users
benefits, by implementing IoT 12, 13
V
value widget 78
VIN 229
voltage common collector (VCC) 99, 119
VSCode 198
W
Warehouse Management Systems (WMSs) 12
weather monitoring 229
Webhooks 69
webhook trigger 319
web technologies
evolution 14
WeMos D1 MINI ESP8266 95
Wi-Fi/LoRa-enabled microcontroller 65
wireless IoT nodes
benefits 19
WS18B20 module 73
WS2812
testing, with Arduino IDE 260-263
WS2812 RGB LED 253
X
XIAO ESP32C3 200, 256, 305
architecture 308
schematics design and assembly 308, 309
sensor calibration 309-311
XIAO ESP32-C3 series 299
Z
Zap 319
Zapier 64, 190, 318
Zigbee 171, 255
Z-Wave 255
Packtpub.com
Subscribe to our online digital library for full access to over 7,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.
Why subscribe?
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
Fully searchable for easy access to vital information
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 Packtpub.com and
as a print book customer, you are entitled to a discount on the eBook copy. Get in
touch with us at customercare@packtpub.com 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.
https://packt.link/free-ebook/9781837637171
2. Submit your proof of purchase
3. That’s it! We’ll send your free PDF and other benefits to your email directly