0% found this document useful (0 votes)
18 views41 pages

Iot 4

The document outlines the rules for an IoT class and provides a detailed overview of the MQTT protocol, including its functions, components, and applications in IoT systems. It explains how sensors collect and transmit data, the importance of communication protocols, and the architecture of MQTT brokers in cloud environments. Additionally, it discusses the differences between ESP32 and Raspberry Pi, system limitations, and potential solutions for improving IoT applications.

Uploaded by

aliaahisham208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views41 pages

Iot 4

The document outlines the rules for an IoT class and provides a detailed overview of the MQTT protocol, including its functions, components, and applications in IoT systems. It explains how sensors collect and transmit data, the importance of communication protocols, and the architecture of MQTT brokers in cloud environments. Additionally, it discusses the differences between ESP32 and Raspberry Pi, system limitations, and potential solutions for improving IoT applications.

Uploaded by

aliaahisham208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

IOT

Associated Prof. Wafaa


Shalash
Lect. 4
Class Rules
• Be in class on time,
• Listen to instructions and
explanations.
• Talk to your classmates only when
there is an activity.
• Use appropriate and professional
language.
• Keep your mobile silent.
Sensors & Protocols
Lecture Topics
• MQTT Protocol
• Main Functions of MQTT
• Components of MQTT
Sender & Receiver in IoT
How Sensors Work in IoT?

1.Data Collection – Sensors measure


environmental parameters (e.g., temperature,
humidity, motion).
2.Data Conversion – Converts the physical
value into an electrical signal.
3.Data Transmission – Sends the signal to an
IoT gateway or cloud via communication
protocols like MQTT, CoAP, Bluetooth, Wi-Fi,
or LoRaWAN.
4.Processing & Action – The IoT system
analyzes the data and performs actions (e.g.,
alerting users, adjusting temperature, or
turning off lights). 5
Protocols More
on……
Sensor Communication & Protocols (MQTT, CoAP,
Bluetooth, etc.)
• IoT sensors collect data, but they need communication protocols to
transmit this data to other devices, edge gateways, or cloud platforms.
These protocols are essential for reliable, efficient, and secure data
exchange.
The Constraints on Communication Protocols for IoT
Applications

Powe
Range Application Latency
Efficiency

Cost Compatibility reliability


Comparison Table
Feature Wi-Fi Bluetooth Zigbee LoRa NB-IoT CoAP HTTP 5G MQTT
Request- Publish-
Short-range Short-range Long-range Cellular Lightweight Cellular
Type Wireless LAN Response Subscribe
Wireless Mesh LPWAN LPWAN Protocol Network
Protocol Protocol

Communicatio Peer-to-Peer Client-Server


Client-Server Mesh Star Topology Star Topology Client-Server Client-Server Client-Server
n Model or Mesh (Broker-based)

Medium to
~10m (100m Medium
Range ~100m ~100m 10+ km 10+ km Medium (LAN) 1+ km Long (LAN,
BLE 5.0) (WAN)
WAN, Cloud)

Power
High Very Low (BLE) Low Very Low Low Low High High Low
Consumption
Low to
Latency Low Very Low Low High High Low High Ultra-low
Medium
Up to 2 Mbps
Data Rate Up to 1 Gbps 250 kbps 0.3–50 kbps ~100 kbps 10s of kbps Mbps Gbps 10s of kbps
(BLE 5.0)
Supports
AES AES AES Cellular 5G Security
Security WPA2, WPA3 DTLS TLS/SSL TLS/SSL
encryption encryption encryption encryption Framework
encryption

