Bird
0
0

You want your Raspberry Pi to send live temperature updates to a web page using WebSocket. Which approach best ensures the web page updates instantly when the sensor value changes?

hard🚀 Application Q15 of 15
Raspberry Pi - Web Server and API
You want your Raspberry Pi to send live temperature updates to a web page using WebSocket. Which approach best ensures the web page updates instantly when the sensor value changes?
AOpen a new WebSocket connection every time the temperature changes.
BOpen a WebSocket connection once, then send new temperature data whenever it changes.
CSend temperature data only when the web page reloads.
DUse HTTP GET requests repeatedly to fetch temperature data.
Step-by-Step Solution
Solution:
  1. Step 1: Understand WebSocket usage for live updates

    WebSocket keeps a connection open, so sending data only when it changes over the same connection is efficient and instant.
  2. Step 2: Evaluate other options

    Opening new connections repeatedly (B) wastes resources. Sending data only on reload (C) or using HTTP polling (D) is slower and less real-time.
  3. Final Answer:

    Open a WebSocket connection once, then send new temperature data whenever it changes. -> Option B
  4. Quick Check:

    One open connection + send updates = instant live data [OK]
Quick Trick: Keep one connection open; send updates as they happen [OK]
Common Mistakes:
MISTAKES
  • Opening multiple connections unnecessarily
  • Relying on page reloads for updates
  • Using HTTP polling instead of WebSocket

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes