Bird
0
0

Which is the best way to organize MQTT topics and client IDs?Device 1 in living roomDevice 2 in kitchenChoose the best topic and client ID setup.

hard🚀 Application Q15 of 15
Raspberry Pi - MQTT for IoT

You want to control multiple Raspberry Pi devices in different rooms using MQTT. Each device should only receive messages for its room. Which is the best way to organize MQTT topics and client IDs?

  • Device 1 in living room
  • Device 2 in kitchen

Choose the best topic and client ID setup.

AUse topics <code>livingroom</code> and <code>kitchen</code> but same client ID <code>pi</code> for both devices.
BUse the same topic <code>home/all</code> for both and client IDs <code>pi1</code> and <code>pi2</code>.
CUse topics like <code>home/livingroom/#</code> and <code>home/kitchen/#</code> with client IDs <code>pi_livingroom</code> and <code>pi_kitchen</code>.
DUse random topics and client IDs for each device without pattern.
Step-by-Step Solution
Solution:
  1. Step 1: Organize topics by room

    Using hierarchical topics like home/livingroom/# and home/kitchen/# lets devices subscribe only to their room's messages.
  2. Step 2: Assign unique client IDs

    Unique client IDs like pi_livingroom and pi_kitchen avoid connection conflicts and identify devices clearly.
  3. Final Answer:

    Use topics like home/livingroom/# and home/kitchen/# with client IDs pi_livingroom and pi_kitchen. -> Option C
  4. Quick Check:

    Unique IDs + room topics = clean multi-device MQTT [OK]
Quick Trick: Use unique client IDs and room-based topics [OK]
Common Mistakes:
MISTAKES
  • Using same client ID for multiple devices
  • Subscribing all devices to a single topic
  • Not organizing topics by device location

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes