IO7: Device-to-cloud messaging: MQTT and CoAP

Lesson 1 of 5 · reading 15–25 minutes; practice and project time is on the module page

Why not HTTP for everything?

🎯You'll be able to

Compare HTTP, MQTT and CoAP for devices, and choose one for a given device and network.

🏠The everyday picture

A newspaper delivered to every subscriber is different from each person going to the shop to ask whether there's news. One message fanned out to many beats many questions asked again and again.

📘What it really is

📝A worked example

Input: JalSetu sends a small reading every hour and should receive a "send your log" command now and then.

Steps:

  1. With HTTP, the device would have to ask "any commands?" on every wake, and the server couldn't reach it otherwise.
  2. With MQTT, the device subscribes to its command topic when it connects, and messages waiting for it can be delivered then.
  3. Choose MQTT for readings and commands, and plain downloads for firmware images.

Expected output: the protocol choice the kit uses.

🌍Where it's used

📝Case scenario

A team's devices polled an HTTP endpoint every minute for commands. With 10,000 devices, the server handled 14 million requests a day, almost all saying "nothing new". Moving to MQTT subscriptions cut the load to the messages that mattered.

🖱️Try it

For three devices (a door sensor, a weather station sending every 10 minutes, a smart bulb), choose HTTP, MQTT or CoAP and say why. Success: a choice and a reason for each.

⚠️Common mistakes

🛠️For your project

Project 2 sends readings and status with MQTT; Project 3 downloads firmware separately.

✅Quick check

How does a publish and subscribe system deliver a message?

Show the answer

A device publishes to a topic on a broker, and the broker passes it to everyone subscribed to that topic.

Why is polling for commands a poor fit for devices?

Show the answer

It costs requests and battery even when there's nothing new, and commands wait until the next poll.

← BackIO7
ProLearners Assist