Bird
0
0

Which of the following is the correct way to subscribe to a topic named 'home/temperature' using paho-mqtt client in Python?

easy📝 Syntax Q3 of 15
Raspberry Pi - MQTT for IoT
Which of the following is the correct way to subscribe to a topic named 'home/temperature' using paho-mqtt client in Python?
Aclient.sub('home/temperature')
Bclient.connect('home/temperature')
Cclient.listen('home/temperature')
Dclient.subscribe('home/temperature')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct subscription method

    The method to subscribe to a topic is client.subscribe(topic).
  2. Step 2: Eliminate incorrect methods

    client.sub() and client.listen() do not exist; client.connect() is for broker connection.
  3. Final Answer:

    client.subscribe('home/temperature') -> Option D
  4. Quick Check:

    Subscribe method = B [OK]
Quick Trick: Use subscribe() to listen to topics [OK]
Common Mistakes:
MISTAKES
  • Using sub() instead of subscribe()
  • Confusing connect() with subscribe()
  • Trying listen() which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes