Bird
0
0

You want to send temperature and humidity readings from a Raspberry Pi to an MQTT broker every 10 seconds. Which method is the best practice?

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

You want to send temperature and humidity readings from a Raspberry Pi to an MQTT broker every 10 seconds. Which method is the best practice?

AUse a loop with <code>time.sleep(10)</code> and publish both readings inside the loop
BPublish temperature and humidity once and rely on MQTT to resend automatically
CPublish only temperature every 10 seconds and humidity every 30 seconds
DPublish data only when sensor values change, ignoring timing
Step-by-Step Solution
Solution:
  1. Step 1: Understand periodic publishing

    To send data every 10 seconds, a loop with a delay is appropriate.
  2. Step 2: Publish both readings together

    Publishing temperature and humidity together ensures synchronized data.
  3. Step 3: Evaluate other options

    Relying on MQTT to resend or publishing irregularly is not reliable for periodic data.
  4. Final Answer:

    Use a loop with time.sleep(10) and publish both readings inside the loop -> Option A
  5. Quick Check:

    Periodic loop with sleep for timed publishing [OK]
Quick Trick: Use timed loops to publish sensor data regularly [OK]
Common Mistakes:
MISTAKES
  • Assuming MQTT broker resends data automatically
  • Publishing only one sensor value periodically
  • Ignoring timing and publishing irregularly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes