Skip to main content

Flood Alert - Part 8: Code & Data Guide

by Hey Jude

Flood Alert (Environmental Agency, UK) API

The Environmental Agency in the UK runs an API to provide data on Fluvia (rivers) and Pluvial (surface water) data.

Environmental Agency Website

If you navigate to this link, you’ll find it looks like the images below, for Waltham Forest’s Lee Tributary area. You can toggle the Rainfall data points on/off, and also River, Sea, and Groundwater. As mentioned in this project, these are good as a ‘proxy’ but for many people in urban places (or far away from a monitoring station / datapoint) it may not be enough.

Flood Alert Map

Finding Your Local Data

This is the easiest way to find out your flood area but there needs to be an alert or warning at the time:

You can get all the flood warnings in the UK in your browser by visiting the following URL: https://check-for-flooding.service.gov.uk/alerts-and-warnings

Click on the warning you are interested in for example Keswick Campsite: https://check-for-flooding.service.gov.uk/target-area/011FWFNC6KC

The last part of the URL above is the flood warning area code in this example it is 011FWFNC6KC

Check for flooding map

If there is no flood warning for your area you can find the url from your Lat / Long coordinates. For example, Witney in Oxfordshire has lat: 51.7859° N, long: 1.4851° W North is positive, West is negative.

Put these into the following URL:

http://environment.data.gov.uk/flood-monitoring/id/floodAreas?lat=y&long=x&dist=d

Where: y is the lat, x is the long and d is the distance in km from your location. Start with close distances and use larger values if you don't get any results.

Find your coordinates here.

Latitude and Longitude locator

Only 4 decimal points are needed, (not 6), so shorten accordingly…

So for Witney, the URL is (Note the negative W coordinate): https://environment.data.gov.uk/flood-monitoring/id/floodAreas?lat=51.7859&long=-1.4851&dist=0.5

Paste this into a browser and you will get a list of possible Flood Areas.

