Chapter 2(Iot)
Chapter 2(Iot)
1. “Things”: Things in IoT are any devices that are capable of connecting to the internet. They can transmit,
retrieve and store huge amounts of data that they collect from the surrounding. They include home
appliances such as geysers, microwaves, thermostats and refrigerators
2. Data Acquisition module: As the term suggests, this module is responsible for acquiring data from the
physical surroundings or environment. These could include changes in the temperature, movement,
humidity and pressure.
3. Data processing module: This module includes computers that process the data acquired from the
previous module. They analyze the data, store data for future references and other purposes.
4. Communication module: This is the final building block and this module is responsible for
communication with third party vendors. This could include device to device, device to server or device to
user.
The computing component is the decision-making center of the IoT device. It receives data from sensors, processes it
according to programmed logic, and sends instructions to actuators or communication modules.
Reliable and efficient communication is vital for IoT devices to interact within a network and with the cloud.
The accuracy, sensitivity, and reliability of sensors are critical for the quality of data collected by IoT devices.
Actuators enable IoT devices to interact with their surroundings and perform physical actions.
The I/O interfaces are the pathways through which the computing component interacts with the rest of the hardware.
This more detailed explanation should provide a stronger foundation for understanding the hardware building blocks of
IoT systems. Remember that the specific components chosen for an IoT device are driven by the requirements of its
intended application.
Arduino is centered around microcontroller boards. These boards are designed to be easy to use for a wide range of
projects, especially those involving direct interaction with electronics.
The Raspberry Pi is a more powerful and versatile platform. It's essentially a small, single-board computer capable of
running a full operating system.
Side-by-Side Comparison:
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 discussed in this article.
The following diagram shows the architecture of Raspberry Pi:
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.
What is Arduino?
Arduino is an open-source, cross-platform, very simple hardware and software environment intended for
interactive projects. It could be an electronic board having a microcontroller—a computer in one chip—
besides a development environment within which one writes, compiles, and ultimately downloads code onto
the microcontroller. The Arduino boards were designed to make simple engagements with an electronic
system easy for both supporters and audiences: beginners, enthusiasts, and learners.
Advantages of Arduino
User Friendly: Arduino IDE is so user-friendly that even a complete beginner finds it very easy to
learn.
Above all: Open-source, Arduino has an enormous community providing a huge number of
tutorials, libraries, and other resources.
variety of shields: There exist a variety of shields that can give extended capabilities to an Arduino
for wireless, motor control, and even Internet connectivity.
Economical: Arduino boards are much cheaper in price than most other microcontrollers or
development boards.
Platform Independent: The Arduino Software runs on Windows, Mac OS X and Linux.
Disadvantages of Arduino
Limited Computational Power: The processing and memory resources of the Arduino boards are
actually quite limited, so they cannot be used for higher operations, such as an operating system
workable through intensive computation.
Absence of Multitasking: Arduino boards are fundamentally designed for single-task execution,
signifying their inability to manage several tasks concurrently.
Connectivity is limited: While shields can absolutely extend the connective selection, the basic
model of an Arduino does have its features lacking, such as Wi-Fi and Ethernet.
Control unit of the Arduino is from the The control unit of Raspberry Pi is from the
2.
At mega family. ARM family.
Arduino boards have a simple hardware While Raspberry Pi boards have a complex
5.
and software structure. architecture of hardware and software.
7. It uses very little RAM, 2 kB. While Raspberry Pi requires more RAM, 1 GB.
11. It consumes about 200 MW of power. While it consumes about 700 MW of power.
13. It does not have internet support. It has inbuilt Ethernet port and WiFi support.
14. It has higher current drive strength. It has lower current drive strength.
Some of the applications of Arduino are Some of the applications of Raspberry Pi are
15. traffic light countdown timer , Weighing Stop motion cameras , Robot Controllers ,
machines , etc. Game Servers.
17. Two tiny cores Arduino with 32 MHz Single core and 700 MHz
Bluetooth (BLE) Short (~10-100m) Low Moderate Wearables, smart home devices
Example:
o LM35 Temperature Sensor → Analog pin on Arduino.
o LDR (Light Dependent Resistor) → Measures light intensity.
(2) Digital Input (GPIO - General Purpose Input/Output)
Reads binary signals (HIGH/LOW, 1/0).
Example:
o PIR Motion Sensor → Detects movement (Digital Pin).
o Push Button → Simple ON/OFF input.
(3) Communication Protocols for Sensors
UART (Universal Asynchronous Simple serial communication (TX, GPS Module, Bluetooth
Receiver-Transmitter) RX). Module
Example:
o LED Control → digitalWrite(PIN, HIGH) in Arduino.
o Relay Module → Controls high-voltage appliances.
(2) PWM (Pulse Width Modulation)
Controls speed, brightness, or power by varying pulse width.
Example:
o DC Motor Speed Control → analogWrite(PIN, dutyCycle).
o LED Dimming → Adjust brightness.
(3) DAC (Digital-to-Analog Converter)
Converts digital signals to analog (e.g., audio output).
Example:
Audio Output → Used in IoT-based music players.
IoT Data Communication Protocols
WebSocket
Linked to the HTTP protocol, the WebSocket technology
establishes a TCP connection between a browser and a
server, and then both of them exchange information until the
connection is closed. Figure 3 shows a high-level
comparison between HTTP and WebSocket.
Although this protocol can be seen as an improvement of
the HTTP connection, the WebSocket is still very
overloaded and heavy for IoT applications.
HTTP (Hypertext Transfer Protocol) is a fundamental protocol of the Internet, enabling the
transfer of data between a client and a server. It is the foundation of data communication for
the World Wide Web.
HTTP provides a standard between a web browser and a web server to establish
communication. It is a set of rules for transferring data from one computer to another. Data
such as text, images, and other multimedia files are shared on the World Wide Web.
Whenever a web user opens their web browser, the user indirectly uses HTTP. It is an
application protocol that is used for distributed, collaborative, hypermedia information systems.
Constrained Application Protocol (CoAP)
CoAP is a web transfer protocol to be used with limited networks with low bandwidth and low availability. It
follows a client/server architecture and is built similarly to HTTP, supporting the REST model: servers make
resources available with an URL, and clients can make requests of types GET, POST, PUT and DELETE.
The CoAP communication links are 1:1 and UDP-based, so the delivery is not guaranteed. CoAP is made
to work in highly congested networks, where nodes do not have a lot of intelligence and are not always
working.
Data Distribution Service (DDS)
MQTT (Message Queuing Telemetry Transport) is an OASIS standard messaging protocol for the
Internet of Things (IoT). It is designed with an extremely lightweight publish/subscribe messaging model,
making it ideal for connecting IoT devices with a small code footprint and minimal network bandwidth and
exchanging data in real-time between connected devices and cloud services.
MQTT can not only be used as a gateway to access communication on the device side, but also as a
Device-Cloud Communication Protocol. Most gateway protocols such as ZigBee and LoRa can be
converted into MQTT Protocol to connect to the Cloud.
A use case of MQTT is in a smart factory where there are temperature sensors installed along
with the production plant. The installed sensors will connect to the MQTT broker and will publish
the data within sensor topics, as follows:
Afterward, the MQTT clients, which can be of several types and quantities, will subscribe to the
same topic in order to read the temperature data. An example of an MQTT architecture can be
seen in Figure 1.
Lightweight and Reliable: MQTT messages are compact, enabling stable transmission on
severely constrained hardware devices and networks with low bandwidth and high latency.
Publish/Subscribe Model: Based on the publish/subscribe model, its advantage lies in decoupling
publishers and subscribers - they don't need to establish a direct connection or be online
simultaneously.
Designed for IoT: Provides comprehensive IoT application features such as keep alive
mechanism, will message, QoS, topic, and security management.
More Complete Ecosystem: It covers client and SDK platforms in all languages, and has mature
Broker server software, supporting a vast number of topics, millions of device connections, and rich
enterprise integration capabilities.
Key Concepts:
Publish/Subscribe (Pub/Sub): Unlike the request/response model, MQTT uses a pub/sub architecture. Devices
(clients) don't communicate directly with each other. Instead, they interact with a central broker.
o Publishers: Devices that send out data or messages on specific topics.
o Subscribers: Devices that express interest in (subscribe to) specific topics and receive messages
published to those topics.
o Broker: The intermediary server that receives messages from publishers and routes them to interested
subscribers.
Topics: Messages are published to and subscribed from hierarchical strings called topics (e.g., home/temperature,
sensor/humidity/room1). The broker uses these topics to filter and route messages.
Quality of Service (QoS): MQTT defines three levels of QoS for message delivery:
o QoS 0 (At most once): Messages are delivered with no guarantee of delivery. Best effort, fire and
forget.
o QoS 1 (At least once): Messages are guaranteed to be delivered at least once, but may be delivered
multiple times. Requires acknowledgment.
o QoS 2 (Exactly once): Messages are guaranteed to be delivered exactly once. This is the most reliable
but also the most overhead-intensive level.
Lightweight: MQTT has a small message overhead, making it efficient for low-bandwidth networks.
Stateful Connections: Clients maintain persistent connections with the broker, reducing connection overhead
for frequent communication.
Last Will and Testament (LWT): A client can register an LWT message with the broker. If the client
disconnects unexpectedly, the broker will publish this LWT message on a specified topic, alerting other
subscribers to the client's offline status.
Retained Messages: Publishers can mark messages as "retained." The broker stores the last retained message
for a topic and delivers it to new subscribers when they subscribe to that topic.
Smart Homes: Sending sensor readings (temperature, light), controlling actuators (lights, locks).
Industrial IoT (IIoT): Monitoring machine status, collecting telemetry data from industrial equipment.
Agriculture: Tracking environmental conditions in fields, controlling irrigation systems.
Logistics and Transportation: Tracking vehicle locations, monitoring cargo conditions.
Messaging and Notifications: Lightweight messaging between devices or to user interfaces.
Advantages:
Requires a central broker, which can be a single point of failure if not properly managed.
Not ideal for request/response interactions where an immediate response is needed.
6. CoAP
CoAP: The RESTful Protocol for Constrained Environments
CoAP is a specialized web transfer protocol designed for constrained nodes and constrained networks, often referred
to as the "HTTP of the IoT." It aims to bring the familiar REST (Representational State Transfer) architecture of the
web to resource-limited devices.
IoT devices have limited resources like CPU, RAM, Flash, and network bandwidth. Direct data exchange
using TCP and HTTP is unrealistic. CoAP protocol emerged to solve this problem and enable these devices
to connect to the network smoothly.
CoAP incorporates HTTP design ideas and develops practical functions specific to resource-limited
devices.
Key Concepts:
o RESTful Architecture: CoAP follows the REST principles, using concepts like resources identified by
URIs (Uniform Resource Identifiers) and standard methods (GET, POST, PUT, DELETE) to interact
with these resources.
o Request/Response Model: Unlike MQTT's pub/sub, CoAP operates on a request/response model
between clients and servers.
o Lightweight: CoAP minimizes overhead by using a compact binary message format (based on UDP by
default).
o Stateless Protocol: Like HTTP, CoAP is generally stateless, meaning each request from a client to a
server contains all the information needed to understand the request.
o Methods: CoAP defines methods analogous to HTTP:
GET: Retrieve a representation of a resource.
POST: Request the server to accept the entity enclosed in the request as a new subordinate of
the resource identified by the Request-URI.
PUT: Request 1 the server to update or create the resource identified by the Request-URI with
the enclosed entity.
DELETE: Request the server to delete the resource identified by the Request-URI.
o Responses: Servers respond to requests with status codes similar to HTTP (e.g., 2.00 OK, 4.04 Not
Found).
o Observations: CoAP supports a mechanism for clients to "observe" resources on a server. The server
will then send notifications (similar to pub/sub) to the client whenever the state of the observed resource
changes.
o
Security: CoAP can be secured using DTLS (Datagram Transport Layer Security) when running over
UDP.
o Proxying and Bridging: CoAP can be easily bridged to HTTP, allowing constrained devices to interact
with the wider web.
Typical Use Cases:
o Smart Lighting: Controlling light intensity and color using GET, PUT.
o Smart Sensors: Retrieving sensor readings using GET, observing changes.
o Actuator Control: Triggering actions using POST or PUT.
o Building Automation: Managing HVAC systems, security devices.
o Resource Discovery: Finding available resources on constrained devices.
Advantages:
o RESTful architecture: Familiar to web developers, promotes interoperability.
o Lightweight and efficient: Designed for constrained environments.
o Request/response model: Suitable for interactions where an immediate response is needed.
o Support for resource discovery and observation.
o Can be secured with DTLS.
o Easy bridging to HTTP.
Disadvantages:
o Stateless nature might add overhead for applications requiring session management.
o Reliance on UDP (by default) can mean less reliable delivery without implementing application-level
mechanisms or using TCP as a transport.
Introduction of ZigBee
ZigBee is a Personal Area Network task group with low rate task group 4. It is a technology of home
networking. ZigBee is a technological standard created for controlling and sensing the network. As we know
that ZigBee is the Personal Area Network of task group 4 so it is based on IEEE 802.15.4 and is created by
Zigbee Alliance.
ZigBee is an open, global, packet-based protocol designed to provide an easy-to-use architecture for
secure, reliable, low power wireless networks. Flow or process control equipment can be place anywhere
and still communicate with the rest of the system. It can also be moved, since the network doesn’t care
about the physical location of a sensor, pump or valve.
ZigBee is a standard that addresses the need for very low-cost implementation of Low power devices with
Low data rates for short-range wireless communications.
IEEE 802.15.4 supports star and peer-to-peer topologies. The ZigBee specification supports star and two
kinds of peer-to-peer topologies, mesh and cluster tree. ZigBee-compliant devices are sometimes specified
as supporting point-to-point and point-to-multipoint topologies
Types of ZigBee Devices:
Zigbee Coordinator Device: It communicates with routers. This device is used for connecting the
devices.
Zigbee Router: It is used for passing the data between devices.
Zigbee End Device: It is the device that is going to be controlled.
Key Concepts:
o Mesh Networking: One of ZigBee's defining features is its ability to form mesh networks. In a mesh
network, devices can communicate directly with each other or through intermediary devices. This
provides several advantages:
Extended Range: Devices that are out of range of a central coordinator can still communicate by
hopping through other devices in the network.
Redundancy and Reliability: If one communication path fails, data can be routed through
alternative paths, making the network more resilient.
Self-Healing: The network can automatically reconfigure itself if a device fails or a connection is
lost.
o Low Power Consumption: ZigBee is designed to minimize power usage, allowing devices to operate for
extended periods on batteries. This is achieved through efficient protocols and low duty cycles.
o Low Data Rate: ZigBee is optimized for transmitting small amounts of data intermittently, which is
typical for many sensor and control applications.
o Personal Area Network (PAN): ZigBee networks are often referred to as Personal Area Networks
(PANs).
o Network Topologies: ZigBee supports different network topologies:
Star: All devices communicate directly with a central coordinator.
Tree: A hierarchical network structure with a coordinator and routers.
Mesh: Allows for peer-to-peer communication and multiple paths between devices.
o Coordinator, Router, and End Device: ZigBee networks typically have three types of nodes:
Coordinator: Manages the network, initiates its formation, and stores information about the
network. There is typically only one coordinator per network.
Router: Extends the network range and can route data between other devices. Routers are
always mains-powered.
End Device: Typically battery-powered devices that communicate with a router or the
coordinator. They can sleep for extended periods to conserve power.
o Security: ZigBee incorporates strong security features, including AES-128 encryption, to protect
communication within the network.
Typical Use Cases:
o Smart Homes: Controlling lighting, thermostats, door locks, and other home automation devices. Its
mesh capabilities make it ideal for covering larger homes.
o Industrial Automation: Monitoring sensors, controlling machinery, and asset tracking in industrial
environments.
o Smart Buildings: Managing lighting, HVAC, and security systems in commercial buildings.
o Healthcare: Monitoring patient vital signs and tracking medical equipment.
o Agriculture: Deploying wireless sensor networks for environmental monitoring and control.
Advantages:
o Low power consumption: Enables long battery life for devices.
o Robust and reliable: Mesh networking provides redundancy and self-healing capabilities.
o Secure communication: Uses AES-128 encryption.
o Scalable: Can support a large number of devices in a network.
o Relatively low cost: ZigBee modules are generally cost-effective.
o Standardized protocol: Ensures interoperability between devices from different manufacturers (to a
certain extent, depending on profiles).
Disadvantages:
o Low data rate: Not suitable for applications requiring high bandwidth (e.g., video streaming).
o Shorter range compared to some other technologies (like Wi-Fi), although the mesh topology helps
extend the effective range.
o Complexity: Setting up and managing a large mesh network can be more complex than simpler point-
to-point or star networks.
o Interoperability challenges: While a standard exists, different "profiles" (like ZigBee Home Automation,
ZigBee Light Link, ZigBee 3.0) can sometimes lead to interoperability issues between devices adhering
to different profiles. ZigBee 3.0 aims to unify these profiles.
Architecture of Zigbee:
Physical layer: The lowest two layers i.e the physical and the MAC (Medium Access Control) Layer
are defined by the IEEE 802.15.4 specifications. The Physical layer is closest to the hardware and
directly controls and communicates with the Zigbee radio. The physical layer translates the data
packets in the over-the-air bits for transmission and vice-versa during the reception.
Medium Access Control layer (MAC layer): The layer is responsible for the interface between the
physical and network layer. The MAC layer is also responsible for providing PAN ID and also
network discovery through beacon requests.
Network layer: This layer acts as an interface between the MAC layer and the application layer. It is
responsible for mesh networking.
Application layer: The application layer in the Zigbee stack is the highest protocol layer and it
consists of the application support sub-layer and Zigbee device object. It contains manufacturer-
defined applications.
.
Key Characteristics:
o Connection-Oriented: Before any data is exchanged, a connection is established between the sender
and the receiver through a process called a "three-way handshake." This ensures that both sides are
ready to communicate.
o Reliable Delivery: TCP guarantees that all data sent will arrive at the destination correctly and in the
same order it was sent. It achieves this through:
Sequence Numbers: Each segment of data is assigned a sequence number, allowing the
receiver to reassemble the data in the correct order.
Acknowledgments (ACKs): The receiver sends acknowledgments back to the sender to confirm
that it has received data segments.
Retransmission: If the sender doesn't receive an acknowledgment within a certain timeout
period, it retransmits the lost data segment.
Error Detection: TCP uses checksums to detect errors in the data during transmission.
Corrupted packets are discarded and retransmitted.
o Ordered Delivery: Due to sequence numbers, even if packets arrive out of order, TCP ensures that the
application at the receiving end receives the data in the correct sequence.
o Flow Control: TCP manages the rate of data transmission to prevent the sender from overwhelming the
receiver. It uses mechanisms like sliding windows to control the amount of data sent before an
acknowledgment is required.
o Congestion Control: TCP also implements mechanisms to detect and respond to network congestion,
reducing the transmission rate to avoid further overloading the network.
o Higher Overhead: Due to the mechanisms for reliability, ordering, and flow control, TCP has a higher
overhead compared to UDP. Each TCP segment includes header information for sequence numbers,
acknowledgments, etc.
TCP (Transmission Control Protocol) is one of the main protocols of the Internet protocol suite. It lies between the
Application and Network Layers which are used in providing reliable delivery services. It is a connection-oriented
protocol for communications that helps in the exchange of messages between different
devices over a network. The Internet Protocol (IP), which
establishes the technique for sending data packets
between computers, works with TCP.
Applications of TCP
World Wide Web (WWW) : When you browse websites, TCP ensures reliable data transfer
between your browser and web servers.
Email : TCP is used for sending and receiving emails. Protocols like SMTP (Simple Mail Transfer
Protocol) handle email delivery across servers.
File Transfer Protocol (FTP) : FTP relies on TCP to transfer large files securely. Whether you’re
uploading or downloading files, TCP ensures data integrity.
Secure Shell (SSH) : SSH sessions, commonly used for remote administration, rely on TCP for
encrypted communication between client and server.
Streaming Media : Services like Netflix, YouTube, and Spotify use TCP to stream videos and
music. It ensures smooth playback by managing data segments and retransmissions.
• Web Browsing/HTTP Communication: When an IoT device needs to interact with web
services or APIs using HTTP/HTTPS.
• Secure Data Transfer: Applications requiring guaranteed delivery and integrity of data, such
as firmware updates or critical control commands.
• File Transfer: Sending larger files or datasets from IoT devices to servers.
• Remote Access and Control: Establishing reliable connections for remote management of IoT
devices.
• Email Protocols (SMTP, POP3, IMAP): If an IoT device needs to send or receive emails.
Advantages of TCP
o Reliable data delivery: Guarantees that data will arrive correctly and in order.
o Ordered data delivery: Ensures the receiving application processes data in the intended sequence.
o Flow and congestion control: Helps to manage network resources and prevent data loss.
o Well-established and widely supported.online video chas
User Datagram Protocol (UDP) is a Transport Layer protocol. UDP is a part of the Internet Protocol suite,
referred to as the UDP/IP suite. Unlike TCP, it is an unreliable and connectionless protocol. So, there is no
need to establish a connection before data transfer. The UDP helps to establish low-latency and loss-
tolerating connections establish over the network. The UDP enables process-to-process communication.
Key Characteristics:
o Connectionless: No connection is established before data transmission begins. The sender simply
sends packets (called datagrams) to the receiver without any prior handshake.
o Unreliable Delivery: UDP provides no guarantee that data will reach the destination. Packets may be
lost, duplicated, or arrive out of order. There are no acknowledgments or retransmissions at the UDP
level.
o Unordered Delivery: If multiple UDP packets are sent, they may arrive at the destination in a different
order than they were sent.
o Minimal Overhead: UDP has a very small header, resulting in minimal overhead and efficient use of
bandwidth.
o Faster Transmission: The lack of connection establishment, acknowledgments, and retransmissions
makes UDP faster than TCP.
Typical Use Cases in IoT:
o Real-time Data Streaming: Applications where timely delivery is more important than guaranteed
delivery, such as streaming sensor data (e.g., environmental readings, telemetry) where occasional
packet loss is acceptable.
o Online Gaming: Where low latency is crucial, and occasional dropped packets are less detrimental than
delays caused by retransmissions.
o Voice over IP (VoIP) and Video Conferencing: Similar to online gaming, real-time delivery is key.
o DNS (Domain Name System): The initial lookups for website IP addresses often use UDP due to its
speed.
o Simple Network Management Protocol (SNMP): Used for managing network devices.
o Broadcasting and Multicasting: Sending data to multiple recipients simultaneously.
Real-Time Multimedia Streaming : UDP is ideal for streaming audio and video content. Its low-
latency nature ensures smooth playback, even if occasional data loss occurs.
Online Gaming : Many online games rely on UDP for fast communication between players.
DNS (Domain Name System) Queries : When your device looks up domain names (like converting
“www.example.com” to an IP address), UDP handles these requests efficiently .
Network Monitoring : Tools that monitor network performance often use UDP for lightweight, rapid
data exchange.
Multicasting : UDP supports packet switching, making it suitable for multicasting scenarios where
data needs to be sent to multiple recipients simultaneously.
Routing Update Protocols : Some routing protocols, like RIP (Routing Information Protocol), utilize
UDP for exchanging routing information among routers.
Advantages of UDP
The choice between TCP and UDP in an IoT application depends on the specific requirements:
We can not have any way to acknowledge the successful transfer of data.
UDP cannot have the mechanism to track the sequence of data.
UDP is connectionless, and due to this, it is unreliable to transfer data.
In case of a Collision, UDP packets are dropped by Routers in comparison to TCP.
UDP can drop packets in case of detection of errors.
Where TCP is Used?
Sending Emails
Transferring Files
Web Browsing
Where UDP is Used?
Gaming
Video Streaming
==============================
Differences between TCP and UDP
TCP has a (20-60) bytes variable length UDP has an 8 bytes fixed-length
Header Length
header. header.
Weight TCP is heavy-weight. UDP is lightweight.
Handshaking Uses handshakes such as SYN, ACK, SYN- It’s a connectionless protocol i.e.
Techniques ACK No handshake
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 scatter net.
Bluetooth is a wireless technology that lets devices like phones, tablets, and headphones connect to each
other and share information without needing cables. Bluetooth simply follows the principle of transmitting
and receiving data using radio waves. It can be paired with the other device which has also Bluetooth but it
should be within the estimated communication range to connect. When two devices start to share data,
they form a network called piconet which can further accommodate more than five devices.
Key Features of Bluetooth
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.
Bluetooth in IoT: Short-Range Connectivity
Bluetooth technology enables devices to communicate wirelessly over short distances (typically up to 10-
100 meters, depending on the class and version). Its low power consumption, relatively low cost, and
widespread availability make it a popular choice for many IoT use cases.
these Programming APIs and Communication Protocols are key Software Components in building IoT
solutions. They bridge the gap between the physical hardware and the applications that make the IoT system
intelligent and useful. Let's recap how they fit into the broader IoT software landscape:
Here's a broader view of typical IoT software components, with your focus area highlighted:
1. Device Software (Firmware): This is the software that runs directly on the IoT devices themselves,
often on microcontrollers like those found in Arduino or the processors of Raspberry Pi. It's
responsible for:
o Interfacing with sensors and actuators.
o Local data processing and control logic.
o Implementing communication protocols to interact with other devices or the cloud. This is
where the Programming APIs you mentioned come into play.
2. Connectivity and Communication Middleware: This layer handles the complexities of network
communication between devices and the cloud or other on-premise systems. It often involves:
o Implementing and managing various communication protocols (MQTT, CoAP, etc.).
o Handling different network types (Wi-Fi, cellular, LoRaWAN, etc.).
o Ensuring secure communication.
o Device management aspects related to connectivity.
3. IoT Platforms and Cloud Services: These are often cloud-based services that provide a
comprehensive set of tools and capabilities for managing and leveraging IoT data. They typically
include:
o Device Management: Provisioning, onboarding, configuring, monitoring, and updating
devices.
o Data Ingestion and Storage: Receiving and storing the vast amounts of data generated by
IoT devices.
o Data Processing and Analytics: Analyzing the collected data to derive insights, identify
patterns, and trigger actions.
o Rules Engine and Event Processing: Defining rules and workflows based on real-time data
from devices.
o Visualization and User Interfaces: Creating dashboards and applications for users to interact
with the IoT system.
o Security Services: Protecting devices, data, and communication channels.
o Application Enablement: Providing tools and APIs for developers to build IoT applications.
4. Applications and User Interfaces: These are the end-user facing applications that allow users to
interact with and benefit from the IoT system. This could be mobile apps, web dashboards, or
integrations with other enterprise systems.
The Programming APIs (using Python, Node.js, Arduino) are the tools that developers use within the
Device Software and sometimes within the Connectivity and Communication Middleware layers to
implement the specific Communication Protocols (MQTT, ZigBee, Bluetooth, CoAP, UDP, TCP).
Abstraction: These APIs abstract away the low-level details of the communication protocols, making
it easier for developers to send and receive data without needing to understand the intricate
workings of each protocol.
Ease of Development: They provide functions and libraries that simplify tasks like connecting to
brokers or devices, subscribing to topics, publishing messages, handling data formats, and
managing connections.
Platform Specificity: The choice of API often depends on the programming language being used on
the IoT device or gateway (Python on Raspberry Pi, C/C++ on Arduino, JavaScript/Node.js on more
powerful edge devices).
Let's explore the common programming languages and the APIs they offer for the communication protocols
you mentioned:
1. Python APIs:
Python is a very popular language for IoT development due to its readability, extensive libraries, and ease of
use.
2. Node.js APIs:
Node.js, with its event-driven, non-blocking I/O model, is also popular for IoT gateways and backend
services.
MQTT:
o mqtt: A widely used and robust MQTT client library for Node.js. It offers similar
functionalities to paho-mqtt in Python:
Connecting to a broker.
Subscribing and publishing.
Handling events (connect, message, disconnect).
Supporting QoS and secure connections.
ZigBee:
o Node.js support for ZigBee often involves using libraries that interact with ZigBee coordinator
hardware (connected via USB or network).
o Libraries like zigbee-herdsman are used in projects like Zigbee2MQTT to bridge ZigBee
devices to an MQTT broker. These libraries handle the complexities of the ZigBee protocol.
Bluetooth:
o noble: A popular library for interacting with Bluetooth Low Energy (BLE) peripherals on
Linux, macOS, and Windows. It allows you to scan for devices, connect, discover services
and characteristics, and read/write data.
o Other libraries like bleno can be used to create BLE peripherals (advertise services and
characteristics) with Node.js.
CoAP:
o coap: A Node.js library for implementing CoAP clients and servers. It supports the core
CoAP features and allows you to build resource-constrained applications.
UDP and TCP:
o Node.js provides the built-in net module for TCP and the dgram module for UDP. These
modules offer asynchronous APIs for creating sockets, sending and receiving data, and
managing connections.
When programming directly on Arduino boards that have network capabilities (like ESP8266 or ESP32),
you often use specific libraries provided by the board's SDK or the Arduino community.
MQTT:
o PubSubClient: A very popular and widely used MQTT client library for Arduino (compatible
with ESP8266, ESP32, and other boards). It offers functions for connecting, subscribing,
publishing, and handling messages.
ZigBee:
o Direct ZigBee communication on standard Arduino boards often requires interfacing with
external ZigBee modules (via serial). You would then need to implement the ZigBee protocol
logic yourself or use libraries specific to the module.
o On ESP32, some libraries might provide more direct support for certain ZigBee chips.
Bluetooth:
o For ESP32, the built-in Bluetooth capabilities are often accessed through libraries provided
in the ESP-IDF (Espressif IoT Development Framework), which can be used with the
Arduino environment. These libraries allow for BLE scanning, advertising, connecting, and
data transfer.
CoAP:
o Libraries like CoapClient and CoapServer are available for Arduino (especially for
ESP8266/ESP32) to implement CoAP communication.
UDP and TCP:
o For network-enabled Arduino boards (like ESP8266 and ESP32), libraries like WiFiUdp (for
UDP) and WiFiClient (for TCP) are part of the standard Arduino core for these boards.
They provide functions for creating sockets, sending and receiving data over Wi-Fi.
Client vs. Server/Broker: For protocols like MQTT and CoAP, you'll often have clients (your IoT
devices) communicating with a central server (MQTT broker) or other servers. For protocols like
TCP and UDP, devices can act as both clients and servers.
Publish/Subscribe (Pub/Sub): MQTT is based on this pattern, where devices publish messages to
topics, and other devices subscribe to those topics to receive the messages.
Request/Response: CoAP follows a more traditional request/response model similar to HTTP.
Sockets: UDP and TCP communication is built on the concept of sockets, which are endpoints for
network communication.
Asynchronous vs. Synchronous Programming: Some libraries (especially in Node.js and modern
Python) offer asynchronous APIs, allowing your program to perform other tasks while waiting for
network operations to complete, leading to more efficient and responsive applications.
Event Handling: Many network libraries use event-driven programming, where your code defines
functions to be executed when specific network events occur (e.g., a new message arrives, a
connection is established).