Cloud
Wearables, Smart homes, Smart Resource- Smart cities, communicatio
Smart Homes, Agriculture, Web-based
Use Cases Smart home Industrial metering, constrained Autonomous n, Industrial
Industrial IoT Smart Cities IoT, APIs
devices sensors Industrial IoT devices vehicles IoT, Remote
Monitoring
MQTT Protocol
(Message Queuing Telemetry Transport)
What is the MQTT protocol?
• IoT MQTT is a lightweight publish/subscribe messaging protocol
designed for M2M (machine to machine) telemetry in low bandwidth
environments.
• MQTT is fast becoming one of the main protocols for IOT (internet of
things) deployments.
Main Functions of MQTT
• 1. Publish-Subscribe Messaging Model
• Instead of direct communication between devices, MQTT uses a broker-
based architecture where:
• Publishers send messages to a central broker.
• Subscribers receive messages from the broker when they are subscribed to a specific
topic.
• This decouples the sender and receiver, making MQTT scalable and
efficient.
• 2. Efficient Data Transmission
• MQTT transmits small message payloads, reducing bandwidth usage.
• Works well in low-power and constrained environments, such as sensor
networks and mobile applications.
Main Functions of MQTT
• 3. Quality of Service (QoS) Levels
• Quality of Service (QoS) in networking and communication protocols refers to the level of reliability and
guarantee provided for message delivery.
• In MQTT (Message Queuing Telemetry Transport), there are three QoS levels, each defining how messages
are delivered between the sender (publisher) and receiver (subscriber)
• MQTT supports three QoS levels to ensure message delivery reliability:
Example: How QoS Levels Affect the
application design:
1.QoS 0 (At most once) – Used for non-critical sensor data
1. The ESP32 sends temperature readings every 10 seconds to the MQTT broker.
2. If a message is lost due to network issues, the system does not resend it.
3. This is acceptable because a new reading will be sent soon.
2.QoS 1 (At least once) – Used for logging temperature data
1. The Raspberry Pi logs temperature data to a database.
2. The message is retransmitted if an acknowledgment (ACK) is not received.
3. If a duplicate is received, it can be handled by checking timestamps.
3.QoS 2 (Exactly once) – Used for controlling the Smart AC
1. When the temperature exceeds 30°C, the Raspberry Pi sends a command to the smart AC unit
to turn on.
2. The AC must receive this command exactly once, as duplicate messages could cause
unnecessary toggling.
3. QoS 2 ensures the command is delivered reliably without duplication.
Main Functions of MQTT
• 4. Persistent Session Support
• Retains messages for disconnected clients and delivers them once
they reconnect.
• Useful for IoT devices that may experience intermittent connectivity.
• 5. Security & Authentication
• Supports TLS/SSL encryption for secure communication.
• Uses username-password authentication and Access Control Lists
(ACLs) to manage client permissions.
Components of MQTT Sender & Receiver in IoT
• In an MQTT communication system, the Sender (Publisher) and
Receiver (Subscriber) are usually IoT devices, microcontrollers, or
servers that exchange messages through an MQTT broker.
•The Sender (Publisher) is any device that sends data (sensors,
apps, cloud platforms).
•The Receiver (Subscriber) is any device that listens and reacts
(microcontrollers, actuators, cloud).
•Both communicate via an MQTT broker, making the system
scalable and efficient for IoT.
1. Physical Components of an MQTT Sender
(Publisher)
• The Sender (Publisher) is the device that collects data and sends
messages to the MQTT broker. It could be:
• Sensors & Microcontrollers
• ESP32/ESP8266 – Used in IoT applications to send sensor data.
• Arduino + Wi-Fi Module – Sends data to an MQTT broker.
• Raspberry Pi – Runs Python scripts to publish messages.
• Industrial Machines
• PLCs (Programmable Logic Controllers) in factories send data on temperature,
pressure, or machine status.
• Mobile Apps & Web Applications
• A smartphone app (e.g., a smart home app) sends commands like “Turn on the
light”.
• A web dashboard sends MQTT messages to control devices remotely.
2. Physical Components of an MQTT Receiver
(Subscriber)

• The Receiver (Subscriber) is the device that listens for messages from the MQTT
broker. It could be:
• Microcontrollers & IoT Devices
• ESP32/ESP8266 with a relay – Turns on/off appliances when receiving MQTT commands.
• Arduino with an OLED display – Displays sensor values received via MQTT.
• Raspberry Pi – Logs data from the MQTT broker.
• Actuators & Smart Devices
• Smart Bulbs, Fans, or Thermostats – Receive MQTT messages to change state.
• Motors, Servo Controls – Used in robotics, home automation, or industrial applications.
• Cloud Platforms & Web Apps
• AWS IoT Core, Azure IoT Hub, Google Cloud IoT – Receive and process MQTT messages.
• Web dashboards & mobile apps – Display received data in real-time.
How an MQTT Broker Connects to a Cloud Server
• An MQTT broker is responsible for routing messages between MQTT
clients (publishers and subscribers). When deploying an MQTT broker
in a cloud environment, it enables remote access, scalability, and
global communication for IoT devices.
1. Architecture of an MQTT Broker in the Cloud
• IoT Devices (Publishers & Subscribers) → Send and receive MQTT messages.
MQTT Broker (Cloud-based or On-Premises) → Routes messages between
devices.
Cloud Server (AWS, Azure, Google Cloud, etc.) → Stores, analyzes, and
processes data.

