iot-full Knows the Difference Between a Flood and a Blockage

A drainage-monitoring dashboard reduces a city's flood response to two numbers per sensor and one rule that a threshold alarm would miss.

7 min read • View on GitHub • More from ashser004

A black-ink cross-section of a rain-soaked Kochi street. Rain falls on the road above while a large drainage pipe runs below ground toward the viewer, with water flowing through it and small sensor probes mounted at pipe junctions. It shows that the dashboard is a thin software layer sitting over physical pipes and hardware.
The dashboard is a thin layer over physical pipes. Everything the screen shows comes from probes like these.
Key Takeaways

A Full Pipe Is Not Always a Flood

A drainage pipe at 80 percent capacity is telling you one of two completely different things. Either water is racing through it and the drain cannot keep up, or water is stuck and something is blocking it. Same water level. Opposite emergency. Different crew, different tools, different fix.

Most flood alarms look at water level alone. That works until it doesn't. A threshold alarm that fires at 75 percent capacity will scream FLOOD whether the pipe is surging or plugged, and the response team that shows up expecting to clear a drain finds a wall of still water instead. The sensor was right about the water and wrong about the problem.

const H = 2.0;                  // pipe height, metres
const LOW_FLOW_THRESHOLD = 2.0; // L/min

export function getAlertStatus(waterLevelCm, flowRate) {
  const h = waterLevelCm / 100;

  // Above the critical line, flow decides the cause.
  if (h >= 0.75 * H && flowRate <= LOW_FLOW_THRESHOLD) return "BLOCKAGE";
  if (h >= 0.75 * H && flowRate >  LOW_FLOW_THRESHOLD) return "FLOOD";

  if (h >= 0.50 * H && h < 0.75 * H) return "WARNING";
  return "NORMAL";
}

The rule is small. It reads two numbers per sensor, water height and flow rate, and it lands in one of four states. The interesting part is what happens above the critical line. Once the pipe is more than three quarters full, height stops being the deciding signal. Flow takes over. High flow means the drain is overwhelmed (FLOOD). Low flow means it is blocked (BLOCKAGE).

The repository describes itself as a "Flood-Detection Dashboard" that is "designed for real-time drainage sensor networks." Read that description carefully and the ambition is modest. It is a dashboard. The cleverness lives in the classification underneath it, not in the interface on top.

What iot-full Actually Is

Set expectations before the praise. This is a full-stack prototype with one contributor, six commits, and no license. The sample data is set in Kochi, Kerala, with node names like Marine Drive, MG Road Junction, and Kaloor Stadium. There is no hardware. A set of Python scripts simulates the sensors and pushes readings into Firebase.

So it is a teaching artifact and a template, not a product. That framing is not a knock. It is what makes the classification rule worth reading on its own terms, separate from the scaffolding around it.

The Rule That Separates a Flood from a Blockage

Everything runs off a single constant. The pipe is modeled as 2.0 metres tall, and a reading in centimetres is normalized against it. Three lines divide the range into four states.

StateWater levelFlow rateMeaning
NORMALbelow 1.0 manyPipe is clear
WARNING1.0 to 1.5 manyPipe is filling
FLOODat or above 1.5 mabove 2.0 L/minDrain is overwhelmed
BLOCKAGEat or above 1.5 mat or below 2.0 L/minSomething is stuck

The WARNING band is where the value is. A pipe between half full and three quarters full is not yet in trouble, but it is the window where a slow blockage announces itself. A system that waits for the critical line to fire has already spent the lead time it needed to react.

Drag the probe or move the sliders. Above the 0.75 times H line, flow rate decides whether the state is FLOOD or BLOCKAGE at the same water level.

The diagram is the whole rule. Push the water level above the critical line with a low flow rate and you get a BLOCKAGE; raise the flow and the same height becomes a FLOOD. Two readings, four states, no ambiguity. The physical pipe sketch on the side keeps the abstraction honest, because the point is always about water in an actual drain.

A black-ink close-up of a single pipe junction split into two halves. The left half shows water surging through and out of a grate with long tight flow arrows and no debris. The right half shows the same pipe with water backed up and nearly still, short broken flow arrows, and a plastic bottle and a mat of leaves wedged at the throat. It illustrates the article's thesis: identical water level, opposite cause.
Same pipe, same water level, opposite cause. Flow rate is the only reading that tells the two apart.

Two Databases, One Pipeline

