DEV Community

Innovationdigest
Innovationdigest

Posted on

A Simple Check for When Your IoT Data and Your Records Disagree

A storage silo reads "adequate" in the inventory system, while the real material level is already low. Nothing is broken. The numbers just come from different places, and nobody compares them.

A simple reconciliation check

Take a recorded value and a measured value for the same asset, make sure they are close enough in time, and flag the pair if they disagree by more than a tolerance.

from dataclasses import dataclass
from datetime import datetime


@dataclass
class Reading:
    value: float
    timestamp: datetime


def reconcile(recorded, measured, tolerance=10.0, max_gap_s=300):
    gap = abs((recorded.timestamp - measured.timestamp).total_seconds())
    if gap > max_gap_s:
        return "stale"
    if abs(recorded.value - measured.value) > tolerance:
        return "discrepancy"
    return "ok"
Enter fullscreen mode Exit fullscreen mode

Three details that matter

  1. Check timestamps first. Comparing a live reading with a value recorded this morning creates false alarms. A stale result also tells you a data source stopped updating.
  2. Set tolerance per asset. Keep thresholds in configuration, not in code.
  3. Don't auto-correct. Overwriting the recorded value hides the problem. Log it and find out why it happened.

You don't need machine learning to start. Add it later, once you trust the data coming in.

If you are building a system like this and want to show it to investors or partners, Aperture Ventures Summit is accepting speaker applications from AI and IoT builders.

How do you handle disagreements between recorded and measured data in your own systems?

Top comments (0)