Flash-flood forecaster on the edge gateway
The gateway predicts the water level 3 hours ahead from rainfall and level history, so the park team and DOE are warned before the lake overflows, even while a thunderstorm has cut the 4G link.
Node LAKE-N03 · Spillway · simulated time (MYT)
--
Water level and rainfall: last 6 h and next 3 h
The “4G” strip at the top shows when the link was down. Readings taken then sit in the gateway's SQLite buffer and are sent oldest first when the link returns.
Warning time gained
--
Latest reading
--Alert log
Rows as stored in thealert table| Reading time | Source | Severity | Value | What happened | Sent to SNS |
|---|
The forecasting model
A linear model predicts the level change every 5 minutes from recent rain and the current level. It starts from a fit to 30 days of archived readings and re-fits itself after every new reading (recursive least squares), so it adapts if the inlet silts up or the spillway is cleared.
How this fits Deliverables 1 and 2
Where it runs
- A Python service on the Raspberry Pi gateway, beside the existing threshold check. It reads
local_readingfrom SQLite, so it keeps forecasting with no internet. - If a flood is forecast while 4G is down, the gateway switches on the park's warning lights at once and queues the alert. Alerts are sent before buffered readings when the link returns.
- Lambda re-runs the same model in the cloud on synced data, as it already does for threshold alerts.
Schema changes
alert.sourcegains a third value,FORECAST. For these rowsmeasured_valueholds the predicted peak.- New table
flood_forecast:forecast_id,node_id(FK),issued_ts,predicted_peak_cm,predicted_peak_ts,minutes_to_critical,model_version,error_cm. - The 130 and 145 cm limits are
alert_thresholdrows forWATER_LEVEL, not values in code.
Backlog items covered
- ID10 AI predictions: trained on the readings archived in S3.
- ID04 Water level trends: uses
water_level_cmandrainfall_mm. - ID02 Automated alerts: warns before the threshold is crossed, not after.
- ID07 Outages: forecasting and local warnings work offline.
All data on this page is simulated by a water-balance model of a 4-acre lake (about 1.6 ha) fed by a 26 ha park catchment. On site, rain ahead is unknown, so the forecast assumes the current intensity tapers off with a 30-minute half-life. MetMalaysia radar nowcasts could replace that assumption later.