The project splits its storage across two Firebase products on purpose. The Realtime Database holds the current state of every node at a path like sensors/{node_id}, optimized for cheap, low-latency reads. Cloud Firestore holds the append-only history at sensor_history/{node_id}/records/{auto_id}, optimized for querying the past.

The split is sound. "What is it now" and "what was it an hour ago" are different questions with different access patterns, and using the right store for each avoids overloading either one. History queries filter on ISO-8601 timestamp strings, which works cleanly as long as every writer agrees on the format and timezone.

query = ref.order_by("timestamp", direction=direction)
if start: query = query.where("timestamp", ">=", start)
if end:   query = query.where("timestamp", "<=", end)
query = query.limit(limit)

The fragility is in the writes. The simulators update both stores inside the same loop with no transaction. If the second write fails, the live view and the history disagree, and nothing reconciles them. For a demo this is fine. For anything with real sensors, it is the kind of gap that produces two teams looking at two different truths.

Streaming Without a Broker

The backend does not run a message broker. It polls Firebase instead. The /stream route opens a Server-Sent Events connection and, every three seconds, reads the full sensor map, serializes it, and pushes it downstream only if the string changed.

@app.route('/stream')
def stream():
    def event_stream():
        last_data = None
        while True:
            sensors = get_all_sensors()
            current_json = json.dumps(sensors, sort_keys=True)
            if current_json != last_data:
                last_data = current_json
                yield f"data: {current_json}\n\n"
            time.sleep(3)
    return Response(event_stream(), mimetype='text/event-stream')

Three design choices ride along with this. Each connected client gets its own poll loop, so read volume scales with the number of open dashboards. Change detection is done by comparing serialized JSON, which is simple and correct but re-reads everything on every tick. And because nothing is sent when nothing changes, there is no heartbeat, so a dead connection looks exactly like a quiet network.

The deployment config matches the design. Gunicorn runs with the gevent worker class, so each long-lived stream is a greenlet rather than a blocked thread, and the worker timeout is raised to 120 seconds to keep those connections alive. It is a coherent set of choices for a small number of viewers.

There is one frontend bug worth naming. The data hook sets src.onerror to close the EventSource. The browser would normally reconnect on its own after a transient error. Closing it permanently means a single network blip, or a backend restart during a deploy, freezes the dashboard until someone reloads the page, with no on-screen sign that the data has stopped.

A Prototype, Honestly

A project earns trust when it tells you what it is not. Here is the list.

GapWhereWhy it matters
Exceptions swallowedget_all_sensors() returns {}A database outage looks like an empty city
Committed credentialsserviceAccountKey.json in the treeAnyone with the repo has the keys
Workflows misplacedbackend/.github/workflows/GitHub Actions will not find them there
No testsThe pytest step is a no-opNothing catches regressions
Dual writes, no transactiondemopush3.py and demopush4.pyLive state and history can diverge
Reconnect disableduseSensorData.js onerror closes the streamOne network blip freezes the dashboard

None of these are exotic. They are the difference between a prototype and a system you would put in front of a city. The classification rule is the good idea. The scaffolding around it is a starting point.

Where It Sits in the Field

The open-source IoT landscape is crowded, but it is crowded at different layers. Tasmota is firmware. EMQX is a broker. Node-RED is a flow editor. ThingsBoard, OpenRemote, Home Assistant, and openHAB are platforms with device management, plugin ecosystems, and years of production hardening.

ProjectLayerData storeRealtime transportDomain logicProduction readiness
iot-fullDashboard + domain logicFirebase RTDB + FirestoreSSEFlood vs blockage rulePrototype
ThingsBoardDevice and data platformCassandra + PostgresMQTT + WebSocketGeneric rule engineProduction
Home AssistantHome automationSQLite + PostgresWebSocketAutomation rulesProduction
Node-REDFlow integrationStatelessWebSocketUser-built flowsProduction
EMQXMQTT brokerBuilt-in storeMQTTNoneProduction
OpenRemoteAsset managementPostgresMQTT + WebSocketWHEN-THEN rulesProduction
openHABHome automationMultiple backendsSSE + WebSocketRulesProduction
iot-full (verified deployment)None foundn/an/an/an/a

iot-full does none of the platform work. It has no device management, no broker, no plugin system, and no verified deployment. What it has is a domain-specific classification layer that the general platforms leave to you to build. That is a design decision, not a deficiency. It also means the interesting comparison is not feature count. It is whether the classification rule is worth copying, and it is.