Bird
0
0

How can you combine Flask and JavaScript to update the GPIO pin status on a web page without refreshing the page?

hard🚀 Application Q9 of 15
Raspberry Pi - Web Server and API
How can you combine Flask and JavaScript to update the GPIO pin status on a web page without refreshing the page?
AReload the entire Flask page every second to update status
BUse Flask to serve API endpoints and JavaScript fetch() to poll pin status asynchronously
CUse Flask to send pin status only on initial page load
DUse JavaScript alert() to show pin status changes
Step-by-Step Solution
Solution:
  1. Step 1: Understand asynchronous updates

    JavaScript fetch() can call Flask API endpoints without page reload.
  2. Step 2: Use this to update GPIO status dynamically

    Polling or event-driven fetch updates pin status on page smoothly.
  3. Final Answer:

    Use Flask to serve API endpoints and JavaScript fetch() to poll pin status asynchronously -> Option B
  4. Quick Check:

    Async fetch + Flask API = A [OK]
Quick Trick: Use fetch() to get GPIO status from Flask API without reload [OK]
Common Mistakes:
MISTAKES
  • Reloading full page wastes resources
  • Only sending status once misses updates
  • Using alert() is intrusive and not dynamic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes