ESP8266 + 4 Digit Display = Dam Percentage Monitor

We have recently got a lot of rain where I live in Central Queensland. I was returning home and only just made it passed Theresa Creek before it overflowed. This rain is welcome as the local dam (Fairbairn Dam) has been at historically low levels.

Emerald is prone to flooding and the town has flooded before. Although recently our main concern has been about running out of water with the dam recording the lowest of 7.39% on the 16th of December, 2020.

Over a year ago I made an IOT Clock and built and printed a case for it. It had be laying around unused and I decided to repurpose it.

It consists of a MAX7219 4×32 Dot Matrix Display Module and a ESP8266 module. In this case I used a Wemos D1 Mini that I had lying around.

I discovered that https://storagelevels.sunwater.com.au/win/reports/win_storages.htm has an internal API for querying storage levels.

Sun Water
var Url = 'https://data.sunwater.com.au/api/Sites/' + model_file + '/data?startDate=' + start_date;	//2019-03-24T02%3A24%3A44.003Z

function getData() {
    $.get(Url, function (data, result) {
        for (var i = 0; i < data.value.length; i++) {
            var temp = data.value[i];
            var temp_time = new Date(temp.date);
            var temp_time2 = temp_time.getTime() - (temp_time.getTimezoneOffset() * 60000);
            series_0.push({x: temp_time2, y: temp.storageLevelMetres});
            series_1.push({x: temp_time2, y: (temp.cubicMetersPerSecond * 86.4)});
            series_2.push({x: temp_time2, y: temp.percentageFull});
        }

        if (data.continuationToken) {
            token = encodeURIComponent(data.continuationToken); //console.log(token);
            Url = 'https://data.sunwater.com.au/api/Sites/' + model_file + '/data?startDate=' + start_date + '&continuationToken=' + (token);
            getData();
            return;
        }
        chart2 = new Highcharts.Chart(chartOptions);
    });
};

getData();

This is a recursive function that queries the Sun Water API and adds data to arrays. The “continuationToken” indicates if successive queries should be made to retrieve more data.

Using this code snippet and another section in the code that deals with time for the queries I was able to quickly throw together a micro service running on NodeJS and ExpressJS.

I used JavaScript to right pad the percentage levels and remove the period in between the numbers. An setInterval() call in JavaScript polls the Sun Water API every minute and updates the internal variable which holds the percentage.

The API call is here: https://planthe.work:3000/percentage

It returns a plain text response such as “1936”. This equates to 19.36%.

The code for the ESP8266 is very simple and just iterates over each number and draws it on the Dot Matrix supply. WiFi connection is done using a WiFi manager library. I used the ESP HTTP Client to connect to my micro service.

Here is the result:

It’s all quite simple. But it’s a cool example of a Full Stack project that includes manufacturing, electronics, networking and backend programming.

The Git repository is here.

Leave a comment

Your email address will not be published. Required fields are marked *