Unit - Iv
Unit - Iv
UNIT – IV
DATA LINK LAYER OF IOT
The IoT Data Link communication protocol provides service to the Network
Layer. There are various protocols and standard technologies specified by the
different organization for data link protocols.
Bluetooth
1. Bluetooth Classic
2. Bluetooth Low Energy
3. Bluetooth Smart Ready
It is wireless.
It is cheap.
It is easy to install.
It is free to use if the device is installed with it.
UNIT - IV 1
[INTERNET OF THINGS]
Z-Wave
UNIT - IV 2
[INTERNET OF THINGS]
ZigBee is a low power, low data rate wireless personal area network
communication protocol. It is mostly used in home automation and industrial
settings. Since ZigBee is a low power communication protocol, the IoT power
devices used with ZigBee technology. The ZigBee communication protocol is
based on the IEEE 802.15.4 standard operating at the 2.4GHz frequency. The
ZigBee protocol supports star, cluster or wireless mesh technology topology.
UNIT - IV 3
[INTERNET OF THINGS]
o Zigbee Coordinator
o Zigbee End Device
o Zigbee Router
Wireless
Mesh networking
Direct communication
Low power consumption
Costly
Works with low speed within a small distance
UNIT - IV 4
[INTERNET OF THINGS]
LoRaWAN
LoRaWAN refers to Long Rage Wide Area Network which is a wide area
network protocol. It is an optimized low-power consumption protocol design to
support large-scale public networks with millions of low-power devices. A single
operator operates the LoRaWAN. The LoRaWAN network is a bi-directional
communication for IoT application with low cost, mobility, and security.
Standard: LoRaWAN
Frequency: Various
Range: 2-5km (urban environment), 15km (suburban environment)
Data Rates: 0.3-50 kbps.
Wide coverage:
The radius of Wi-Fi can reach about 300 feet or about 100 meters, and additional
antennas or hotspots can be set up to expand the coverage area.
Network structure:
Compared to wired networks, wireless networks in its coverage area, its signal
will weaken with the increase of distance from the node, resulting in weaker
transmission speed, and wireless signals are easily obstructed by obscurants,
electromagnetic environment, and lightning weather, and wireless signals are
easily interfered by the same frequency radio waves.
Poor security:
Wi-Fi provides an encryption algorithm called WEP though, which encrypts the
data transmitted wirelessly between the network access point and the host
device to prevent illegal users from eavesdropping, attacking, and invading the
network.
Since Wi-Fi does not have the protection of the physical structure of the wired
network, and also unlike to access the wired network before you must first
connect to the network, if the network is not protected, as long as it is in the
signal coverage range, just through the wireless network card others can access
your network, occupy your bandwidth and cause your information leakage.
With the development and update of Wi-Fi technology, Wi-Fi is one of the most
important wireless communication technologies in IoT, from the first phase
driven by consumer-grade electronic terminals such as cell phones, tablets,
laptops, etc.
The second phase driven by IoT applications such as smart homes, smart cities,
smart manufacturing, Industry 4.0, and the third phase driven by a new
generation of high-speed rate applications such as virtual reality, ultra-high-
definition video applications driven, is focusing on penetrating IoT application
scenarios as the most widely used means of wireless networking.
UNIT - IV 7
[INTERNET OF THINGS]
distance, from the release of Bluetooth 1.0 in 1998 to now, has developed to
Bluetooth 5.0, in the data transmission speed, stability, security, exchange
protocol, power consumption performance and other aspects have been greatly
improved.
Transmission mode:
Peer-to-peer connection:
Small size: Bluetooth modules are small and easy to integrate, and are usually
embedded directly into mobile devices.
Bluetooth 5.0 theoretically can be in the distance range of about 100 meters
between the devices for short-distance connection, but the actual use of only
about 10 meters.
Poor anti-interference:
Because the Bluetooth transmission protocol and other 2.4G Bluetooth devices
are sharing this band of signals, it will lead to signal interference with each
other's situation.
UNIT - IV 8
[INTERNET OF THINGS]
It is an emerging technology in the field of IoT and the main standard for future
IoT construction, China is already in the scale commercialization stage.
It is also called Low Power Wide Area Network LPWA because it supports cellular
data connection of low-power devices in wide area networks.
Strong connectivity:
NB-IoT can provide 50-100 times more access than existing wireless
technologies. Supports low latency sensitivity, low device power consumption,
and optimized network architecture.
Wide coverage:
NB-IoT can cover indoors and basements, which can not only meet the network
coverage demand in remote places, but also long-distance communication up to
10KM or more, and is also applicable to application scenarios such as factory,
garage, and manhole cover which have requirements for deep coverage.
NB-IoT focuses on small data volume and small rate applications, so the power
consumption of NB-IoT devices can be very small, and the equipment endurance
UNIT - IV 9
[INTERNET OF THINGS]
working time can be significantly increased from a few months in the past to
several years.
Low cost:
NB-IoT does not need to re-build the network, and RF and antennas are basically
reused. Low rate, low power consumption, and low bandwidth also bring low-
cost advantages to NB-IoT chips and modules.
Many NB-IoT terminals are deployed in unsafe places such as outdoors, which
are easy to be stolen and controlled. When the terminal is out of control, it is
easy to cause leakage of user privacy and other information.
Difficult to upgrade:
The network and core network of NB-IoT access are open to a large number of
terminals, and the network layer is vulnerable to attacks from terminals and
wireless space, bringing the risk of invasion to the system.
Currently, NB-IoT has been widely used in smart homes, smart meters, smart
devices, smart cities, artificial intelligence, and other fields.
UNIT - IV 10
[INTERNET OF THINGS]
It can receive and process data from multiple nodes in parallel. In the same
power consumption conditions as other wireless communication methods to
spread farther distance, to achieve the unification of low power consumption
and long-distance, it is the same power consumption than the traditional
wireless radio frequency communication distance expanded 3-5 times.
The number of 10,000 nodes can be added, and the network deployment
topology layout can be designed and deployed according to specific applications
and scenarios to form networks by themselves at low cost.
In the case of applications with low communication frequency and small data
volume, the battery can be used for 1~5 years.
Low security:
The data transmission method is to send the field data to the base station first
and then back to the enterprise server, not to upload directly, and there is data
leakage in this process.
UNIT - IV 11
[INTERNET OF THINGS]
Poor latency:
The interference and blocking factors in the transmission path of WAN are not
controllable, and the link transmission has a delay, which easily leads to unstable
data reception.
Currently, smart meter reading, smart parking, vehicle tracking, smart factory,
smart agriculture, smart industry, smart city, smart community, and other fields
are applied.
With the rise of new wireless communication technologies such as big data,
cloud services, intelligent manufacturing, high-end equipment, in order to
comply with the development trend of information technology, digitalization,
intelligence, wireless communication technologies in commercial, civil, and
industrial fields will be more widely used, and the future will also be more
reliable, flexible, stable and lower construction costs.
UNIT - IV 12
[INTERNET OF THINGS]
UNIT - IV 13
[INTERNET OF THINGS]
1. USB Protocols
USB Stands For Universal Serial Bus. Hence, It Is A Serial Communication
Protocol For Connecting Devices With USB Ports Like Gaming Consoles, Mobile
Phones, Set-Top Box, Etc. It Also Provides A Fast Master-Slave Interface
Supporting Up To 127 Devices With Up To 6 Tires.
USB 1.X And 2.X Use Four Lines Ie. Vcc, Ground, D+ And D-. Data Is Though
Transferred In The Form Of Packets, Which Is Composed Of 8 Bits(1 Byte) With
LSB(Least Significant Bit) Transmitted First.
Pros: -
1. Simple And Fast.
2. Almost Acceptable Everywhere.
Cons: -
1. Requires Powerful Master-Slave Device.
2. Particular Drivers Are Required.
2. UART/USART Protocols
UART Stands For Universal Asynchronous Receiver Transmitter And USART Also
Means For Universal Synchronous Asynchronous Receiver Transmitter.
UART Converts Data Into Serial Data. Though, UARTs Communicate Directly By
Converting Data Into Serial Form And Transmits It Into The Receiving UART That
Converts Serial Data Into Parallel Data For The Receiving Device.
The Flow Of Data Is From The Tx Pin Of The Transmitting UART To The Rx Pin Of
The Receiving UART. Hence Only Two Wires Are Required. UART Is
Asynchronous And Hence Doesn’t Require A Clock For Synchronisation Whereas
USART Uses A Clock For Synchronisation In Case Of Synchronous
Communication. It Can Be Used In Asynchronous Communication Also. Hence,
It Is A Dual-Type Of Serial Communication.
UNIT - IV 14
[INTERNET OF THINGS]
Pros: -
1. No Clock Signal Required.
2. Only Requires Two Wires.
Cons: -
1. Data Frame Size Is Limited Only To A Maximum Of 9 Bits.
2. Multiple Master/Slaves Are Not Possible.
3. RS-232 Protocols
RS-232 Stands For Recommended Standard 232. Basically, It Is An Interface
Standard Commonly Used In Computer Serial Ports. It Also Defines The Electrical
Signals And Its Timings. However, It Serializes The Data To Be Transfer To The
Modem And Deserializes It Back While Receiving Back From The Modem.
Pros:-
1. Cheap And Also Easily Available.
2. Simple Connections And Easy To Code.
3. Commonly In Use.
Cons:-
1. Half Duplex Master/Slave Operation.
2. Less Standardized Connectors And Terminology Also.
4. RS-485 Protocols
It Is An Improved Version Of RS-232 Which Can Connect 10 To 32 Devices At The
Same Time And Defines Electrical Characteristics To Ensure Proper Signal
Voltages Under Maximum Load. The Good Noise Immunity And Multi-Drop
Ability Make It The Choice For Serial Connection In Industrial Applications With
Its Cable Length Up To 4000 Feet. However, Generally In Use For Computer And
Automation Systems.
Pros:-
1. Good Noise Immunity.
2. Multipoint Applications.
3. Though Cheap.
Cons:-
1. Half-Duplex Master-Slave Operation.
2. Less Standardized Connectors And Technology.
5. Ethernet
A System Connecting A Number Of Systems To Form A LAN (Local Area Network)
Having Protocols To Control The Data Transfer And Avoid Data Transmission By
UNIT - IV 15
[INTERNET OF THINGS]
Pros:–
1. The Network Starts And Ends With It.
2. Needs A Switch To Keep A Network.
3. Can Be In Use In A Building.
Cons:-
1. Can’t Be In Use For Long Distances As Fibre Should Be In Use.
2. It Includes Too Many Wires While Connecting It In A Building Which Is
Tough To Manage.
INTERNAL SYSTEMS
Internal System Protocols Are Use To Communicate Between Devices Within
The Same Circuit.
1. I2C Protocols
I2C Stands For Inter-Integrated Circuit Bus. It Is An Internal Communication
Protocol That Uses One Wire SCL (Serial Clock) For Clock And The Other Wire
SDA (Serial Data) For Transmission. It Can Connect Many Slave Devices To
Master Devices. Since Communication Is Half-Duplex, It Can Either Send Or
Receive Messages At A Time.
Pros:-
1. Multiple Devices Can Connect.
2. Interconnection Without Extra Wires.
Cons:-
1. Complicated Hardware.
2. Complicated Programming.
2. SPI Protocol
The SPI Stands For Serial Peripheral Interface Bus. It Is A Synchronous Serial
Communication Interface Which Is Generally In Use For Short-Distance
Communication. It Uses Four Wires I.E.
SCLK (Serial Clock).
MOSI (Master Output Slave Input).
MISO (Master Input Slave Output).
UNIT - IV 16
[INTERNET OF THINGS]
SS (Slave Select).
Here, The Communication Is Full-Duplex I.E. Devices Can Transmit And Receive
Data Simultaneously. First 3 Pins Have The Same Line From The Controller. Only
The SS Pin Controls Which Slave Device Is Active.
Pros: –
1. Faster.
2. The Receiver Can Be Also A Simple Shift Register.
3. Multiple Devices Can Connect.
Cons:-
1. Requires A Greater Number Of Wires Than Other Types Of
Protocols.
2. Slave Devices Can Not Communicate With Each Other. An Only
Master-Slave Can Communicate With Slaves.
3. So, Each Slave Requires Different SS Lines Which Causes Problems
If Many Slaves Have Connection
MANET NETWORKS:
A MANET consists of a number of mobile devices that come together
to form a network as needed, without any support from any existing
internet infrastructure or any other kind of fixed stations.
A MANET can be defined as an autonomous system of nodes or
MSs(also serving as routers) connected by wireless links, the union of
which forms a communication network modeled in the form of an
arbitrary communication graph.
This is in contrast to the well-known single hop cellular network model
that supports the needs of wireless communication between two
mobile nodes relies on the wired backbone and fixed base stations.
In a MANET, no such infrastructure exists and network topology may
be changed dynamically in an unpredictable manner since nodes are
free to move and each node has limiting transmitting power,
restricting access to the node only in the neighboring range.
MANETs are basically peer-to-peer, multi-hop wireless networks in
which information packets are transmitted in a store and forward
manner from a source to an arbitrary destination, via intermediate
nodes as given in the figure:
UNIT - IV 17
[INTERNET OF THINGS]
The other issue is varying the mobility patterns of different nodes. Some
other nodes are highly mobile, while others are primarily stationary. It is
difficult to predict a node's movement and direction of movement and
numerous studies have been performed to evaluate their performance using
different simulators.
UNIT - IV 18
[INTERNET OF THINGS]
Characteristics of MANET
Applications of MANET
UNIT - IV 19
[INTERNET OF THINGS]
RPL Protocol
RPL stands for Routing Protocol for Low-Power and Lossy Network. It is a
distance-vector protocol that supports a varity of Data Link Protocols. RPL builds
UNIT - IV 20
[INTERNET OF THINGS]
a Destination Oriented Directed Acyclic Graph (DODAG) which has only one
route from each leaf node to the root. All the traffic in this DODAG is routed
through the root. Initially, each node sends a DODAG Information Object (DIO)
announcing them self as a root. This information travels in the network, and
complete DODAG is gradually built. When a new node wants to join the network,
it sends a DODAG Information Solicitation (DIS) request and root responds back
with a DAO Acknowledgment (DAO-ACK) confirming the join.
CORPL Protocol
CARP Protocol
6LoWPAN
The 6LoWPAN protocol refers to IPv6 Low Power Personal Area Network which
uses a lightweight IP-based communication to travel over low data rate
networks. It has limited processing ability to transfer information wirelessly
using an internet protocol. So, it is mainly used for home and building
automation. The 6LoWPAN protocol operates only within the 2.4 GHz frequency
range with 250 kbps transfer rate. It has a maximum length of 128-bit header
packets.
UNIT - IV 21
[INTERNET OF THINGS]
Standard: RFC6282
Frequency: Used over a variety of other networking media including
Bluetooth Smart (2.4GHz) or ZigBee or low-power RF (sub-1GHz)
Range: NA
Data Rates: NA
Header compression
-Assuming the usage of common fields, the header compression compresses
the 40-byte and 8-byte UDP headers. Header fields are suppressed when they
can be derived from the link layer and the way that the header can be
compressed is one of the factors that led to the standard that only supporting
IPv6 and not IPv4.
UNIT - IV 22
[INTERNET OF THINGS]
Stateless autoconfiguration
-It is the process where the devices in the 6LoWPAN network automatically
generate their own IPv6 address. A method to avoid the two devices getting
the same address is called duplicate address detection (DAD)
The key concept of the 6LoWPAN adaptation layer is to use stateless or shared-
context compression to compressed header fields. This can compress all
headers (adaptation, network, and transport layers) down to a few bytes.
Header fields are possible to compress since they often carry common values.
Common values always occur due to frequent use of a subset of IPv6
functionality, namely UDP, TCP, and ICMP. The 6LoWPAN adaptation layer
removes duplicate information that can be derived from other layers such as
the IPv6 addresses and UDP/IPv6 length fields.
As you can see from the above technical explanation, you will notice 6LoWPAN
exists and does provide a much more practical approach to local personal area
network (PAN) device exchange of data, in particular for the model world
where Internet of Things (IoT) devices keep rising. We are now in the world full
of IoT sensors, whether it is your smartphone you wear all the time, to
smartTag you bind with your physical keys, to smart home or smart office
devices, all are IoT devices.
Routing Classification
1. Proactive Protocol
2. Reactive Protocol
3. Hybrid Protocol
1. Proactive Protocol
UNIT - IV 24
[INTERNET OF THINGS]
already and can be immediately used. The family of distance vector protocols is
an example of proactive scheme.
2. Reactive Protocols
3. Hybrid Protocols
UNIT - IV 25
[INTERNET OF THINGS]
demand but at a limited search cost. One of the popular hybrid protocols is zone
routing protocol (ZRP).
1. Table-driven protocols
2. Source initiated on -demand protocols
UNIT - IV 26
[INTERNET OF THINGS]
For example the routing table of Node A from the above network is:
A A 0 A46 001000
B B 1 B36 001200
C B 2 C28 001500
Basically the table stores description of all possible paths reachable by node A,
along with the hop, number of hops, sequence number and install time.
Advantages
UNIT - IV 27
[INTERNET OF THINGS]
Disadvantage
The cluster head (CH) gateway switch routing (CGSR) protocol is different
from the destination sequenced distance vector routing in the type of
addressing and the network organization scheme employed.
Instead of a flat network, CGSR uses cluster heads, which control a group
of ad hoc nodes and hence achieve a hierarchical framework for code
separation among clusters, routing, channel access, and bandwidth
allocation.
Identification of appropriate clusters and selection of cluster heads is
quite complex. Once clusters have been defined, it is desirable to use a
distributed algorithm within the cluster to elect a node as the cluster
head.
The disadvantage of using a cluster head scheme is that frequent changes
adversely affect performance as nodes spend more time selecting a
cluster head rather than relaying packets. Hence, the least cluster change
(LCC) clustering algorithm is used rather than CH selection every time the
cluster membership changes. Using LCC, CHs change only when two CHs
come into contact, or when a node moves out of contact with all other
CHs.
UNIT - IV 28
[INTERNET OF THINGS]
In this scheme, each node must maintain a cluster member table (CMT),
which stores the destination CH for each node in the network. The cluster
member tables are broadcast periodically by the nodes using the DSDV
algorithm.
When a node receives such a table from a neighbor, it can update its own
information. As expected, each node also maintains a routing table to
determine the next hop required to reach any destination.
The wireless routing protocol is a proactive unicast routing protocol for MANETs.
It uses an enhanced version of the distance vector routing protocol, which uses
the Bellman - Ford algorithm to calculate paths.
For the wireless routing protocol (WRP) each node maintains 4 tables:
Distance table
Routing table
Link cost table
Message retransmission list (MRL) table
Each entry in the message retransmission list has a sequence number of the
update message, a retransmission counter, an acknowledgment required flag
vector with one entry per neighbor, and a list of updates sent in the update
message. When any node receives a hello message from a new node, it adds the
new node to its routing table and sends the new node a copy of its routing table.
A node must send a message to its neighbors within a certain time to ensure
connectivity.
Advantages
Disadvantage
UNIT - IV 29
[INTERNET OF THINGS]
o Since it suffers from limited scalability therefore WRP is not suitable for
highly dynamic and for a very large ad hoc wireless network.
UNIT - IV 30
[INTERNET OF THINGS]
The above figure illustrates the propagation of the broadcast request (RREQs)
across the network. Since in DSDV, destination sequence numbers are used to
ensure that all routes are loop free and contain the most recent route
information. Each node has a unique sequence number and a broadcast ID,
which is incremented each time the node, initiates RREQ.
The broadcast ID, together with the IP address of node, uniquely identifies every
RREQ.
Intermediate mobile reply only if they have a route to the destination with a
sequence number greater than or at least equal to that contained in the RREQ.
To optimize the route performance, intermediate nodes record the address.
From the above figure, since RREP (route reply packet) travels back on the
reverse path, the nodes on this path set up their forward route entries to point
to the node from which RREP had just been received. These forward route
records indicate the active forward route. The RREP continues traveling back
along the reverse path till it reaches the initiator of the route discovery. Thus,
AODV can support only the use of symmetric links.
UNIT - IV 31
[INTERNET OF THINGS]
UNIT - IV 32
[INTERNET OF THINGS]
CoAP Architecture
The WWW and the constraints ecosystem are the 2 foundational elements of
the CoAP protocol architecture. Here, the server monitors and helps in
communication happening using CoAP and HTTP while proxy devices bridge the
existing gap for these 2 ecosystems, making the communication smoother.
CoAP allows HTTP clients (also called CoAP clients here) to talk or exchange
data/information with each other within resource constraints.
While one tries to understand this architecture, gaining acquaintances with
some key terms is crucial:
UNIT - IV 33
[INTERNET OF THINGS]
CoAP Function
The key role of CoAP is to act like HTTP wherever restricted devices are a part of
communication. While filling the gap of HTTP, it enables devices like actuators
and sensors to interact over the internet.
The devices, involved in the process, are administered and controlled by
considering data as a system’s component. CoAP protocol can operate its
functions in an environment having reduced bandwidth and extreme congestion
as it consumes reduced power and network bandwidth.
Networks featuring intense congestion and constrained connectivity are not
ideal conditions for TCP-based protocols to carry out their responsibilities. CoAP
comes as a rescuer at this place and supports the wen transfers.
UNIT - IV 34
[INTERNET OF THINGS]
Web transfers happening using satellites and covering long distances can be
accomplished with full perfection using CoAP. Networks featuring billions of
nodes take the help of the CoAP protocol for information exchange.
Regardless of the function handled or role played, CoAP promised security of
highest grade as DTLS parameters as default security parameter; the
counterpart of 128-bit RSA keys.
Speaking of its deployment, it’s simple and hassle-free. It can be implemented
from scratch for a straightforward application.
For the application ecosystem where CoAP is not desirable, generic
implementations are offered for various platforms. Most of the CoAP
implementations are done privately while few are published in open-source
libraries like MIT license.
CoAP Features
The defining features that place CoAP protocol separate from other protocols
are as stated next. As it shares great similarities with HTTP, developers face bare
minimum difficulties while using it.
CoAP is an integration-friendly protocol and can be paired easily with
applications using cross-protocol proxies. Seamlessly, it integrates with JSON,
XML, CBOR, and various other data formats. In the process, the web client
doesn’t get hints about a sensor resource being accessed.
Developers are endowed with various payloads and have the freedom to make
a choice to bring the ideal payload into action.
The successful IoT device/application demands the usage of billions of nodes at
a time. CoAP is designed to handle such huge mode amounts with full perfection
while keeping the overheads under control. It can operate on tons of
microcontrollers while using the least possible resources. RAM space as low as
10KiB and code space as 100 KiB is enough for CoAP.
As resources demanded by CoAP are on the minimum side, it keeps the wastes
under control. There is no need to deploy a hefty transport stack for web
transfers. The header and encoding, used for message processing, are compact
and don’t cause any fragments on the link layer. At a time, it supports the
functions of multiple servers.
UNIT - IV 35
[INTERNET OF THINGS]
CoAP Layer
The protocol works through its two layers:
This layer takes care of CON and NON message requests. Acceptance of these
requests depend on server’s availability. Cases are:
1. If idle, the server will handle the request right away. If a CON, the client
will get an ACK for it. If the ACK is shared as a Token and differs from the
ID, it is essential to map it properly by matching request-response pairs.
2. If there is a delay or wait involved, the ACK is sent but as an empty text.
When its turn arrvies, the request is processed andthe client gets a fresh
CON.
Request or response codes for CoAP are same as for the HTTP, except for
the fact that they are in the binary format (0-8 byte Tokens) in CoAP’s
case.
Request methods for making calls (GET, PUT, POST, and DELETE) are
declared in the process.
UNIT - IV 36
[INTERNET OF THINGS]
CoAP vs MQTT
As there are great similarities, we won’t blame you if you consider these two
identical. For instance, they both are used for IoT devices as they both
necessitate less amounts of network packets causing more power-optimized
performance, less storage consumption, and longer battery power.
CoAP and MQTT are distinct from each other on various fronts:
CoAP vs MQTT
MQTT CoAP
UNIT - IV 37
[INTERNET OF THINGS]
UNIT - IV 38
[INTERNET OF THINGS]
Characteristics of MQTT
The MQTT has some unique features which are hardly found in other protocols.
Some of the features of an MQTT are given below:
History of MQTT
, and Arlen Nipper. The previous versions of protocol 3.1 and 3.1.1 were made
available under MQTT ORG. In 2014, the MQTT was officially published by OASIS.
The OASIS becomes a new home for the development of the MQTT. Then, the
OASIS started the further development of the MQTT. Version 3.1.1 is backward
comfortable with a 3.1 and brought only minor changes such as changes to the
connect message and clarification of the 3.1 version. The recent version of MQTT
is 5.0, which is a successor of the 3.1.1 version. Version 5.0 is not backward,
UNIT - IV 39
[INTERNET OF THINGS]
comfortable like version 3.1.1. According to the specifications, version 5.0 has a
significant number of features that make the code in place.
MQTT Architecture
Message
Client
Server or Broker
TOPIC
Message
The message is the data that is carried out by the protocol across the network
for the application. When the message is transmitted over the network, then
the message contains the following parameters:
1. Payload data
2. Quality of Service (QoS)
3. Collection of Properties
4. Topic Name
Client
In MQTT, the subscriber and publisher are the two roles of a client. The clients
subscribe to the topics to publish and receive messages. In simple words, we can
say that if any program or device uses an MQTT, then that device is referred to
as a client. A device is a client if it opens the network connection to the server,
publishes messages that other clients want to see, subscribes to the messages
that it is interested in receiving, unsubscribes to the messages that it is not
interested in receiving, and closes the network connection to the server.
UNIT - IV 40
[INTERNET OF THINGS]
Publish: When the client sends the data to the server, then we call this
operation as a publish.
Subscribe: When the client receives the data from the server, then we call
this operation a subscription.
Server
The device or a program that allows the client to publish the messages and
subscribe to the messages. A server accepts the network connection from the
client, accepts the messages from the client, processes the subscribe and
unsubscribe requests, forwards the application messages to the client, and
closes the network connection from the client.
TOPIC
The label provided to the message is checked against the subscription known by
the server is known as TOPIC.
Architecture of MQTT
UNIT - IV 41
[INTERNET OF THINGS]
The MQTT uses the command and the command acknowledgment format,
which means that each command has an associated acknowledgment. As shown
in the above figure that the connect command has connect acknowledgment,
subscribe command has subscribe acknowledgment, and publish command has
publish acknowledgment. This mechanism is similar to the handshaking
mechanism as in TCP protocol.
Now we will look at the packet structure or message format of the MQTT.
UNIT - IV 42
[INTERNET OF THINGS]
The MQTT message format consists of 2 bytes fixed header, which is present in
all the MQTT packets. The second field is a variable header, which is not always
present. The third field is a payload, which is also not always present. The
payload field basically contains the data which is being sent. We might think that
the payload is a compulsory field, but it does not happen. Some commands do
not use the payload field, for example, disconnect message.
Fixed Header
As we can observe in the above format that the fixed header contains two bytes.
The first byte contains the following fields:
The byte 2 contains the remaining length, which is a variable-length byte integer.
It represents the number of bytes remaining in a current control packet,
including data in the variable header and payload. Therefore, we can say that
the remaining length is equal to the sum of the data in the variable header and
the payload.
UNIT - IV 43
[INTERNET OF THINGS]
The above table shows the control packet types with 4-bit value and direction
flow. As we can observe that every command is followed by acknowledgment
like CONNECT has CONNACK, PUBLISH has PUBACK, PUBREC, PUBREL, and
PUBCOMP, SUBSCRIBE has SUBACK, UNSUBSCRIBE has UNSUBACK.
UNIT - IV 44
[INTERNET OF THINGS]
Flag Bit
The above table shows the flag value associated with each command. Here,
reserved refers to future use, which means that it is not being used right now.
In the case of PUBLISH command, flag bits are further divided into DUP, QoS,
and RETAIN, where DUP is a duplicate delivery of a PUBLISH packet, QoS is
Quality of Service, and RETAIN is retained message flag.
Remaining length
For example, if the length of the variable header is 20 and the length of the
payload is 30, then the remaining length is 50.
The remaining length can be used upto 4 bytes, and it starts from 2 bytes and
can be used upto 4 bytes.
This field uses 7-bit for the lengths, and MSB bit can be used to continue a flag.
If the continuation flag is 1, the next byte is also a part of the
UNIT - IV 45
[INTERNET OF THINGS]
remaining length. If the continuation flag is 0, a byte is the last one of the
remaining length.
Variable header
Some types of MQTT control packet types contain an optional field also, i.e.,
variable header component. This field resides between the fixed header and the
payload. The content of the variable header depends upon the packet type. The
variable header contains the packet identifier field, which is common in several
packet types. The variable header component of many MQTT control packet
types includes 2-byte integer, i.e., the packet identifier field.
PUBLISH
PUBACK
PUBREC
PUBREL
PUBCOMP
SUBSCRIBE
SUBACK
UNSUBSCRIBE
UNSUBACK
o A PUBLISH packet should not contain the packet identifier field if the value
of QoS (Quality of Service) is set to zero. It implies that if the value of QoS
is greater than zero, only the PUBLISH packet will contain the packet
identifier field.
o When a client sends a new SUBSCRIBE, UNSUBSCRIBE, or PUBLISH MQTT
control packet, it should assign a non-zero packet identifier that is
currently unused.
o When a server sends a new PUBLISH MQTT control packet, it should assign
a non-zero packet identifier that is currently unused.
o A PUBACK, PUBREC, PUBUREL, PUBREC are the acknowledgment packets
of PUBLISH command that contain the same packet identifier as the
PUBLISH packet.
UNIT - IV 46
[INTERNET OF THINGS]
Payload
In the ICMP message format, the last MQTT control packet is the payload. This
field contains the data which is to be sent. For example, in the case of the
CONNECT packet, the payload is a client ID, the username and password, and
the PUBLISH packet, the payload is just an application message.
UNIT - IV 47
[INTERNET OF THINGS]
UNIT - IV 48
[INTERNET OF THINGS]
DNS Service Discovery (DNS-SD) – This protocol stack uses standard DNS
messages to discover services in an IOT network. Based on mDNS, DNS-SD is
used to resolve services available in a network. The service discovery is
implemented in two steps – in the first step, host names of the service providers
are resolved and in the next step, IP addresses are paired with the host names
using mDNS. It is important to identify host names as IP addresses can change
in the network.
Like in mDNS, the IP address and host name of the target device is
communicated as a multicast response and each node (connected IOT device in
the network) updates the host name and related IP address on receiving the
response. It is the protocol which keeps the host names constant in the network
despite the devices or nodes have dynamic IP addresses. As the host name
always remain constant in the network, it is possible to identify the devices
uniquely and reliably within the local IOT network. Like mDNS, this protocol
stack does not require any additional infrastructure (DNS Name Server in the
network) or manual configuration or administration of connected IOT devices.
uPnP – Maintained by Open Connectivity Foundation, Universal Plug and Play
(uPnP) is a protocol stack that allows devices in a network to discover each other
and each other’s capabilities along with setting up network functions like data
sharing and communication.
There are three building blocks of any uPnP network – devices, services and
control points. The devices are the basic blocks of the network where each
device provides specific service or services. The services are seen as set of
actions which can be implemented by the device. The control points identify
devices by device and service descriptions and respond to client node by
invoking requested services. In this protocol, the discovery of devices and
services happen automatically and autonomously once a node enters the
network. So, there remains no need to manually configure nodes (IOT devices)
to discover available devices and service in the network.
This protocol is based on TCP-IP routing. The devices are identified by their
Universal Resource Indicators (URIs) and the services are discovered using
Hypertext Transfer Protocol (HTTP). A device connected to network
automatically configures itself by acquiring a TCP-IP address and indicating
available services by it using HTTP. The devices then use XML to communicate
with each other and indicate each other’s capabilities (services to offer).
UNIT - IV 49
[INTERNET OF THINGS]
UNIT - IV 50
[INTERNET OF THINGS]
UNIT - IV 51