Communicating With An IoT Device
Communicating With An IoT Device
Communicating with an
3 IoT Device
Lesson Time: 3 hours, 25 minutes
Lesson Introduction
You have set up an Internet of Things (IoT) device that can operate on its own power and
connect with other devices over the Internet, but it's still missing a few ingredients
commonly found in the Internet of Things. In this lesson, you'll give your device the ability
to communicate over various types of connections.
Lesson Objectives
In this lesson, you will:
• Use a wired connection to communicate with an IoT device.
• Use a wireless connection to communicate with an IoT device.
• Use the Internet Protocol Suite to communicate with an IoT device.
84 | Certified Internet of Things (IoT) Practitioner (Exam ITP-110)
TOPIC A
Communicate Using Wired Connections
An IoT device may use a wired connection to connect to other devices or the Internet.
Item Description
EtherNet/IP (EIP) An industrial networking protocol developed by ODVA, Inc., a global
trade and standards development organization. The protocol is based on
Common Industrial Protocol (CIP, also developed by ODVA), which is
widely used with Rockwell industrial automation systems. EIP operates
on standard Ethernet hardware, supporting IP communication using TCP
and UDP.
EIP distinguishes between these message types:
• Implicit messages: The data field does not contain protocol
information, but only real-time I/O data, minimizing the time needed
to process the message.
• Explicit messages: General purpose, point-to-point connections that
support request-response transactions between two devices, using
TCP/IP services to send messages over the industrial Ethernet
network.
Item Description
Process Field Net An industrial Ethernet standard maintained and supported by Profibus
(PROFINET) and Profinet International, designed to support real-time (under 1 ms or
less) data communication for the purpose of data collection and industrial
control.
The standard supports three levels of data communication:
• TCP/IP: Communications that are not time critical, with an expected
response within 100 ms.
• RT (Real-Time): Time critical communication with cycle times up to
10 ms.
• IRT (Isochronous Real-Time): Time critical communication with
cycle times less than 1 ms.
EtherCAT (Ethernet An Ethernet-based system developed by Beckhoff Automation, and
for Control standardized as IEC 61158. EtherCAT is intended to support real-time
Automation communication over Ethernet for process automation applications while
Technology) also supporting reduced hardware costs.
Precision Time A standard for precise clock synchronization of real-time devices
Protocol (PTP) communicating over Ethernet, originally defined in the IEEE 1588-2002
standard, published in 2002. PTP is intended to provide more accurate
synchronization than the services provided by Network Time Protocol
(NTP) and Global Positioning System (GPS). PTP was revised in 2008 as
IEEE 1588-2008, also known as PTP Version 2, to improve its accuracy,
precision, and robustness.
Time Sensitive A collection of standards under development by IEEE, Intel, Cisco,
Networking (TSN) National Instruments, and other organizations to provide Ethernet with
deterministic network behavior, meaning that it can be mathematically
determined precisely how long it will take for data to be delivered from a
"talker" to a "listener." With traditional Ethernet, which provides "best
effort" delivery, the delivery time cannot be determined. TSN can
function alongside traditional Ethernet, ensuring that deterministic traffic
will have priority over non-deterministic traffic.
OPC
In the 1990s, the Open Platform Communications (OPC) standard was pulled together based on
Microsoft's standards for distributed computing. While this solution provided much needed
interoperability, it was dependent on Microsoft Windows and starting to show problems of age,
such as cybersecurity issues. In 2002, Microsoft dropped support for standards that OPC was based
on.
In 2006, the OPC Foundation developed a new version of their open standard, renamed Open
Platform Communication Unified Architecture (OPC-UA) to include security improvements
and provide support across many different operating systems. It defines communications between a
86 | Certified Internet of Things (IoT) Practitioner (Exam ITP-110)
variety of systems, and has been adopted for use in a wide range of industries, including
manufacturing, energy, and pharmaceuticals.
OPC-UA supports:
• A streamlined binary protocol, which can easily be enabled through a firewall
• A web service protocol (SOAP), which uses standard HTTP/HTTPS ports
With the wide support for programming web services on microcontrollers, OPC-UA's support for
web services has made it a good choice for communicating with embedded devices, and because
OPC-UA has been widely adopted by many different vendors, it enables a wide range of equipment
from different vendors to interoperate.
DDS
In the late 1990s, the U.S. Department of Defense introduced the concept of the Global
Information Grid (GIG — essentially a military version of IoT). The DoD used the Data
Distribution Service for Real-Time Systems (DDS) standard developed by the Object
Management Group (OMG).
The DDS spec defines the Real Time Publish-Subscribe (RTPS) protocol, which defines a publish-
and-subscribe model for efficient delivery of data from programs producing information (such as
sensor devices) to programs consuming that data. The standard also includes the DDS
Interoperability Wire Protocol (DDSI-RTPS), which provides a standard for data communication
over an unreliable transport protocol such as UDP.
Item Description
Modbus In 1979 Modicon (now known as Schneider Electric) produced this
protocol for use with its line of PLCs. This protocol is now commonly
used for industrial networking, and has been adopted by other vendors
because it is an open, royalty-free standard that is relatively easy to
implement.
In 2004, Schneider Electric transferred rights to the Modbus protocols to
the Modbus Organization, an association of users and suppliers of
Modbus-compliant devices.
HART Initially developed by Rosemount Inc. in the mid-1980s to support
Communication communication with their instrumentation products, this protocol
Protocol (Highway evolved into an industrial automation protocol that supports both digital
Addressable Remote and analog signaling methods. Because of its ability to communicate
Transducer) through legacy analog wiring, the Highway Addressable Remote
Transducer (HART) protocol provided an easy transition for
conversion of legacy instrumentation to smart systems, making it one of
the most widely used industrial protocols.
Item Description
PROFIBUS (Process In the late 1980s, a German initiative backed by 21 organizations
Field Bus) proposed a plan for a serial field bus, which was promoted by the
German department of education and research (BMBF) and implemented
by Siemens in their industrial automation products. PROFIBUS is part of
the IEC 61158 open standard.
The Field bus Message Specification (FMS) specification was released
first. Later the Decentralised Peripherals (DP) specification was released.
FMS supports non-deterministic communication, while DP is designed
for deterministic communication.
Note: All of the Guidelines for this lesson are available as checklists from the Checklist tile on
the CHOICE Course screen.
ACTIVITY 3-1
Communicating over a Wired Serial Connection
Before You Begin
The course data files are installed on your computer in C:\095024Data. These files include a
customized version of the Arduino IDE (located in C:\095024Data\Tools\arduino), which
contains example programs that you will use in this course. The example programs are contained in
the File > Sketchbook sub-menus inside the Arduino IDE.
The ESP8266 microcontroller is connected to a USB port on the development computer. The
Arduino IDE is not running.
Scenario
The ESP8266 microcontroller can obtain and process all sorts of data, but unless you have a display
device of some sort attached to it, it can't display the information it processes. So you must
communicate with it somehow to obtain that information. One way you can do that is using the
USB serial interface that you have already used to upload a program. In this activity, you will upload
a program that queries the microcontroller for various types of information, and displays that
information in a console on the development computer.
Note: During the course, we suggest that you not install updates if the Arduino IDE prompts
you to do so. The course was written for the version of the Arduino IDE and software libraries
that are included with the course, and installing the updates may change menu options and
features, and may cause some of the source code to not compile correctly.
• Line 8 specifies that the IoT device will use 9600 baud as its data rate.
• A computer communicating with this device will need to match this data rate to correctly read
data from the device, so it knows how frequently to sample the data for values.
b) Select Tools→Serial Monitor to display the serial monitor window.
c) Arrange the windows so you can see the code window and serial monitor side by side.
d) In the serial monitor window, set the line ending characters to Carriage return and the baud rate to
9600 baud.
4. Compile and upload the program while you review the rest of the source
code.
a) Select Sketch→Upload or press Control+U to start the compile and upload process.
• When the program starts running, lines 15 through 24 print information about the microcontroller
out to the serial connection.
• This information will be sent over the serial data line (USB cable) from the IoT device to the
development computer.
c) Examine the code in the loop function in the Serial_Communication window.
• Similar to the Blink program, each time this program runs its main loop, it just flashes the LED on
and off.
5. When the program runs on the IoT device, examine the message the IoT
device sends over the USB cable.
a) In the serial monitor, examine the message received from the IoT device.
• Information about the microcontroller appears in the serial monitor. This information was
transported from the device to your development computer over the USB serial connection.
• Communication through wired serial connections is useful for development and debugging, and
for situations where IoT devices are in a fixed location where wiring is practical.
• Wireless technologies such as Wi-Fi and LTE are typically better suited for connecting mobile
IoT devices or those in situations where wiring is impractical.
• The requirements for this project are that the device be connected wirelessly, so you'll need to
add some code in order to connect to Wi-Fi and communicate using TCP/IP.
Note: Your microcontroller may be using different versions of SDK, core, and
bootloader than those shown here.
b) In the serial monitor, observe how much sketch memory is in use, and how much space is
remaining.
• This small program gives you an idea of how much code you can upload to the microcontroller.
• As you can see from the numbers output in the serial monitor, it's already using about 10%, so
the programs you install on the device must be fairly small.
• This reveals an important point about designing IoT devices; typically, code on the devices
themselves must be quite small and efficient.
TOPIC B
Communicate Using Wireless Connections
You've established wired communication with a prototype IoT device for development purposes,
but the requirements call for a device that can connect to a network wirelessly. You will now enable
the device to connect to a wireless network.
Wireless Communication
Using wireless communication enables devices to be mobile, or located in remote locations where
wired communication options may not be practical. However, the distance over which data can be
transmitted by wireless devices is an important design concern. As a general rule, doubling the range
covered by a wireless transmission requires a fourfold increase in power. There are tradeoffs
between power consumption, data rates, and the distance that can be traversed, so it is important to
identify your requirements for these different attributes before selecting a technology.
The following terms are often used to provide a conceptual description of the various ranges that
may need to be supported by different devices.
Item Description
Near Range • Very short range
• Typical: Hand-to-hand exchange
• Distances measured in inches
• Example: Devices used as a digital wallet, or "bumping" smartphones
to exchange data
PAN (Personal Area • Short to medium range
Network) • Typical: Same room
• Distances of no more than 15 feet
• Example: Wearable fitness tracker that uses Bluetooth to send data to
a smartphone app
HAN (Home Area • Medium range
Network) • Typical: Within a single residence, extending into the surrounding yard
• Distances up to hundreds of yards
• Example: Actuators located throughout a home to control lighting
and power to electrical outlets.
LAN (Local Area • Medium range
Network)
• Typical: Same building
• Distances up to hundreds of yards
• Example: Sensors located throughout a single assembly line using Wi-
Fi to transmit data to a gateway device in the engineering office
WAN (Wide Area • Long range
Network) • Typical: Same campus
• Distances in miles
• Example: An industrial network supporting industrial control systems
throughout the entire campus
Item Description
MAN (Metropolitan • Long range
Area Network) • Typical: Same city
• Distances up to a few miles
• Example: Smart parking sensors connected in a mesh network
throughout an entire city
Note: These terms may be useful to identify the conceptual range a wireless network must
cover, but they don't correspond directly to a specific distance that must be covered. For
example, one home area network might cover a small apartment, while another might cover
several acres.
Note: To learn why mesh networks are beneficial for IoT implementations, check out the
Spotlight on Mesh Networks for IoT presentation from the Spotlight tile on the CHOICE
Course screen.
Item Description
Near Field This protocol is used for very short range communication (less than two
Communication inches). It is commonly used for payment systems, and also has been used
(NFC) for asset tracking and smartphone data exchange.
Radio Frequency Electronic tags attached to objects store identifying information that can
Identification be read by an RFID reader, typically over a range of a few feet or less.
(RFID)
RFID tags may be passive or active.
• Passive tags are suitable for devices without batteries since the power
source is not required by the tag.
• Active tags periodically broadcast their ID, while assisted passive tags
become active when RFID reader is present.
RFID is commonly used for inventory tracking in retail and industrial
IoT.
Item Description
IEEE 802.11 (Wi-Fi) The IEEE 802.11a/b/g/n specification defines protocols for wireless
connection to a local area network, and is very widely used by the current
generation of IoT devices. Wi-Fi is a trademark of the Wi-Fi alliance,
which certifies products that adhere to IEEE 802.11a/b/g/n, ensuring
interoperability of those products. 802.11n produces very high data
throughputs at the cost of high power consumption. IoT devices may
instead use 802.11b or 802.11g to conserve power.
Item Description
Bluetooth Bluetooth short-link radio technology was initially developed in 1989 by
Ericsson Mobile to support the connection of wireless telephone headsets
to cell phones. Bluetooth radios are rated for a range of no more than 100
meters.
Bluetooth Low Energy (BLE) (originally named Wibree) is a Bluetooth
alternative designed to support small personal devices like wearable health
and fitness trackers, using much less power while providing a similar
communication range.
IEEE 802.15.4 This specification, originally released in May 2003, defines a wireless
personal area network that achieves extremely low power consumption
through simple technologies that provide low data rates. The standard's
efficient use of power and simplicity makes it well suited for constrained
devices.
This standard is implemented by various competing technologies,
including Z-Wave, Zigbee, 6LoWPAN, Thread, WirelessHART, and
others.
Zigbee
Zigbee builds on the physical layer and media access control specifications defined in IEEE
802.15.4 to provide a medium range wireless network for applications such as home automation,
wireless sensor networks, industrial control, medical data collection within a clinical or home setting,
and smart buildings. Zigbee is not well suited for situations in which the networked devices are
highly mobile and require frequent reconfiguration.
Zigbee provides a less complicated and more energy-efficient alternative to Wi-Fi and Bluetooth.
Zigbee operates on the same 2.4 GHz radio frequency as BLE, but with a longer range (up to 100
meters) and a slightly lower data rate (250 kbps maximum) than BLE's 270 kbps.
Zigbee supports mesh, star, and tree network configurations. Devices play various roles in a Zigbee
network: coordinator, routers, and end devices.
• Coordinator: At least one coordinator is required, functioning as the root device, and providing
a gateway to other networks. The coordinator processes and stores information on behalf of
other devices.
• Router: Routers manage the flow of data between devices.
• End device: End devices perform various sensor and actuator functions. To conserve battery
power, they have limited communication functionality, relying on routers and coordinators to
manage communication and data aggregation.
Some devices in the network can sleep to save power, but other devices must remain awake between
bursts of network communication to function as routers or coordinators, depending on their current
position and role in the network.
Note: Zigbee is named for the zig-zag pattern honeybees follow when collecting pollen.
Likewise, Zigbee data can "zig" and "zag" through a reconfigurable mesh network until a
suitable path is found to the destination.
Zigbee Topologies
Zigbee supports various network topologies. Star, mesh, and cluster tree are the most commonly
used. The type of network topology used influences the number and configuration of devices
required. Regardless of the topology, at least one coordinator is required.
A network can be set up as a star, with each end device connecting directly to the coordinator, and
no routers required. The coordinator manages communication over the network. This topology is
simple and easy to configure.
When you introduce routers into the mix, other configurations are possible, such as mesh and
cluster tree.
Routers can be interconnected to create redundancy paths in the network. If any node loses
connectivity, data can be routed automatically through remaining paths. In this way, a mesh
topology can improve the reliability of wireless sensor networks like Zigbee.
Z-Wave
Z-Wave is another wireless communication technology based on IEEE 802.15.4. Z-Wave was
designed by Zensys, a Danish company based in Copenhagen, for use in home automation. It
started as a proprietary technology, and was later released into the public domain. Z-Wave provides
interoperability among home control systems of different manufacturers that are a part of the Z-
Wave alliance. With hundreds of companies in the alliance and thousands of products using the
standard, Z-Wave is widely used in home automation products.
Based on IEEE 802.15.4, Z-Wave was designed to use less power than Wi-Fi, and provides a greater
range than Bluetooth. It is designed to be easy to set up and configure. A Z-Wave hub serves as the
network controller, enabling up to 232 devices to wirelessly communicate with each other. From
one device to another, the range is about 100 meters, but because Z-Wave uses a mesh network,
each connected device may extend the network's overall reach. Z-Wave signals hop from one device
to another, extending the network to more devices, so five devices could span a total distance of 400
meters.
For security, the Z-Wave network and each of the devices within the network have unique IDs that
communicate only with other local devices and the hub. A different hub cannot control devices
associated with the local hub. Sensitive devices like door locks and alarms use AES-128 encryption
to provide even more security.
Z-Wave communicates in the 800-900 MHz radio frequency range, so it is not subject to
interference from Wi-Fi, unlike Zigbee, which operates in the 2.4 GHz frequency that is commonly
occupied by Wi-Fi signals.
WirelessHART
In 2004, WirelessHART was developed to provide a wireless communication protocol compatible
with HART to provide an easy transition path for those wishing to use new, wireless technologies in
their legacy industrial networks that use the HART protocol. WirelessHART is a reliable protocol
that uses advanced encryption to provide security over a wireless connection.
Item Description
Cellular With IoT, machine-type communications (MTC) are expected to
represent a significant portion of communications provided by services
such as cellular. Cellular systems designed for human-type
communications were not intended to efficiently send very short packets
between massive numbers of devices. Furthermore, IoT applications
require wide-area coverage with deep indoor penetration, while
maintaining low costs and energy efficiency. New cellular technologies
address these needs.
The challenges for cellular providers have been described as ultra-reliable
machine-type communication (uMTC) and massive machine-type communication
(mMTC). While uMTC focuses on availability, low latency, and high
reliability, mMTC focuses on the challenge of scaling wireless
connectivity to tens of billions of IoT devices.
Narrowband IoT (NB-IoT) is an LPWAN radio standard that enables a
wide range of cellular devices and services, focusing on indoor coverage,
low cost, long battery life, and high connection density. NB-IoT
implements a subset of the LTE standard, operating in a single narrow
band of 200kHz.
5G, when released, will also support the objectives of uMTC and mMTC.
LoRaWAN LoRaWAN (long range wide area network) refers to a vendor alliance
(Semtech, IBM, Microchip, Cisco, Bouygues Telecom, Singtel, KPN,
Swisscom, FastNet, and Belgacom) focused on creating LPWAN
technologies for IoT devices. It is relatively inexpensive to add
LoRaWAN to a new area, making it a good choice for IoT products that
need to be located in areas where cellular service is not already present.
This technology is primarily for data uplinks, sensor networks where most
of the communication from the sensor devices are uploads to a gateway
or cloud service.
While LoRaWAN is an open standard, the chipset it runs on is
proprietary, owned by Semtech. long range (LoRa) is the physical layer
technology that LoRaWAN runs on. LoRa uses license-free sub-gigahertz
radio frequency bands such as 169 MHz, 433 MHz, 868 MHz (Europe),
and 915 MHz (North America), and supports low-power data
transmissions with a range of more than 10 km (6 miles) in rural areas.
SigFox SigFox has been providing wireless networks for low-power devices since
2009. SigFox uses proprietary technologies, with a signal that can pass
freely through solid objects.
Like LoRaWAN, this technology is also for data uplinks.
RPMA Random Phase Multiple Access (RPMA) is a proprietary LPWAN
technology stack developed by Ingenu. RPMA uses the globally available
2.4 GHz spectrum used for Wi-Fi and Bluetooth.
Lesson 3: Communicating with an IoT Device | Topic B
100 | Certified Internet of Things (IoT) Practitioner (Exam ITP-110)
Item Description
Satellite Satellite communication provides a good wireless backhaul option,
enabling devices in remote locations to connect to the Internet.
Narrowband providers such as L-band currently dominate IoT satellite
offerings, but newer high-throughput Ku-band and Ka-band are well
suited for use in IoT. New transceiver designs will use compact electronic
antennas (no dish) and power-saving modems suitable for use with IoT
devices.
ACTIVITY 3-2
Testing Wi-Fi Communication with a
Microcontroller
Scenario
You will start implementing wireless capabilities on the device by establishing that you can connect
to a local Wi-Fi network. Although a user interface of some sort will have to be provided so end
users can configure the device for the Service Set Identifier (SSID) and Wi-Fi password, for now
you'll just hard-code that information into the program.
• Placeholders are provided in lines 3 and 4 for the Wi-Fi network's SSID and password. (You'll
replace these later.)
• Lines 7 through 13 in the setup function set up the serial connection, similar to how this was
done in the previous activity. The serial connection is being used here only to provide the
developer with feedback. It's not needed in order to connect to Wi-Fi.
• Line 19 starts the Wi-Fi connection. It uses the SSID and password values that were defined in
lines 3 and 4.
• The code that implements the ability to connect to Wi-Fi is contained in the ESP8266WiFi
library, which is included in the project through an include directive in line 1.
• The program runs a loop at lines 20 through 23 until the connection is completed.
• The network automatically assigns an IP address to the device, which is printed out to the serial
port in line 27, so you can see the device's IP address printed in the serial monitor.
a) In line 3, revise the text within the double quotes to identify the SSID for the local Wi-Fi router.
Note: Your instructor will provide you with the SSID and password for the
classroom Wi-Fi router. If you are a remote student, you'll need to use the
credentials for the Wi-Fi router in your remote course environment (e.g., your
office or home Wi-Fi router).
b) In line 4, revise the text within the double quotes to provide the password for the Wi-Fi router.
4. Upload and run the program, and examine the output to the serial monitor.
a) Make sure the serial monitor window is showing and set for a 9600 baud connection.
b) Upload the sketch to the microcontroller.
c) When the program runs, examine the output in the serial monitor.
6. Many IoT devices do not have their own display or keyboard. How can you
provide users with access to the IoT device so it can be configured to access
the local Wi-Fi network access point?
smartphone, but there must be some way for the smartphone to easily connect directly to the IoT
device.
Since many smartphones also have Bluetooth, consumer IoT devices often use Bluetooth to pair up
an IoT device with a smartphone. Then an app on the smartphone can be used to provide the user
interface through which the IoT device can be configured for the wireless network.
Of course, wireless provisioning schemes like this should be carefully designed so as not to create
security or usability problems. There are different tradeoffs with each approach.
SSID and entering the network password could be provided through a simple web page hosted
on the IoT device.
• Pro: Uses technologies commonly found in most mobile devices and computers.
• Pro: Other options for configuring the IoT device can be presented along with the Wi-Fi
settings.
• Pro: Additional security could be provided through a button on the IoT device, which must
be pressed to enable the configuration mode. If such a button is provided, a pre-defined
password for the configuration manager could be provided, simplifying setup for the user.
• Con: The IoT device must include code to host a simple web server, which may consume
storage needed for other programs.
ACTIVITY 3-3
Providing a Wi-Fi Configuration Manager
Before You Begin
The course data files are installed on your computer in C:\095024Data. These files include a
customized version of the Arduino IDE (located in C:\095024Data\Tools\arduino), which
contains example programs that you will use in this course. The example programs are contained in
the File > Sketchbook sub-menus inside the Arduino IDE.
The ESP8266 microcontroller is connected to a USB port on the development computer. The
Arduino IDE is running, and the serial monitor is showing.
Scenario
You have previously hard-coded your prototype IoT device to connect to Wi-Fi. Now you will set it
up to present a Wi-Fi configuration manager to provide a user interface through which users can
provide it with the SSID and password whenever it cannot connect to a Wi-Fi router.
When you assign an SSID and password to the ESP8266, it caches them so it can reconnect later.
Since you've already successfully connected the device to Wi-Fi, you'll start by running a program
that will clear the previous Wi-Fi credentials.
1. Upload a program that will clear the device's current Wi-Fi configuration.
a) Select File→Sketchbook→Communicating with an IoT Device→WiFi_Forget.
The sketch opens in a new Arduino IDE window. The window you were previously using,
WiFi_Communication, is still open in the background.
b) Close the WiFi_Communication window, and position the WiFi_Forget window side by side with the
serial monitor.
c) Select Sketch→Upload.
• Line 17 calls WiFi.disconnect(), which clears the previously cached Wi-Fi connection.
• Lines 13 through 14 and 20 through 21 contain print statements to show the data stored before
and after the Wi-Fi data is cleared, so you can verify the data has actually been cleared from the
device.
a) When the program runs, examine the output in the serial monitor.
• The SSID and password you provided earlier are shown. Then the connection is cleared. The
second time the SSID and password are shown, they are empty text.
• The next time the device accesses Wi-Fi, it will not be able to reuse the last SSID and password.
• Line 27 prints the currently cached SSID to the serial port. This is done only for debugging and
development purposes, since it won't be necessary to use the serial monitor in the finished
product.
• Lines 30 through 36 use the Wi-Fi manager software library to establish the Wi-Fi connection.
• The software library contains code that will set up the device as a Wi-Fi access point if it can't
use cached credentials to connect.
b) Examine the configModeCallback() code.
• This function is called when the device has to enter configuration mode (because the cached
credentials don't enable it to connect).
• More information is shown for debugging and development purposes. In an actual product, the
device might flash an LED or provide some other feedback to inform the user the device is in
configuration mode.
a) When the program runs, examine the output in the serial monitor.
• The device doesn't have a stored SSID and therefore needs the user's help to connect to a Wi-Fi
router. The user documentation for the device would provide the user with information similar to
that shown in the serial monitor to establish a connection to a new Wi-Fi router.
• In practice, you might also include a button on the device to force the device into configuration
mode when pressed. This would enable you to specify a different SSID and password, even if
the device currently has cached credentials that enable it to successfully connect.
b) Using your computer, smartphone, or tablet with a Wi-Fi capability, browse the available Wi-Fi
routers, and attach to the IoT device that you named.
• For example, in the Windows 10 Settings app, you can select Network & Internet, and then
select Show Available Networks to display available networks, as shown in the following. When
you select your device and select Connect, you will be prompted to enter the password.
c) When you are prompted for the password to the IoT device access point, enter 123!Pwd$
• Your computer is no longer connected to the local Wi-Fi network, but is instead connected to the
IoT device as a Wi-Fi access point.
• After you have logged in to the IoT device as an access point, a browser may be launched after
a few seconds.
• Depending on the computer or device you are using, the browser may automatically open the
configuration page at 192.168.4.1.
d) If your browser does not automatically open the configuration page after a few seconds, open the
address 192.168.4.1 in your browser.
• This web page is provided by the IoT device, which is running as a web server.
• The Wi-Fi network provided by the IoT device is not Internet connected. There are only two
devices on its little network—the IoT device itself, and the computer you have used to attach to
it.
• The purpose of this page is to temporarily provide an accessible user interface for the IoT
device, so you can provide the device with the SSID and password of the actual Wi-Fi network it
should attach to.
d) If the Credentials Saved browser window did not automatically close itself, then close it.
After a moment, the device connects to the Wi-Fi network using the SSID and password you
provided.
f) In the computer, smartphone, or tablet you used to configure the device, show the available Wi-Fi
networks again.
Your IoT device is no longer available as an access point. (It may take a moment to disappear.)
Note: You may need to reselect the local Wi-Fi router to reattach your
computer to the local Wi-Fi network. In many cases, the computer will reattach
automatically to the local Wi-Fi network once the IoT device stops functioning
as an access point.
10. Examine how the device reconnects to Wi-Fi, once it has been configured—
even if a new sketch is uploaded.
a) Select Sketch→Upload to upload a new copy of the program.
b) When the program runs, examine the output in the serial monitor.
• As long as the IoT device can successfully reattach to the network using the cached Wi-Fi
credentials, it will continue to do so.
• If the device cannot connect to Wi-Fi at any point, it will present itself as a Wi-Fi hotspot again,
so it can be reconfigured.
11. What
do you like and dislike about using the "IoT device enters access point
mode" approach to Wi-Fi configuration on a headless device?
TOPIC C
Communicate Using Internet Protocols
You've enabled an IoT device to connect to the network. Now that it is on the network, it can use
application-layer messaging protocols to communicate with other devices, such as IoT gateways, or
client applications. In this topic, you will enable a device to communicate using common web
protocols provided by the Internet Protocol Suite.
The Internet of Things, as the name implies, relies on the Internet to communicate, and underlying
the Internet is the Internet Protocol Suite, the communication standards that define how the
Internet works. The Internet Protocol Suite is also called TCP/IP after two of the major protocols
in the suite.
Thinking of the Internet Protocol Suite as a four-layer reference model may help in understanding
the tasks performed by protocols at each distinct layer, as well as how each layer interacts with
another in the communication process. These are the four layers of the TCP/IP reference model:
• Application layer: Defines the protocols used by applications as well as how host applications
interface with the transport layer protocols to access network resources.
• Transport layer: The protocols that manage session connections between host computers and
control data transfer.
• Internet layer: The protocols that package data into IP datagrams, which include source and
destination information, to control packet routing between hosts and across networks.
• Network interface layer: The protocols that define how IP datagrams are packaged and
physically transmitted through the network.
translated to an IP address, and the HTTP request composed by the browser is sent to the server.
Behind the scenes, the HTTP request is essentially a text document with lines ending with a carriage
return and line feed characters.
A request might be in the form of a GET request, which specifies the requested resource (/
index.htm), the protocol for the request (HTTP 1.1), and the web host's address.
GET /index.htm HTTP/1.1
Host: www.mysite.com
When the web server receives an HTTP or HTTPS request, it replies with a response such as the
following.
HTTP/1.1 200 OK
Date: Wed, 30 May 2018 12:22:21 GMT
Server: Apache
Last-Modified: Sun, 22 May 2018 09:33:11 GMT
ETag: "51142bc1-7449-479b075b2891b"
Accept-Ranges: bytes
Content-Length: 29769
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head> ...
The response begins with a header that describes what is contained in the response, followed by the
content of the response. Typically the content is an HTML page (abbreviated previously to save
space).
For example, web protocols can be used to provide a remote management interface for setting up
and configuring IoT devices, gateways, routers, and so forth. Devices not commonly thought of as
web servers can present themselves as a web server to provide a user interface that can be accessed
by remote users.
Cloud services that aggregate, process, and present IoT data can present users with a web
application that enables users to view aggregated data, filter and search, generate reports, and
perform other tasks.
HTML web pages provide the user interface for examples described previously. But HTML is not
the only payload that HTTP can deliver. HTTP can also be used to deliver XML, JSON, and
numerous other file formats. Behind the scenes, applications can use HTTP to communicate over
the web. Programs running throughout the entire IoT infrastructure commonly use HTTP/HTTPS
to interact with web/cloud services—exchanging data, messages, and other communications.
IP Addressing
One vision for IoT is to provide every IoT device with its own unique IP address to represent its
presence on the Internet.
Internet Protocol version 4 (IPv4), the traditional Internet addressing scheme that many users are
familiar with, can provide about four billion devices with a unique IP address, such as 184.30.114.35.
Four billion is a very large number but it is not enough to give every person on the planet his or her
own IP address for a personal device like a computer, tablet, or smartphone. Add to this the routers,
switches, gateways, and many other network devices on the Internet, and you've already run out of
addresses. With the Internet of Things, presumably billions more "things" will be added to the mix.
Cisco predicts there will be 50 billion connected devices by 2020.
Internet Protocol version 6 (IPv6) offers a solution to this problem by increasing the number of
possible addresses to 340 undecillion. (Another way of expressing that amount is 340 trillion trillion
trillions.) It's hard to imagine running out of addresses with IPv6 for a long time to come.
Furthermore, the software that supports IPv4 has been around a long time, and many security
vulnerabilities have surfaced over the years. Many cybersecurity lessons were learned before IPv6
software was developed, so simply moving to IPv6 may improve the security outlook somewhat.
Encapsulation
Figure 3-4: Data is encapsulated at the sender and decapsulated at the receiver.
Network communication begins with an application composing the payload (such as a message or
request) to send to another device. In the case of a web application, for example, this would be in
the form of an HTTP/HTTPS request. The application opens communication with the receiver.
Depending on the type of connection it needs to establish, it will open either a TCP or UDP
connection.
The application uses the transport services provided by TCP/IP to start the process of
encapsulating the data. The data is encapsulated within a TCP segment or UDP packet. These
containers act as shipping envelopes, providing an encapsulation (wrapping) around the data and
information needed to handle that data during transit, and at its destination. It's similar to the way an
envelope provides a wrapper for a letter and provides information (such as the recipient's address)
needed during transit and delivery. Information provided at this layer includes a checksum that can
be evaluated to ensure data at the other end is intact and has been transported successfully.
The transport services then pass the encapsulated data off to Internet services, which encapsulate
the whole thing with a wrapper, which provides information used for addressing and delivery, such
as the IP addresses of the sender and receiver.
The Internet services then pass the data off to the data link and physical layers, which encapsulate it
even further, adding framing information necessary to ensure the data is physically encoded and
transported over the network.
At the other end, the encapsulation process is reversed, with the outermost wrapper removed and
information provided in the wrapper read and interpreted by the receiver to reassemble the data,
verify it, and eventually hand it off to the receiving application it was sent to.
Each layer of encapsulation provides a specific set of data to be used at the other end, so it is
important for the sender and receiver to use the same protocols at both ends of the communication.
Figure 3-5: Using an IoT gateway to manage communications between Zigbee and TCP/IP
networks.
A common network design pattern used for IoT devices and sensor networks involves setting up an
IoT gateway to serve as the communication manager between IoT devices and the cloud. The IoT
devices may only communicate with each other and with the IoT gateway over the local network,
whereas the IoT gateway can communicate over the local network and over the Internet. The IoT
gateway uses TCP/IP to communicate over the Internet, enabling it to handle all communication
with cloud services on behalf of the devices in its local network.
Although a Wi-Fi or Ethernet based TCP/IP network could also be used for the local network, a
lightweight network protocol geared toward IoT, such as Zigbee or Z-Wave, may be used for local
communications. This enables the constrained devices (IoT devices and sensors) to communicate as
quickly as possible, offloading the more demanding communication tasks to the IoT gateway.
Note: Networking tasks such as encapsulation, bridging, encryption, VPN tunneling, and so
forth can add significant overhead to networking, increasing the required bandwidth, electrical
power, time, and other resources. An important part of designing an IoT network is planning
where these tasks should occur.
Note: Although IPv6 addressing would enable every IoT device to have its own Internet
address, IPv6 has not been fully adopted yet, and even where it has been adopted, the best
option may not be to provide every IoT device with its own global IP address—or with any IP
address at all.
parameters that enable you to prioritize some communications over others, or to specify reliability
requirements.
Typically, QoS settings involve a tradeoff. For example, if you configure communications to be
acknowledged by the receiver, then you can ensure that a message reached its destination. But such
acknowledgment produces more network traffic and takes longer to complete. So before you design
and configure quality of service, you must take time to identify which communications have priority,
and determine the rules underlying your priorities.
Note: If you give one type of communication more priority, then other types of
communications will have less priority. If you give all communications high priority, then
essentially all communications will have average priority.
Multiple layers of protocols may be involved in a particular communication scenario, and each layer
of protocols may have its own QoS parameters that you can specify. For example, an application
may use a certain messaging protocol that provides quality of service parameters, and the network
that application is communicating over may use a network protocol that has its own QoS
parameters. So tailoring quality of service may involve multiple QoS parameters in multiple protocol
layers.
For example, IoT devices might be using an unreliable network-layer protocol such as User
Datagram Protocol (UDP), where delivery is not acknowledged or guaranteed. But QoS parameters
used in the Application layer can ensure the message gets delivered. For example, the messaging
service could be configured with a QoS setting to resend messages until they are acknowledged by
the receiver.
Also, note that QoS options must have some leeway to prioritize traffic or routing in order to have
an impact. This can be useful, for example, on a wireless mesh network, where multiple paths may
exist between two points.
Note: In practice, under certain conditions (such as very high or very low network traffic
volumes), QoS options may have little effective impact on the quality of service provided.
Networking Abstraction
It is predicted that billions of new IoT devices will be added to networks in the next few years.
Many of these devices will be mobile, with applications in transportation, logistics, wearables, and so
forth. And many of the devices that are stationary will be added and removed frequently. The
predicted increase in network traffic and complexity of the communications involved in IoT will
bring new challenges for network administrators, programmers, and system integrators.
Careful design, planning, and implementation strategies can help to make IoT networks easier to
reconfigure and more resilient to problems caused by change. For example:
• Using routing and quality of service parameters to make the most efficient use of the network.
• Distributing processing and communication tasks where they can be handled most effectively
(such as IoT devices handing off heavy processing and communication tasks to an IoT gateway).
• Strategically selecting appropriate network protocols and technologies for specific tasks within
the overall architecture (such as lightweight encryption and communication protocols for
constrained devices).
• Using wireless networks to reduce the need to physically reconfigure networks.
• Using mesh networking topologies for wireless devices to provide alternate paths as devices go
offline.
However, in many cases, optimum network configuration will be a moving target. Scaling and
reconfiguring network capabilities will be a never-ending task. A possible solution to this problem is
to automate the task of reconfiguring the network. Network virtualization technologies, such as
software-defined networking (SDN) and network function virtualization (NFV), help to make
this kind of automation possible.
SDN
Note: NFV and SDN are sometimes confused. They are complementary but different
technologies. While NFV and SDN are similar in that they move network services to a virtual
environment, NFV does not include policies to automate the environment.
ACTIVITY 3-4
Communicating with an IoT Device Using HTTP
Before You Begin
The course data files are installed on your computer in C:\095024Data. These files include a
customized version of the Arduino IDE (located in C:\095024Data\Tools\arduino), which
contains example programs that you will use in this course. The example programs are contained in
the File > Sketchbook sub-menus inside the Arduino IDE.
The ESP8266 microcontroller is connected to a USB port on the development computer. The
Arduino IDE is running, and the serial monitor is showing. You have successfully connected the
device to the Wi-Fi network, and the SSID and password are now cached on the device.
Scenario
In most cases, IoT devices are "headless." That is they do not have their own monitor or display
that can be used to provide a user interface. The typical IoT device is controlled through a remote
client application the user launches on a computer or mobile device. In some situations, however,
the IoT device might have its own compact web server, which a user can access through a web
browser to communicate with the device.
In this activity, you will explore this approach by loading a simple web server on the IoT device, and
accessing it in your development computer's web browser. Controls on the web page will enable you
to turn the device's onboard LED on or off.
• Much of this code builds on the code from the previous activity.
• Line 4, which is new, imports a software library that enables the program to function as a web
server.
• Line 18 defines an object that will be used to manage the web server. As is typical, the web
server will run on port 80.
• Lines 21 and 22 define objects that will be used in the program. The LED will initially be set to
HIGH. On the microcontroller you're using, this will set the LED to be off initially.
• Again, much of this code has been carried over from the previous sketch. It establishes a
connection with the serial monitor and sets up Wi-Fi.
• Line 43 is new. This line starts the web server. You'll be able to access it using the IP address
provided by the Wi-Fi connection.
• Lines 53 and 54 set the initial state of the LED to off, using the LED pin value that was initialized
in line 21.
• These lines process the web request, which is communicated in a format that adheres to the
HTTP protocol.
• The request is issued by the user's web browser when the user enters the URL in the address
bar.
• The request is output to the serial port, so you'll be able to see the actual request in the serial
monitor when you run the program.
• Lines 77 and 78 extract text from the URL that is used to communicate the desired LED state,
and line 79 sets the data pin for the LED to set its state based on the request.
• These lines compose the web response, which is communicated back to the user's web browser
in a format that adheres to the HTTP protocol.
• This HTTP response is returning web page content in the HTML format. The DOCTYPE of the
response, specified in line 85, is HTML.
The serial monitor shows the device's web address. You will use the address shown in your serial
monitor to load the configuration page in your web browser.
b) On your development computer, launch a web browser and enter the web address of your IoT
device.
Note: Your device may use a different URL than the one shown here. Use the
address that was shown in your serial monitor in step 4a.
c) Examine the microcontroller, and verify that its onboard LED is off.
d) Examine the serial monitor.
e) Select the Turn it ON link. Observe the web page that loads, and the state of the microcontroller's
LED.
Note: You may need to scroll up to see this request if another GET /
favicon.ico request was issued.
• Querystring parameters are often used to pass data values to the server as part of the URL.
g) Position the mouse pointer over the Turn it OFF link, and examine the link information shown in the
browser's status bar.
h) In the browser address bar, change on to off, and press Enter to load the revised address.
The LED is turned off, and the new page provides a link to turn it on again.
Licensed For Use Only By: Multimatics . [email protected] Nov 22 2019 3:26AM
Lesson 3: Communicating with an IoT Device | Topic C
132 | Certified Internet of Things (IoT) Practitioner (Exam ITP-110)
Summary
In this lesson, you used various methods to communicate with an IoT device. You communicated
over a serial cable, and you used a wireless network connection. You also used the Internet Protocol
Suite and HTTP to provide the IoT device with a remote user interface to configure its Wi-Fi
connection, view its current state (LED status), and control it (turn the LED on or OFF).
As simple as it is, what major software subsystems are now installed on the
device?
Note: Check your CHOICE Course screen for opportunities to interact with your classmates,
peers, and the larger CHOICE online community about the topics covered in this course or
other topics you are interested in. From the Course screen you can also access available
resources for a more continuous learning experience.