Unit 3
Unit 3
Unit 3
Figure 1
IoT Architecture Overview:
IoT can be classified into a four or five-layered architecture which gives you a complete overview of
how it works in real life. The various components of the architecture include the following:
Four-layered architecture: this includes media/device layer, network layer, service and application
support layer, and application layer.
Five-Layered architecture:
Five-layered architecture: this includes perception layer, network layer, middleware layer,
application layer, and business layer.
Sensor/Perception layer: This layer comprises of wireless devices, sensors, and radio frequency
identification (RFID) tags that are used for collecting and transmitting raw data such as the
temperature, moisture, etc. which is passed on to the next layer.
Network layer: This layer is largely responsible for routing data to the next layer in the hierarchy
with the help of network protocols. It uses wired and wireless technologies for data transmission.
Middleware layer: This layer comprises of databases that store the information passed on by the
lower layers where it performs information processing and uses the results to make further
decisions.
Service and application support layer: This layer involve business process modeling
andexecution as wellas IoT service monitoring and resolution.
Application layer: It consists of application user interface and deals with various applicationssuch
as homeautomation, electronic health monitoring, etc.
Business layer: this layer determines the future or further actions required based on the
dataprovided by thelower layers.
In 2014 the IoTWF architectural committee (led by Cisco, IBM, Rockwell Automation, and
others) published a seven-layer IoT architectural reference model. While various IoT
reference models exist, the one put forth by the IoT World Forum offers a clean, simplified
perspective on IoT and includes edge computing, data storage, and access. It provides a
succinct way of visualizing IoT from a technical perspective. Each of the seven layers is
broken down into specific functions, and security encompasses the entire model. Figure
belowdetails the IoT Reference Model published by the IoTWF.
Figure 2-2 IoTWF Standardized Architecture
As shown in Figure 2-2, the IoT Reference Model defines a set of levels with control flowing
from the center (this could be either a cloud service or a dedicated data center), to the edge,
which includes sensors, devices, machines, and other types of intelligent end nodes. In
general, data travels up the stack, originating from the edge, and goes northbound to the
center.
While the Internet Protocol is key for a successful Internet of Things, constrained nodes and
constrained networks mandate optimization at various layers and on multiple protocols of the
IP architecture. Some optimizations are already available from the market or under
development by the IETF. Figure 3.1 highlights the TCP/IP layers where optimization is
applied.
In the IP architecture, the transport of IP packets over any given Layer 1 (PHY) and
Layer 2 (MAC) protocol must be defined and documented. The model for packaging IP into
lower-layer protocols is often referred to as an adaptation layer.
An adaptation layer designed for IoT may include some optimizations to deal with
constrained nodes and networks. The main examples of adaptation layers optimized for
constrained nodes or “things” are the ones under the 6LoWPAN working group and its
successor, the 6Lo working group.
The initial focus of the 6LoWPAN working group was to optimize the transmission
of IPv6 packets over constrained networks such as IEEE 802.15.4. Figure 3.2 shows an
example of an IoT protocol stack using the 6LoWPAN adaptation layer beside the well-
known IP protocol stack for reference.
Figure 3.2: Comparison of an IoT Protocol Stack Utilizing 6LoWPAN and an IP Protocol
Stack
The 6LoWPAN working group published several RFCs, but RFC 4994 is
foundational because it defines frame headers for the capabilities of header compression,
fragmentation, and mesh addressing. These headers can be stacked in the adaptation layer to
keep these concepts separate while enforcing a structured method for expressing each
capability. Depending on the implementation, all, none, or any combination of these
capabilities and their corresponding headers can be enabled. Figure 3.3 shows some examples
of typical 6LoWPAN header stacks.
Header Compression
IPv6 header compression for 6LoWPAN was defined initially in RFC 4944 and
subsequently updated by RFC 6282. This capability shrinks the size of IPv6’s 40-byte
headers and User Datagram Protocol’s (UDP’s) 8-byte headers down as low as 6 bytes
combined in some cases. Note that header compression for 6LoWPAN is only defined for an
IPv6 header and not IPv4.
The 6LoWPAN protocol does not support IPv4, and, in fact, there is no standardized
IPv4 adaptation layer for IEEE 802.15.4. 6LoWPAN header compression is stateless, and
conceptually it is not too complicated. However, a number of factors affect the amount of
compression, such as implementation of RFC 4944 versus RFC 6922, whether UDP is
included, and various IPv6 addressing scenarios.
At a high level, 6LoWPAN works by taking advantage of shared information known by all
nodes from their participation in the local network. In addition, it omits some standard header
fields by assuming commonly used values. Figure 3.4 highlights an example that shows the
amount of reduction that is possible with 6LoWPAN header compression.
At the top of Figure 3.4, you see a 6LoWPAN frame without any header compression
enabled: The full 40- byte IPv6 header and 8-byte UDP header are visible. The 6LoWPAN
header is only a single byte in this case. Notice that uncompressed IPv6 and UDP headers
leave only 53 bytes of data payload out of the 127- byte maximum frame size in the case of
IEEE 802.15.4.
The bottom half of Figure 3.4 shows a frame where header compression has been
enabled for a best-case scenario. The 6LoWPAN header increases to 2 bytes to accommodate
the compressed IPv6 header, and UDP has been reduced in half, to 4 bytes from 8. Most
importantly, the header compression has allowed the payload to more than double, from 53
bytes to 108 bytes, which is obviously much more efficient. Note that the 2- byte header
compression applies to intra-cell communications, while communications external to the cell
may require some field of the header to not be compressed.
Fragmentation
The maximum transmission unit (MTU) for an IPv6 network must be at least 1280 bytes.
The term MTU defines the size of the largest protocol data unit that can be passed. For IEEE
802.15.4, 127 bytes is the MTU. This is a problem because IPv6, with a much larger MTU, is
carried inside the 802.15.4 frame with a much smaller one. To remedy this situation, large IPv6
packets must be fragmented across multiple 802.15.4 frames at Layer 2.
The fragment header utilized by 6LoWPAN is composed of three primary fields: Datagram
Size, Datagram Tag, and Datagram Offset. The 1-byte Datagram Size field specifies the
total size of the unfragmented payload. Datagram Tag identifies the set of fragments for a
payload. Finally, the Datagram Offset field delineates how far into a payload a particular
fragment occurs. Figure 3.5 provides an overview of a 6LoWPAN fragmentation header.
In Figure 3.5, the 6LoWPAN fragmentation header field itself uses a unique bit value
to identify that the subsequent fields behind it are fragment fields as opposed to another
capability, such as header compression. Also, in the first fragment, the Datagram Offset field
is not present because it would simply be set to 0. This results in the first fragmentation
header for an IPv6 payload being only 4 bytes long. The remainder of the fragments have a 5-
byte header field so that the appropriate offset can be specified.
Mesh Addressing
The purpose of the 6LoWPAN mesh addressing function is to forward packets over
multiple hops. Three fields are defined for this header: Hop Limit, Source Address, and
Destination Address. Analogous to the IPv6 hop limit field, the hop limit for mesh addressing
also provides an upper limit on how many times the frame can be forwarded. Each hop
decrements this value by 1 as it is forwarded. Once the value hits 0, it is dropped and no
longer forwarded.
The Source Address and Destination Address fields for mesh addressing are IEEE
802.15.4 addresses indicating the endpoints of an IP hop. Figure 3.6 details the 6LoWPAN
mesh addressing header fields.
Note that the mesh addressing header is used in a single IP subnet and is a Layer 2
type of routing known as mesh-under. RFC 4944 only provisions the function in this case as
the definition of Layer 2 mesh routing specifications was outside the scope of the 6LoWPAN
working group, and the IETF doesn’t define “Layer 2 routing.” An implementation
performing Layer 3 IP routing does not need to implement a mesh addressing header unless
required by a given technology profile.
Figure 3.7: Example of a High-Level IoT Protocol Stack for CoAP and MQTT
In Figure 3.7, CoAP and MQTT are naturally at the top of this sample IoT stack, based on an
IEEE 802.15.4 mesh network. While there are a few exceptions, you will almost always find
CoAP deployed over UDP and MQTT running over TCP. The following sections take a
deeper look at CoAP and MQTT.
The CoAP messaging model is primarily designed to facilitate the exchange of messages over
UDP between endpoints, including the secure transport protocol Datagram Transport Layer
Security (DTLS).
The CoAP message format is relatively simple and flexible. It allows CoAP to deliver low
overhead, which is critical for constrained networks, while also being easy to parse and
process for constrained devices.
CoAP can run over IPv4 or IPv6. However, it is recommended that the message fit
within a single IP packet and UDP payload to avoid fragmentation. For IPv6, with the default
MTU size being 1280 bytes and allowing for no fragmentation across nodes, the maximum
CoAP message size could be up to 1152 bytes, including 1024 bytes for the payload. In the
case of IPv4, as IP fragmentation may exist across the network, implementations should
limit themselves to more conservative values and set the IPv4 Don’t Fragment (DF) bit.
CoAP communications across an IoT infrastructure can take various paths.
Connections can be between devices located on the same or different constrained networks or
between devices and generic Internet or cloud servers, all operating over IP. Proxy
mechanisms are also defined, and RFC 7252 details a basic HTTP mapping for CoAP. As
both HTTP and CoAP are IP-based protocols, the proxy function can be located practically
anywhere in the network, not necessarily at the border between constrained and non-
constrained networks.
Just like HTTP, CoAP is based on the REST architecture, but with a “thing” acting as
both the client and the server. Through the exchange of asynchronous messages, a client
requests an action via a method code on a server resource. A uniform resource identifier
(URI) localized on the server identifies this resource. The server responds with a response
code that may include a resource representation. The CoAP request/response semantics
include the methods GET, POST, PUT, and DELETE.
At the end of the 1990s, engineers from IBM and Arcom (acquired in 2006 by
Eurotech) were looking for a reliable, lightweight, and cost-effective protocol to monitor and
control a large number of sensors and their data from a central server location, as typically
used by the oil and gas industries. Their research resulted in the development and
implementation of the Message Queuing Telemetry Transport (MQTT) protocol that is now
standardized by the Organization for the Advancement of Structured Information Standards
(OASIS).
An MQTT client can act as a publisher to send data (or resource information) to an
MQTT server acting as an MQTT message broker. In the example illustrated in Figure 3.10,
the MQTT client on the left side is a temperature (Temp) and relative humidity (RH) sensor
that publishes its Temp/RH data. The MQTT server (or message broker) accepts the network
connection along with application messages, such as Temp/RH data, from the publishers. It
also handles the subscription and unsubscription process and pushes the application data to
MQTT clients acting as subscribers.
The application on the right side of Figure 3.10 is an MQTT client that is a subscriber
to the Temp/RH data being generated by the publisher or sensor on the left. This model,
where subscribers express a desire to receive information from publishers, is well known. A
great example is the collaboration and social networking application Twitter.
With MQTT, clients can subscribe to all data (using a wildcard character) or specific
data from the information tree of a publisher. In addition, the presence of a message broker in
MQTT decouples the data transmission between clients acting as publishers and subscribers.
In fact, publishers and subscribers do not even know (or need to know) about each other. A
benefit of having this decoupling is that the MQTT message broker ensures that information
can be buffered and cached in case of network failures. This also means that publishers and
subscribers do not have to be online at the same time. MQTT control packets run over a TCP
transport using port 1883. TCP ensures an ordered, lossless stream of bytes between the
MQTT client and the MQTT server. Optionally, MQTT can be secured using TLS on port
8883, and WebSocket (defined in RFC 6455) can also be used.
MQTT is a lightweight protocol because each control packet consists of a 2-byte fixed
header with optional variable header fields and optional payload. You should note that a
control packet can contain a payload up to 256 MB. Figure 2.23 provides an overview of the
MQTT message format.
Compared to the CoAP message format, MQTT contains a smaller header of 2 bytes
compared to 4 bytes for CoAP. The first MQTT field in the header is Message Type, which
identifies the kind of MQTT packet within a message. Fourteen different types of control
packets are specified in MQTT version 3.1.1. Each of them has a unique value that is coded
into the Message Type field. Note that values 0 and 15 are reserved. MQTT message types
are summarized in Table 3.2
What is ThingSpeak
ThingSpeak is a platform providing various services exclusively targeted for building IoT
applications. It offers the capabilities of real-time data collection, visualizing the collected
data in the form of charts, ability to create plugins and apps for collaborating with web
services, social network and other APIs. We will consider each of these features in detail
below.
The core element of ThingSpeak is a ‘ThingSpeak Channel’. A channel stores the data
that we send to ThingSpeak and comprises of the below elements:
8 fields for storing data of any type - These can be used to store the data from a sensor
or froman embedded device.
3 location fields - Can be used to store the latitude, longitude and the elevation. These
are veryuseful for tracking a moving device.
1 status field - A short message to describe the data stored in the channel.
To use ThingSpeak, we need to signup and create a channel. Once we have a channel, we
can send the data, allow ThingSpeak to process it and also retrieve the same. Let us start
exploring ThingSpeak by signing up and setting up a channel.
Getting Started
Open https://thingspeak.com/ and click on the ‘Get Started Now’ button on the center of
the page and you will be redirected to the sign-up page(you will reach the same page
when you click the ‘Sign Up’ button on the extreme right). Fill out the required details
and click on the ‘Create Account’ button.
Now you should see a page with a confirmation that the account was successfully
created. The confirmation message disappears after a few seconds and the final page
should look as in the below screen:
Go ahead and click on ‘New Channel’. You should see a page like the below:
You can change the name to fit your need and you can add a description corresponding
to the channel. You can add any other useful description into the metadata field. In the
same page, you should see the fields for Latitude, Longitude and Elevation. Also, when
you scroll down you should see a check box that says ‘Make Public?’. Let us consider
the significance of the various fields and the tabs:
Once you have edited the fields, click on ‘Save Channel’ button. You should now see
a page likethe below in which the ‘Private View’ tab is defaulted:
The Private View shows a chart corresponding to each of the fields that we have added.
Now click on the ‘Public View’ tab. This should look exactly similar to the what we see
in the ‘Private View’ tab since our channel is public. In case your channel is not
public('make public' check box not checked in the ‘channel settings’ tab), the public
view tab shows a message that ‘This channel is not public’.
Now click on the ‘API Keys’ tab. You should see a screen similar to the below. The
write API key is used for sending data to the channel and the read API key(s) is used to
read the channel data.
When we create a channel, by default, a write API key is generated. We generate read
API keys by clicking the ‘Generate New Read API Key’ button under this tab.You can
also add a note corresponding to each of the read API keys.
Note: Please note that clicking on the ‘Generate New Write API Key’ will over-write
the previous key. You will only have one Write API key at any point of time. Also, in
case your channel is private, others can only view the channel’s feed and charts by
using a Read API key. Please share the Read API keys with people who are approved
and authorized to view your channel.
Now click on the ‘Data Import/Export’ tab and you should see a screen similar to the
below. This tab is used to import the ‘Comma Separated Values(CSV)’ data from a file
into the channel. You
can also download the channel’s feed from here in CSV format. This tab also outlines
how to send and view data by providing the URIs to the send and view APIs.
After a series of updates, the charts in the private view tab for each of the fields will
look like the below:
Each of the dots correspond to the value and the time at which the value was posted to
the channel. Place the mouse over a dot to get more details on the exact date and the
GMT offset from which the value was posted.
ThingSpeak Apps
ThingSpeak provides apps that allow us for an easier integration with the web services,
social networks and other APIs. Below are some of the apps provided by ThingSpeak:
ThingTweet - This allows you to post messages to twitter via ThingSpeak. In essence,
thisis a TwitterProxy which re-directs your posts to twitter.
ThingHTTP - This allows you to connect to web services and supports GET, PUT, POST
and DELETE methods of HTTP.
TweetControl - Using this, you can monitor your Twitter feeds for a specific key word
and then process the request. Once the specific keyword is found in the twitter feed, you
can then use ThingHTTP to connect to a different web service or execute a specific
action.
React - Send a tweet or trigger a ThingHTTP request when the Channel meets a certain
condition.
TalkBack - Use this app to queue up commands and then allow a device to act
uponthese queued commands.
Timecontrol - Using this app, we can do a ThingTweet, ThingHTTP or a TalkBack
at a specified time in the future. We can also use this to allow these actions to
happen at aspecified time throughout the week.