Here's the result for Witney:

 "items" : [ { 
    "@id" : "http://environment.data.gov.uk/flood-monitoring/id/floodAreas/061FWF10Witney" ,
    "county" : "Oxfordshire" ,
    "description" : "River Windrush at Witney and Ducklington down to and including Hardwick" ,
    "eaAreaName" : "Thames" ,
    "floodWatchArea" : "http://environment.data.gov.uk/flood-monitoring/id/floodAreas/061WAF10Windrush" ,
    "fwdCode" : "061FWF10Witney" ,
    "label" : "River Windrush at Witney and Ducklington" ,
    "lat" : 51.75773 ,
    "long" : -1.45314 ,
    "notation" : "061FWF10Witney" ,
    "polygon" : "http://environment.data.gov.uk/flood-monitoring/id/floodAreas/061FWF10Witney/polygon" ,
    "quickDialNumber" : "171073" ,
    "riverOrSea" : "River Windrush"
  }
  , { 
    "@id" : "http://environment.data.gov.uk/flood-monitoring/id/floodAreas/061WAF10Windrush" ,
    "county" : "Gloucestershire, Oxfordshire" ,
    "description" : "River Windrush from Bourton to Newbridge including Burford, Asthall, Minster Lovell, Crawley, Witney, Ducklington, Rack End and Standlake" ,
    "eaAreaName" : "Thames" ,
    "fwdCode" : "061WAF10Windrush" ,
    "label" : "River Windrush from Bourton to Newbridge" ,
    "lat" : 51.82888 ,
    "long" : -1.65351 ,
    "notation" : "061WAF10Windrush" ,
    "polygon" : "http://environment.data.gov.uk/flood-monitoring/id/floodAreas/061WAF10Windrush/polygon" ,
    "quickDialNumber" : "171075" ,
    "riverOrSea" : "River Windrush"
  }

Use the "description" key to find the nearest area to you and then take the "@id" url for that area.

For example: "@id" : "http://environment.data.gov.uk/flood-monitoring/id/floodAreas/061FWF10Witney"

Now take the last part of the "@id" url which is the key for that area, in this case "061FWF10Witney"

In Arduino. With the main ‘ino’ file opened up - which will in turn open up all the other relevant sub-files/folders; Copy and paste the key into the magnet_config.h file:

// Your flood area code from Gov.co.uk Flood Warning Service

#define AREA_CODE "061FWF10Witney"

Arduino Code

Safe to say add your WiFi credentials. Save the File.

Pre-Upload Test (optional)

You can test the API for your flood area by making a request in your browser to the following URI: http://environment.data.gov.uk/flood-monitoring/id/floods/{your-flood-area-code}

So in the example above for the Witney use this URI: https://check-for-flooding.service.gov.uk/target-area/061FWF10Witney

At the time of writing up, Witney was not having a flood alert, so had no output.

However, Lee Valley did, and here’s what it looks like:

https://environment.data.gov.uk/flood-monitoring/id/floods/062WAF53LLTribs

Producing this:

Pre-Upload Test

This will return a JSON object with all the flood information for that area.

 

Display Output

The Flood Alert polls the API at the frequency you set and it receives the API response and displays the following data:

An icon representing the flood warning which may be at one of four possible severity levels - derived from the severity level:

Display - severity levels

Level Name Meaning:

Severe Flood Warning Severe Flooding, Danger to Life.

Flood Warning Flooding is Expected, Immediate Action Required.

Flood Alert Flooding is Possible, Be Prepared.

Warning no Longer in Force The warning is no longer in force

The update date / time - derived from timeRaised (The date and time the warning was last reviewed. Usually (but not always) this leads to a change in the message or severity)

Config

User config is in "flood-alert_config.h"

Arduino config

Adding your / your user’s location details in AREA_CODE as described above.

WiFi Data

If you are doing a SIM Card-based WiFi, these should be printed on the back of the Dongle (blacked out here).

SIM Card and WiFi Dongle

With this all done, hit ‘upload’ and ‘verify’ on your Arduino.

Demo Mode (optional)

Hold down the Demo button and press the Reset button to enter Demo Mode. Press Reset again to exit back to Standard Mode.

This Demo Mode works without WiFi and is frankly more something I need for explaining how it works to people, or indeed, as a few of my projects have ended up in an exhibition, you never know when you need it to run through what it does (without actually being a flood). Thanks!

Collaboration

Jude and Pete with Flood Alert

Thanks for taking part in this project, and also may I say thanks again to Pete Milne for his amazing work on this project and excellent work on GitHub, as well as significant input and sparring in the design phase. It’s been a pleasure and an honour. Thanks Pete!

mceclip0_c5b2ecdcd604598d3d6ad2d6ad8185d9ec1deff3.png

Blog Series Contents:

Prologue - The Case for 'Hyper-Localisation' of Civic Data

Research & Development:

Part 1: Filling the Local Data Gap
Part 2: Civic Services & User Experience Research
Part 3: Ideation of Flood Alert Concept
Part 4: Prototyping Back-Story
Part 5: Citizen Science Learnings

Open Source Build Guide:

Part 6: Build Guide for 3D Printed Assembly
Part 7: DIY Decals for 3D Prints
Part 8: Code & Data Guide

Future Ambitions:

Part 9: Project Reboot with Machine Learning

Winner of the 2020 Alastair Graham-Bryce "Imagineering" Award (IMechE), Jude thrives in high risk collaborations, uncertainty and pressure - drawing from global networks and experiences to deliver high profile campaigns and digital/physical products. A leading Creative Technologist & Physical Prototyping Expert, Jude has worked for NHS, Dyson, LEGO, and a number of start-ups. He is one of the eight featured inventors in BBC Two's Big Life Fix. More at: https://www.judepullen.com/
DesignSpark Logo

Enjoying DesignSpark?

Create an account to unlock powerful PCB and 3D Mechanical design software, collaborate in our forums, and download over a million free 3D models, schematics, and footprints.
Create an account

Already a DesignSpark member? Log In

Comments