•Cloud-based MQTT brokers enable global IoT communication.


•Managed cloud brokers (AWS IoT, Azure IoT Hub) simplify deployment.
•Self-hosted MQTT brokers (Mosquitto, EMQX) provide flexibility on cloud
VMs.
•Brokers integrate with databases, AI services, and dashboards for real-time
insights.
2. Ways to Deploy an MQTT Broker in the Cloud
A. Using a Managed MQTT Broker (Cloud Service)
• Cloud providers offer built-in MQTT brokers, eliminating the need for manual
setup.
• Examples of Cloud MQTT Brokers:
• AWS IoT Core – Secure, scalable MQTT service.
• Azure IoT Hub – Supports MQTT for real-time IoT messaging.
• Google Cloud IoT Core – Provides MQTT over WebSockets.
• How It Works:
1.IoT devices publish messages to the cloud broker.
2.The broker forwards messages to cloud applications, databases, or AI models.
3.Cloud dashboards or mobile apps subscribe to the messages for real-time
updates.
2. Ways to Deploy an MQTT Broker in the Cloud
B. Hosting Your Own MQTT Broker on a Cloud Server
• You can install an open-source MQTT broker on a cloud server (AWS
EC2, DigitalOcean, Google Cloud VM, etc.).
• Popular Open-Source MQTT Brokers:
• Mosquitto – Lightweight, widely used.
• EMQX – High-performance, scalable broker.
• HiveMQ – Enterprise-grade broker for large IoT applications.
3. Connecting an MQTT Broker to Cloud
Databases & Applications
Once the MQTT broker is running in the cloud, it can connect to various cloud
services:
• Cloud Database (MongoDB, Firebase, AWS DynamoDB) → Stores sensor data.
Cloud AI/ML Services → Processes IoT data for analytics.
Web Dashboards & Mobile Apps → Display real-time data.
• Example Workflow:
1.IoT sensor publishes data to an MQTT topic (sensor/temperature).
2.Cloud-based MQTT broker (Mosquitto, AWS IoT Core, etc.) routes the
message.
3.Cloud database stores the data (MongoDB, Firebase).
4.Web app or mobile app subscribes to the topic and updates the dashboard in
real-time.
Network Options for MQTT Cloud Connectivity
When to Use Wi-Fi vs. 5G for MQTT?
Example Setup: MQTT-Based Home Automation

• Scenario:
• Sender (Publisher): ESP32 with a DHT11 Sensor sends temperature
data via MQTT.
• MQTT Broker: Mosquitto Broker running on a cloud server.
• Receiver (Subscriber): Raspberry Pi listens for MQTT messages and
logs temperature.
• Actuator: Smart AC unit turns on/off when a temperature threshold
is met.
Components:
Example Setup: MQTT-Based Home Automation

Sender (Publisher): Cloud Receiver (Subscriber)


Raspberry Pi listens for MQTT
ESP32 with a DHT11 Mosquitto Broker messages and logs
Sensor temperature.
MQTT Client
Temperature Sensor
MQTT
Broker

Actuator: Smart
AC unit
Difference Between ESP32 and Raspberry Pi
ESP32 and Raspberry Pi are both popular platforms for IoT and embedded systems, but they serve different purposes
Feature ESP32 Raspberry Pi
Type Microcontroller (MCU) Single-Board Computer (SBC)

Processor Dual-core Xtensa 32-bit LX6 ARM-based CPU (Quad-core in most models)

Clock Speed ~240 MHz ~1 GHz – 2.4 GHz (depending on model)

RAM 512 KB SRAM 512MB – 8GB (depending on model)

Storage Flash memory (~4MB) MicroSD card or onboard eMMC storage

Operating System No OS (runs on bare-metal or RTOS) Runs full OS (Linux, Raspberry Pi OS)

Connectivity Built-in Wi-Fi, Bluetooth, LoRa (some models) Wi-Fi, Ethernet, USB, HDMI

Power Consumption Very Low (Deep Sleep mode ~10µA) Higher (Typically 5V, 2.5A)

GPIO Pins 30+ 40+


Programming
C, C++, MicroPython, Arduino IDE Python, C++, Java, Full OS support
Language
Best Use Cases IoT, sensor applications, low-power projects AI, robotics, full applications, multimedia
Key Differences & When to Use Each
Use Case ESP32 Raspberry Pi
IoT & Low-Power Applications
Wi-Fi & Bluetooth
Connectivity
Running a Full Linux OS
Real-Time Applications (RTOS)
AI & Machine Learning

Embedded Systems (Bare-


Metal Programming)

Camera & Multimedia


Processing

Industrial Automation &


Robotics
Key Differences & When to Use Each

When to Use ESP32? When to Use Raspberry Pi?


• Low-power IoT applications • Projects needing an OS
(e.g., weather stations, smart (Linux) (e.g., AI, home
home). automation, media centers).
• Battery-powered projects • Computer vision & AI
(e.g., wearables, remote applications (e.g., object
monitoring). detection, surveillance).
• Embedded systems requiring • Networking projects (e.g.,
real-time response (e.g., VPN servers, firewalls, web
motor control). servers).
System Limitations
System Limitations :
1. Network Dependency
• Issue: The system relies on a stable network connection for MQTT
messages to be transmitted. If the Wi-Fi or internet connection is
lost, communication between components will fail.
• Solution: Implement offline fallback mechanisms, such as local
storage on the ESP32 or Raspberry Pi, and retry logic for MQTT
messages.
System Limitations :
• 2. Latency Issues
• Issue: Delays can occur in message transmission, especially if the MQTT
broker is hosted on a cloud server.
• Solution: Optimize the network and reduce message payload size. You could
also host the MQTT broker locally (on the Raspberry Pi) instead of the cloud to
reduce latency.
• 3. Security Vulnerabilities
• Issue: MQTT does not have built-in encryption, making it vulnerable to
attacks like man-in-the-middle (MITM) and unauthorized access.
• Solution:
• Use TLS encryption for secure communication.
• Implement username/password authentication for MQTT connections.
• Restrict access using firewall rules and VPNs.
System Limitations :
• 4. Sensor Accuracy and Reliability
• Issue: The DHT11 sensor has limited accuracy (+/- 2°C and 5%
humidity deviation) and a slow refresh rate.
• Solution: Consider upgrading to a more precise sensor like DHT22,
BME280, or SHT31 for better accuracy and response time.
• 5. Scalability Challenges
• Issue: Adding multiple sensors or devices can overload the MQTT
broker, leading to delays or dropped messages.
• Solution:
• Use QoS (Quality of Service) Levels to manage message delivery.
• Deploy a load-balanced MQTT broker cluster if scaling to many devices.
System Limitations :
• 6. Power Consumption
• Issue: The ESP32 and Raspberry Pi consume power continuously,
which might not be ideal for battery-powered setups.
• Solution: Implement low-power modes on the ESP32 and
optimize Raspberry Pi's energy usage.
• 7. Lack of Cloud Integration & Data Storage
• Issue: Without cloud storage, historical temperature logs and
device control history cannot be accessed remotely.
• Solution: Integrate with Google Cloud IoT, AWS IoT, or
ThingsBoard to store and visualize data.
System Limitations :
8. Actuator Control Limitations
•Issue: A smart AC unit might not support direct MQTT control
without additional hardware.
•Solution: Use IR-based relays (e.g., Broadlink RM4) or smart
plugs that support MQTT/Home Assistant for seamless control.
Example 2 Setup: MQTT-Based Smart
Irrigation System
• Scenario
• A smart irrigation system automatically waters plants based on soil
moisture levels and can be controlled remotely using a cloud-based
MQTT broker.
• Components
• ESP32 with Soil Moisture Sensor (Publisher) → Sends moisture data.
• MQTT Broker (Cloud-Based: HiveMQ or AWS IoT Core) → Handles
communication.
• Raspberry Pi (Subscriber & Controller) → Listens for moisture data
and controls a water pump.
• Actuator: Smart Water Pump → Turns ON/OFF based on soil moisture.
What is system
Limitation ?
How to overcome………………….?
Application Layer Protocols (Data Exchange &
Communication)
• A) MQTT (Message Queuing Telemetry Transport)
• Function: Lightweight publish-subscribe protocol ideal
for IoT.
Advantage: Efficient for low-bandwidth, unreliable
networks.
How It Works:
• Publisher: Sends data (e.g., a temperature sensor publishing
readings).
• Broker: Routes messages to interested subscribers.
• Subscriber: Receives data if subscribed to a topic (e.g., a
dashboard displaying temperature data).
Use Cases:
Smart home automation
Industrial IoT monitoring
Real-time tracking

You might also like