IoT applications often collect readings from sensors and turn them into information that people can understand. A pool-monitoring application is one example: it might collect water temperature, pH readings, and equipment status.
The first challenge is not creating a dashboard. It is deciding whether incoming readings are valid and how to process them consistently.
In this tutorial, we'll create a small Python data-processing pipeline using simulated readings.
1. Create sample data
readings = [
{"temperature": 27.4, "ph": 7.3},
{"temperature": 28.1, "ph": 7.4},
{"temperature": 27.8, "ph": 7.2},
{"temperature": None, "ph": 7.3},
{"temperature": 29.0, "ph": 7.5},
]
These readings are illustrative, not live sensor data or a recommendation for pool water chemistry.
2. Validate each reading
Sensors may produce missing values, malformed data, or readings outside expected physical ranges.
import math
def is_valid_reading(reading):
temperature = reading.get("temperature")
ph = reading.get("ph")
if not isinstance(temperature, (int, float)):
return False
if not isinstance(ph, (int, float)):
return False
if not math.isfinite(temperature) or not math.isfinite(ph):
return False
return True
This example validates data types and rejects non-finite numbers. A real deployment should define acceptable ranges based on sensor specifications and the intended use.
3. Filter valid records
valid_readings = [
reading
for reading in readings
if is_valid_reading(reading)
]
print(f"Received: {len(readings)}")
print(f"Valid: {len(valid_readings)}")
print(f"Rejected: {len(readings) - len(valid_readings)}")
Filtering lets the application distinguish between missing data and real measurements rather than silently treating both as zero.
4. Calculate summary statistics
def average_temperature(records):
if not records:
return None
values = [r["temperature"] for r in records]
return sum(values) / len(values)
average = average_temperature(valid_readings)
if average is not None:
print(f"Average temperature: {average:.1f} °C")
else:
print("No valid temperature readings available.")
The function also handles an empty dataset, which is an important edge case in data processing.
5. Design a more reliable pipeline
A production IoT system needs more than averages. Consider this flow:
- Receive a sensor message.
- Validate its schema and timestamp.
- Check whether the reading is duplicated.
- Store the original reading.
- Flag suspicious values for review.
- Generate summaries for the dashboard.
It is also useful to track sensor identifiers, calibration dates, units, and communication failures. A missing reading should not automatically be interpreted as a safe reading.
Conclusion
Reliable dashboards begin with reliable data. By separating validation, filtering, and aggregation, developers can make monitoring systems easier to test and maintain.
The same design can be applied to weather stations, greenhouse monitoring, energy meters, and other sensor-based applications.
Top comments (0)