API in IoT?
An API (Application Programming Interface) in IoT is a software interface that allows
communication between IoT devices and applications. APIs allow:
Devices to send sensor data to servers
Applications to control devices remotely
Cloud platforms to exchange data with devices
In short, APIs are the bridge between IoT hardware and the software world.
🔹 Why APIs are Needed in IoT:
Need Role of API
Sends sensor data to server or
📡 Device Communication
app
App turns device ON/OFF
💻 Application Control
remotely
Connects device to platforms like
☁ Cloud Integration
AWS, Google Cloud
Allows data to move between
🔄 Data Exchange
multiple devices/services
🔹 Types of IoT Communication APIs:
API Type Description Example
HTTP-based API using GET, POST, PUT,
REST API GET temperature from sensor
DELETE commands
ESP32 publishes sensor data to
MQTT API Lightweight messaging protocol used in IoT
MQTT broker
Web transfer protocol optimized for low- Used in constrained devices over
CoAP API
power IoT devices UDP
WebSocket Used in real-time monitoring
Real-time two-way communication
API dashboards
Flexible querying API, useful for data Mobile app fetching only needed
GraphQL API
visualization sensor values
🔹 Example: REST API in Smart Home System
Suppose you have a smart bulb connected to the internet.
Operation API Call Meaning
Turn ON bulb POST /api/bulb/on Sends command to bulb to turn ON
Turn OFF bulb POST /api/bulb/off Sends command to turn OFF
Get bulb status GET /api/bulb/status Returns ON or OFF
The IoT mobile app uses this REST API to control the smart bulb over Wi-Fi.
🔹 Example: MQTT in IoT (Sensor → Cloud)
Sensor device (ESP32) publishes:
topic = "farm/soilMoisture"
payload = "Dry"
Cloud application subscribes to that topic and acts:
o If "Dry" → send command to turn ON irrigation pump.
MQTT is fast and works even in low-bandwidth rural areas, making it ideal for IoT.
🔹 Features of IoT APIs:
Feature Benefit
🌐 Platform-independent Work with mobile, web, desktop
🔒 Secure Use tokens, HTTPS, authentication
⚙ Scalable Can manage many devices
💬 Real-time capable Instant updates from devices
🔹 Popular Platforms Offering IoT APIs:
Platform Type API Use
REST, Send/receive
ThingSpeak
MQTT sensor data
Automation
IFTTT Webhooks between
devices/apps
Realtime
REST,
Firebase database for
WebSockets
IoT apps
AWS IoT REST, Industrial and
MQTT enterprise IoT
Platform Type API Use
control
Simple
REST, dashboard with
Adafruit IO
MQTT APIs for
sensors
IoT Communication Models – Explained with Examples
🔹 What is a Communication Model in IoT?
In IoT, a communication model describes how devices exchange
data with each other, the cloud, or applications.
It defines the direction, method, and flow of data between IoT
devices, servers, and users.
🔹 Main IoT Communication Models
# Model Description Example
Smart lights
Devices communicate
Device-to- communicating with
1 directly without cloud
Device (D2D) smart switches via
involvement
Zigbee
Device sends data directly Smart thermostat
Device-to-
2 to cloud servers over the sending temperature
Cloud (D2C)
internet to AWS IoT Core
Device-to- Device communicates Zigbee sensor → IoT
3 Gateway with a gateway that gateway → Google
(D2G) forwards data to the cloud Cloud
Device communicates
Device-to- Security camera
directly with a user’s
4 Application streaming video to a
application
(D2A) mobile app
(mobile/desktop)
5 Publish- Devices publish data to a MQTT-based soil
Subscribe broker; other moisture sensor
Platform Type API Use
devices/applications publishing readings;
(Pub/Sub) subscribe to receive irrigation controller
updates subscribes
1️⃣ Device-to-Device (D2D) Model
Definition: Direct communication between devices using
protocols like Bluetooth, Zigbee, or Wi-Fi Direct.
Example: Two smart bulbs sync brightness without
internet.
2️⃣ Device-to-Cloud (D2C) Model
Definition: Devices connect to cloud applications for
processing and storage.
Example: A fitness tracker sends heart rate data to Fitbit
cloud servers.
3️⃣ Device-to-Gateway (D2G) Model
Definition: Devices connect to a local gateway (like a
Raspberry Pi or IoT hub), which sends data to the cloud.
Example: Smart meters send usage data to a home
gateway, which uploads it to the utility company.
4️⃣ Device-to-Application (D2A) Model
Definition: Direct device connection with an app,
bypassing cloud storage.
Example: A Bluetooth-enabled blood pressure monitor
sends readings directly to a mobile health app.
5️⃣ Publish-Subscribe (Pub/Sub) Model
Definition: Devices (publishers) send data to a broker;
Platform Type API Use
subscribers receive updates only when new data is
available.
Example:
o Publisher: Temperature sensor publishes to topic
home/livingroom/temp
o Subscriber: Mobile app subscribes to receive
temperature updates.
🔹 Visual Representation of Models:
1. Device-to-Device: [Device A] ↔ [Device B]
2. Device-to-Cloud: [Device] → [Cloud Server]
3. Device-to-Gateway: [Device] → [Gateway] →
[Cloud]
4. Device-to-Application: [Device] → [User App]
5. Pub-Sub: [Publisher] → [Broker] →
[Subscriber]
✅ Summary:
D2D → Local control, no internet required.
D2C → Cloud storage & processing.
D2G → Gateway acts as a bridge.
D2A → Direct to app.
Pub/Sub → Flexible, event-driven communication.
Difference Between IoT Communication APIs and IoT
Communication Models
Aspect IoT Communication Models IoT Communication APIs
Defines how data flows between IoT A set of rules and methods that allow
Meaning devices, gateways, cloud, and software, devices, and cloud platforms to
applications. interact and exchange data.
Describes the structure and direction Provides instructions on how to
Purpose
of communication. send/receive data between systems.
"Who talks to whom" and "in what "How exactly they talk" (commands,
Focus
way". endpoints, format).
Aspect IoT Communication Models IoT Communication APIs
Device-to-Cloud model: A smart REST API call: GET /temperature to
Example thermostat sends temperature readings fetch the latest temperature from the
to the cloud server. thermostat’s server.
Like the language and phrases drivers use
Like the traffic system: defines roads
Analogy to communicate (horn, indicators, road
and directions (one-way, two-way).
signs).
Protocol Uses protocols like MQTT, HTTP, Implements those protocols in an
Relation CoAP in different models. accessible way for developers.
Describes connection patterns in an Delivers actual data or executes an action
Output
IoT network. on a device.
Model: Device-to-Application → Bulb
Example in API: Mobile app sends POST /bulb/on
communicates directly with mobile
Smart Home command to turn on the bulb.
app via Bluetooth.
✅ In Short:
IoT Communication Models = The blueprint of how devices connect and
communicate 📡
IoT Communication APIs = The actual instructions that make the communication
happen 🛠