Serving sensor data as JSON API
📖 Scenario: You have a Raspberry Pi connected to a temperature sensor. You want to share the sensor readings over a simple web API that returns the data in JSON format. This way, other devices or apps can easily get the current temperature.
🎯 Goal: Build a small Python program that reads temperature data from a sensor (simulated), sets up a web server, and serves the sensor data as a JSON response when accessed.
📋 What You'll Learn
Create a dictionary with sensor data including 'temperature' and 'unit'.
Create a variable called 'port' to set the server port number.
Use Flask to create a web server with a route '/' that returns the sensor data as JSON.
Print a message showing the server is running on the specified port.
💡 Why This Matters
🌍 Real World
Sharing sensor data as JSON over a network is common in IoT projects, home automation, and remote monitoring.
💼 Career
Understanding how to serve JSON APIs is important for backend development, embedded systems, and working with connected devices.
Progress0 / 4 steps