UNIT IV
IOT COMMUNICATION AND OPEN PLATFORMS
Communication Models in IoT (Internet of Things)
The Internet of Things (IoT) is a network of connected devices that can communicate
with each other, share data, and perform tasks without human intervention. The
importance of communication in IoT cannot be overstated, as it is the foundation on
which the entire system is built. The devices that make up the IoT ecosystem need to
be able to communicate with each other in order to function properly and achieve their
intended purpose.
Effective communication in IoT enables devices to share data, receive instructions, and
respond to requests in a timely and accurate manner. This is critical for the successful
implementation of IoT solutions across various industries, such as healthcare,
manufacturing, transportation, and smart homes.
For example, in a smart home, the communication between the devices (such as lights,
thermostats, and security systems) allows them to work together to create a more
convenient and secure living environment for the occupants. Similarly, in a healthcare
setting, IoT devices can be used to monitor patients remotely and alert healthcare
providers in case of an emergency, ensuring that timely medical intervention is
provided.
Types of Communication Models in IoT
There are several communication models that can be used in the Internet of Things
(IoT) ecosystem, depending on the requirements of the use case. The three main
communication models used in IoT are −
Client-Server Model
In the Client-Server communication model, the client sends encoded requests to the
server for information as needed. This model is stateless, meaning that each request is
handled independently and data is not retained between requests. The server
categorizes the request, retrieves the data from the database or resource representation,
and converts it to an encoded response that is sent back to the client. The client then
receives the response.
On the other hand, in the Request-Response communication model, the client sends a
request to the server and the server responds to the request by deciding how to retrieve
1
the data or resources needed to prepare the response. Once prepared, the server sends
the response back to the client.
Publish-Subscribe Model
The Publish-Subscribe communication model consists of three entities: Publishers,
Brokers, and Consumers.
Publishers are responsible for generating and sending data to specific topics managed
by the broker. Publishers are not aware of the consumers subscribed to the topic.
Consumers subscribe to the topics managed by the broker to receive data from the
publishers. The broker is responsible for sending the data to the appropriate consumers
based on their subscription to specific topics.
The broker is responsible for accepting data from the publishers and forwarding it to
the appropriate consumers subscribed to that specific topic. The broker is the only
entity that has information regarding the consumer to which a particular topic belongs,
and publishers are not aware of this information.
Push-Pull Model
The Push-Pull communication model consists of three entities: data publishers, data
consumers, and data queues. Publishers and consumers are not aware of each other.
Publishers push messages or data into the queue, and consumers on the other end pull
data out of the queue. The queue acts as a buffer for messages when there is a difference
in the rate of data push or pull by the publisher and consumer.
Queues play an essential role in decoupling messaging between the producer and
consumer, and they act as a buffer in situations where there is a mismatch in the rate at
which data is pushed by producers and pulled by consumers. This buffer helps ensure
smooth communication between the two entities.
Exclusive Pair Model
Exclusive Pairs are communication models that provide full-duplex, bidirectional
communication between a client and server. These models are designed for constant or
continuous connections between the two entities.
Once a connection is established, both the client and server can exchange messages
with each other. As long as the client does not request to close the connection, it
remains open, and the server is aware of every open connection. This enables the client
and server to communicate seamlessly and in real-time.
2
Future of IoT Communication Models
The future of IoT communication models is exciting and promising. As the number of
connected devices and applications continue to increase, the need for efficient and
effective communication models will become even more critical.
One of the most significant trends in IoT communication models is the shift towards
edge computing. This approach involves processing data closer to the source, rather
than transmitting it to a centralized cloud server. By moving processing closer to the
edge of the network, latency can be reduced, and real-time responses can be achieved.
This approach also reduces the amount of data that needs to be transmitted, reducing
bandwidth requirements and improving efficiency.
Another trend is the development of hybrid communication models that combine
different communication protocols to achieve the best possible results. For example, a
hybrid model might combine the Publish-Subscribe model with the Request-Response
model to achieve real-time data updates while still allowing for targeted data requests.
Conclusion
Finally, there is a growing focus on security and privacy in IoT communication models.
As the number of connected devices continues to grow, the risk of security breaches
and data theft also increases. Communication models that prioritize security and
privacy will become increasingly important in the future to ensure the safe and secure
exchange of data.
IoT Communication APIs (Application Programming Interfaces)
The Internet of Things (IoT) has changed how we interact with devices and created
new opportunities for businesses to gather and analyze data. However, this has created
a demand for device−to−device communication that is seamless. This is where IoT
Communications APIs come to play a major role in communication systems.
IoT Communications APIs are a set of protocols and interfaces that allow IoT devices
and platforms to communicate with one another. These APIs enable developers to
create apps that interface with IoT devices over conventional web protocols including
HTTP, MQTT, CoAP, and others.
Internet of Things Communications APIs standardizes how IoT devices communicate
with one another and with other systems. They enable developers to design applications
3
and services that can access and operate IoT devices without worrying about
underlying communication protocols and interfaces.
So, let's go over some of the most crucial advantages of Communications APIs.
Benefits of Communication APIs in IoT
There are multiple benefits to adopting Internet of Things Communications APIs. One
of the primary benefits is that they give a standardized method of connecting with IoT
devices, making it simpler for developers to construct apps and services that work with
many types of devices. This can save developers a lot of time and effort because they
don't have to establish specific communication protocols for each device with which
they want to interact.
Another benefit of adopting Communications APIs is that they might make the
development process easier. Developers can utilize high−level APIs that abstract away
the specifics of communication protocols and interfaces instead of writing low−level
code to handle communication with IoT devices. This can assist minimize the amount
of code required and make it easier to construct reliable and scalable systems.
IoT Communications APIs can also aid in the enhancement of security. APIs may
ensure that devices communicate securely and that data is encrypted and secured from
unauthorized access by offering a standardized communication method with IoT
devices. This can aid in the prevention of data breaches and other security issues.
Internet of Things Communications APIs are also built to be extremely scalable. As
more devices are added to an IoT system, the APIs can handle the increasing traffic
while also ensuring that device communication stays reliable and consistent.
Another advantage of adopting communications APIs is that they make the building of
IoT applications easier. Developers can utilize pre−built APIs to connect their apps to
IoT devices and platforms, saving time and reducing development complexity.
Types of Communication APIs in IoT
There are numerous IoT communications APIs accessible, each with its own set of
advantages and disadvantages. Among the most popular APIs are:
REST APIs
REST APIs are a popular choice for IoT communications because they offer a
straightforward and scalable method of exposing IoT device capabilities over
4
the web. REST APIs can be used to access and alter IoT data and devices,
allowing developers to create novel IoT−powered apps.
Internet of Things communications APIs that use REST APIs follow the same
concepts as normal REST APIs but with an emphasis on IoT−specific resources
and capabilities. An IoT Communications API, for example, may provide
resources such as sensors, actuators, or data streams.
WebSocket
WebSocket is a protocol that provides for bidirectional, real−time
communication between a client and a server. WebSocket is frequently used in
the context of IoT Communications APIs to provide low−latency, real−time data
streaming between IoT devices and cloud services.
WebSocket, unlike HTTP, is a persistent connection between the client and
server, allowing for real−time communication without the need for constant
polling. This makes it perfect for Internet of Things (IoT) applications requiring
real−time data updates, such as monitoring and control systems.
CoAP
Constrained Application Protocol (CoAP) is a protocol used in Communications
APIs for resource−constrained devices and networks. It is a simple protocol for
exposing and manipulating IoT device resources via the internet.
CoAP is a low−overhead protocol with tiny message sizes and minimum header
information. As a result, it is well suited for use in IoT devices with low
processing power and memory. CoAP is also intended to function with restricted
networks, such as those based on the IEEE 802.15.4 or 6LoWPAN standards.
MQTT
MQTT (Message Queuing Telemetry Transport) is a lightweight messaging
protocol used in IoT Communications APIs to link devices to the cloud. MQTT
was created to be efficient, dependable, and simple to use, making it an excellent
choice for IoT applications.
MQTT is a publish or subscribe messaging model that allows devices to submit
messages to particular topics and receive messages from topics to which they
are subscribed.
In addition to these APIs, there are IoT Communications Platforms that offer a
complete end to−end IoT communication solution. These platforms often feature
pre−built APIs, data visualization dashboards, and other tools that make the
development process more manageable.
AWS IoT, Azure IoT, and Google Cloud IoT are some popular IoT
Communications Platforms.
Conclusion
5
Finally, IoT Communications APIs are critical for developing large−scale IoT systems
that can gather and analyze data from a variety of devices. These APIs enable device
interoperability, ease development, and are meant to be extremely scalable. As the
Internet of Things grows and evolves, we can expect additional breakthroughs in IoT
Communications APIs, making it easier than ever to construct sophisticated IoT
applications.
IoT Communication Protocols
– Bluetooth – WiFi – ZigBee – GPS – GSM modules
Machine-to-Machine(M2M) refers to networking of machines (or device) for the
purpose of remote monitoring and control and exchange data. M2M communication is
often used for remote monitoring. In product restocking, for example, a vending
machine can message the distributor when a particular item is running low.M2M
communication is an important aspect of warehouse management, remote control,
robotics, traffic control, logistic services, supply chain management, fleet management
and telemedicine.
Bluetooth
Bluetooth is used for short-range wireless voice and data communication. It is a
Wireless Personal Area Network (WPAN) technology and is used for data
communications over smaller distances. It operates within the unlicensed, business,
scientific, and clinical (ISM) bands from 2.4 GHz to 2.485 GHz. Bluetooth stages up
to 10 meters. Depending upon the version, it presents information up to at least 1 Mbps
or 3 Mbps. The spreading method that it uses is FHSS (Frequency-hopping unfold
spectrum). A Bluetooth network is called a piconet and a group of interconnected
piconets is called a scatternet.
Key Features of Bluetooth
The transmission capacity of Bluetooth is 720 kbps.
Bluetooth is a wireless device.
Bluetooth is a Low-cost and short-distance radio communications standard.
Bluetooth is robust and flexible.
The basic architecture unit of Bluetooth is a piconet.
Architecture of Bluetooth
The architecture of Bluetooth defines two types of networks:
Piconet: Piconet is a type of Bluetooth network that contains one primary node called
the master node and seven active secondary nodes called slave nodes. Thus, we can
say that there is a total of 8 active nodes which are present at a distance of 10 meters.
The communication between the primary and secondary nodes can be one-to-one or
one-to-many. Possible communication is only between the master and slave; Slave-
slave communication is not possible. It also has 255 parked nodes, these are
6
secondary nodes and cannot take participation in communication unless it gets
converted to the active state.
Scatternet: It is formed by using various piconets. A slave that is present in one
piconet can act as master or we can say primary in another piconet. This kind of
node can receive a message from a master in one piconet and deliver the message to
its slave in the other piconet where it is acting as a master. This type of node is
referred to as a bridge node. A station cannot be mastered in two piconets.
Advantages of Bluetooth
It is a low-cost and easy-to-use device.
It can also penetrate through walls.
It creates an Ad-hoc connection immediately without any wires.
It is used for voice and data transfer.
Disadvantages of Bluetooth
It can be hacked and hence, less secure.
It has a slow data transfer rate of 3 Mbps.
Bluetooth communication does not support routing.
Applications of Bluetooth
It can be used in wireless headsets, wireless PANs, and LANs.
It can connect a digital camera wireless to a mobile phone.
It can transfer data in terms of videos, songs, photographs, or files from one cell
phone to another cell phone or computer.
It is used in the sectors of Medical healthcare, sports and fitness, Military.
How does Zigbee protocol work?
Devices using Zigbee protocol can transmit data over long distances by passing data
through a mesh network of intermediate devices to reach more distant ones. Zigbee is
typically used in low data rate applications that require long battery life and secure
networking. (Zigbee networks are secured by 128 bit symmetric encryption keys.)
7
Zigbee Architecture and various features of Zigbee.
Zigbee Architecture
Zigbee system structure consists of three different types of devices as Zigbee
Coordinator, Router, and End device. Every Zigbee network must consist of at least
one coordinator which acts as a root and bridge of the network. The coordinator is
responsible for handling and storing the information while performing receiving and
transmitting data operations. Zigbee routers act as intermediary devices that permit
data to pass to and fro through them to other devices. End devices have limited
functionality to communicate with the parent nodes such that the battery power is saved
as shown in the figure. The number of routers, coordinators, and end devices depends
on the type of networks such as star, tree, and mesh networks. Zigbee protocol
architecture consists of a stack of various layers where IEEE 802.15.4 is defined by
physical and MAC layers while this protocol is completed by accumulating Zigbee’s
own network and application layers.
ZigBee Architecture
The synchronization header for this frame is composed of the Preamble and the
Start of Frame Delimiter fields. The Preamble field is a 32-bit 4-byte (for parallel
construction) pattern that identifies the start of the frame and is used to
synchronize the data transmission. The Start of Frame Delimiter field informs the
receiver that frame contents start immediately after this byte.
8
The PHY Header portion of the PHY frame shown in Figure 2.3 is simply a frame
length value. It lets the receiver know how much total data to expect in the PHY service
data unit (PSDU) portion of the 802.4.15 PHY. The PSDU is the data field or payload.
MAC Layer The IEEE 802.15.4 MAC layer manages access to the PHY channel by
defining how devices in the same area will share the frequencies allocated. At this layer,
the scheduling and routing of data frames are also coordinated. The 802.15.4 MAC
layer performs the following tasks: Network beaconing for devices acting as
coordinators (New devices use beacons to join an 802.15.4 network) PAN association
and disassociation by a device Device security Reliable link communications
between two peer MAC entities The MAC layer achieves these tasks by using various
predefined frame types. In fact, four types of MAC frames are specified in 802.15.4:
Data frame: Handles all transfers of data Beacon frame: Used in the transmission of
beacons from a PAN coordinator Acknowledgement frame: Confirms the successful
reception of a frame MAC command frame: Responsible for control communication
between devices.
The MAC Header field is composed of the Frame Control, Sequence Number and the
Addressing fields. The Frame Control field defines attributes such as frame type,
addressing modes, and other control flags. The Sequence Number field indicates the
sequence identifier for the frame. The Addressing field specifies the Source and
Destination PAN Identifier fields as well as the Source and Destination Address fields.
The MAC Payload field varies by individual frame type. For example, beacon frames
have specific fields and payloads related to beacons, while MAC command frames
have different fields present. The MAC Footer field is nothing more than a frame check
sequence (FCS). An FCS is a calculation based on the data in the frame that is used by
the receiving side to confirm the integrity of the data in the frame. IEEE 802.15.4
requires all devices to support a unique 64-bit extended MAC address, based on EUI-
64. However, because the maximum payload is 127 bytes, 802.15.4 also defines how
a 16-bit “short address” is assigned to devices. This short address is local to the PAN
and substantially reduces the frame overhead compared to a 64-bit extended MAC
9
address. However, you should be aware that the use of this short address might be
limited to specific upper-layer protocol stacks.
List some applications of Zigbee.
ZigBee applications include:
i) Home and office automation ii) Industrial automation iii) Medical
monitoring iv) Low-power sensors v) HVAC control Plus many other control
and monitoring uses
GPS stands for Global Positioning System and used to detect the Latitude and
Longitude of any location on the Earth, with exact UTC time (Universal Time
Coordinated). This device receives the coordinates from the satellite for each and
every second, with time and date. GPS offers great accuracy and also provides other
data besides position coordinates which we can use later on.
GSM is a mobile communication modem; it stands for *Global System for Mobile
Communication (GSM). It was created to describe the protocols for second-
generation (2G) digital cellular networks used by mobile phones and is now the
default global standard for mobile communications. We will use this in order to send
the coordinates that we can receive from the GPS Module to the third party whom
will receive the message.
using the GSM 800l Module because just like the GPS Module it's small. We will use
a micro sim on this, and take note that the sim must have load.
Step 1: Connecting GSM and GPS Module to the Arduino
10
GSM Module to Arduino
TX connected to pin 11
RX connected to pin 10
5V from the module to 5V of Arduino
two Grounds from the module to the Ground to Arduino
GPS Module to Arduino
Vcc connected to 5V of Arduino
RX from the module to the TX of Arduino (pin 1)
TX from the module to the RX of Arduino (pin 2)
GND to GND
Step 2: Software Connection
Connect the USB Cable to a PC or Laptop
What is GSM?
The term GSM is an acronym for Global Systems for Mobile. It is a type of
cellular standard for communication over mobile phones. It caters to data
delivery and mobile services by making use of digital modulation wherever
SMS has an effect on society. GSM is basically the standard-bearer of 2G
technology. It is a circuit-switched type of network in which the billing
depends a lot on the duration of the established connection.
GSM does not establish a direct connection with the internet. One of the most
popular features of GSM is Short Messaging Service (SMS). We can use GSM
in almost all countries, and a large set of users get to experience its services.
What is GPRS?
The term GPRS is an acronym for General Packet Radio Service. It is basically
an up-gradation of the features of GSM (over the basic features). It allows a
user to obtain a much better speed of data and provides them with simple and
wireless access to the packet data networks as compared to the standard GSM
technology.
GPRS is basically the standard-bearer of 2.5G technology. It is a packet-
switched type of network in which the billing depends on the total data
transferred (amount of data). It lets its users develop a direct connection over
the internet. One of the most popular services of the GPRS system is the
Multimedia Messaging Service (MMS). Not all the countries get the GPRS
services because it is only confined to the developed areas that happen to
have proper network connections.
11
Parameters GSM GPRS
Full-Form The term GSM is an acronym The term GPRS is an acronym
for Global Systems for Mobile. for General Packet Radio
Service.
Basics The GSM is a type of cellular The GPRS is basically an up-
standard for communication gradation of the features of GSM
over mobile phones. It caters to (over the basic features). It
data delivery and mobile allows a user to obtain a much
services by making use of better speed of data and provides
digital modulation wherever them with simple and wireless
SMS has an effect on society. access to the packet data
networks as compared to the
standard GSM technology.
System GSM is basically the standard- GPRS is basically the standard-
Generation bearer of 2G technology. bearer of 2.5G technology.
Frequency The GSM system majorly The GPRS system majorly
Bands makes use of the 1800 and 900 makes use of 1900, 1800, 900,
MHz (Megahertz) frequency and 750 MHz frequency bands.
bands.
Type of The GSM is a circuit-switched The GPRS is a packet-switched
Connection type of network. type of network.
Available The GSM technology provides The GPRS technology provides
Data Rates a data rate of about 9.6 kbps a data rate of about 14.4 kbps to
(kilobytes per second) for all of 115.2 (kilobytes per second) for
its users. all of its users.
12
Billing The billing in GSM depends on The billing in GPRS depends
the total duration of the entirely on the total data amount
established connection. that we transferred during the
connection.
Direct The GSM technology does not The GPRS technology allows all
Internet allow any direct connection of its users to establish a direct
Connection with the internet. internet connection.
Based It works on the basis of the It works on the basis of the
System system TDMA (Time-division system GSM.
multiple access).
Individual The GSM technology allots a The GPRS technology is capable
Time Slots single time slot for every single of allotting multiple time slots to
user. every single user.
Time Taken The GSM technology takes The GPRS technology provides
for comparatively much longer to its users with a comparatively
Connection connect. much faster connection.
Area The GSM technology makes The GPRS technology makes
Concept use of the location area use of the routing area concept.
concept.
Popular One of the most popular One of the most popular services
Features features of GSM is Short of the GPRS system is the
Messaging Service (SMS). Multimedia Messaging Service
(MMS).
Open Platform (like Raspberry Pi) – Architecture –
13
Architecture of Raspberry Pi
Raspberry Pi is a small single-board computer (SBC). It is a credit card-sized computer
that can be plugged into a monitor. It acts as a minicomputer by connecting the keyboard,
mouse, and display. Raspberry Pi has an ARM processor and 512MB of RAM. The
architecture of Raspberry Pi is given below.
Raspberry Pi mainly consists of the following blocks
Processor: Raspberry Pi uses Broadcom BCM2835 system on chip which is an ARM
processor and Video core Graphics Processing Unit (GPU). It is the heart of the
Raspberry Pi which controls the operations of all the connected devices and handles all
the required computations.
HDMI: High Definition Multimedia Interface is used for transmitting video or digital
audio data to a computer monitor or to digital TV. This HDMI port helps Raspberry Pi
to connect its signals to any digital device such as a monitor digital TV or display
through an HDMI cable.
GPIO ports: General Purpose Input Output ports are available on Raspberry Pi which
allows the user to interface various I/P devices.
Audio output: An audio connector is available for connecting audio output devices
such as headphones and speakers.
USB ports: This is a common port available for various peripherals such as a mouse,
keyboard, or any other I/P device. With the help of a USB port, the system can be
expanded by connecting more peripherals.
SD card: The SD card slot is available on Raspberry Pi. An SD card with an operating
system installed is required for booting the device.
Ethernet: The ethernet connector allows access to the wired network, it is available
only on the model B of Raspberry Pi.
Power supply: A micro USB power connector is available onto which a 5V power
supply can be connected.
Camera module: Camera Serial Interface (CSI) connects the Broadcom processor to
the Pi camera.
Display: Display Serial Interface (DSI) is used for connecting LCD to Raspberry Pi
using 15 15-pin ribbon cables. DSI provides a high-resolution display interface that is
specifically used for sending video data.
Programming – Interfacing – Accessing GPIO Pins – Sending and Receiving
Signals Using GPIO Pins – Connecting to the Cloud
Program to Flash an LED
14
import RPi.GPIO as GPIO
import time
pin = 21 # The pin connected to the LED
iterations = 10 # The number of times to blink
interval = .25 # The length of time to blink on or off
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(pin, GPIO.OUT)
# The parameters to "range" are inclusive and exclusive, respectively,
# so to go from 1 to 10 we have to use 1 and 11 (add 1 to the max)
for x in range(1, iterations+1):
print "Loop %d: LED on" % (x)
GPIO.output(pin, GPIO.HIGH)
time. sleep(interval)
print "Loop %d: LED off" % (x)
GPIO.output(pin, GPIO.LOW)
time. sleep(interval)
TEMPERATURE MEASUREMENT
import spidev
import time
import RPi.GPIO as GPIO
#BCM GPIO reference
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
buzzer = 21
GPIO.setup(buzzer, GPIO.OUT)
# Open SPI bus
spi = spidev.SpiDev()
spi.open(0,0)
# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
15
def ReadChannel(channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data
# Define sensor channels
temp_channel = 0
while True:
# Read the temperature sensor data
temp_level = ReadChannel(temp_channel)
percent = (temp_level * 3.3) / 1024
temp = percent / (10.0 / 1000)
T = int(temp)
print "Temp: %d deg C"%(T)
time.sleep(1)
if T > 20:
print "Temp: %d deg C"%(T)
GPIO.output(buzzer, 1)
time.sleep(1)
else:
print "Temp: %d deg C"%(T)
GPIO.output(buzzer, 0)
16