The following article is about coding, to allow users to display live stats from the National Grid on a WordPress site, rather than directly related to wind, so please be warned, you may find this post boring if coding is not an interest. 😉

Leo from GridWatch has kindly provided me with initial code that will query the GridWatch database then output the results on a page. I have modified the code so that it can be used on a WordPress site on a sidebar.

Since PHP is not a language I know fully in-depth, I have not as yet turned the code into a stand-alone plugin widget, but I will be working with others to try and improve the basic code and reacquainting myself with the PHP language.

For now though, if you would like to replicate the code and have the stats appear on your site, please follow the following steps;

Step 1 – Installing the Plugin

We need to install a plugin into your WordPress installation that will allow you to insert and execute PHP code from your sidebar. For this I used the plugin: PHP Code Widget by Samuel Wood.

In your WordPress Dashboard, go to Plugins > Add New

Search for the PHP Code Widget, install and activate.

Step 2 – Adding the Code

Once the plugin is installed and activated, go to Appearance > Widgets

On the widgets page, drag the widget PHP Code into your sidebar. Give the widget a title, and make sure that the box for ‘Automatically add paragraphs‘ is selected.

Next copy and paste the following code into the widget;

[php] <?php
$retval=file_get_contents(‘http://gridwatch.templar.co.uk/downloads/nationalgrid’);
$results=explode("\n",$retval);

print "<h4>UK Demand = $results[12] MW</h4>\n";
print "<strong>Wind</strong> $wind= $results[5] MW\n";
print "Nuclear $nuclear= $results[4] MW\n";
print "Coal $coal= $results[3] MW\n";
print "CCGT $ccgt= $results[0] MW\n";
print "Hydro $hydro= $results[7] MW\n";
print "Pumped $pumped= $results[6] MW\n";
print "French ICT $coal= $results[9] MW\n";
print "Irish ICT $irish= $results[10] MW\n";
print "Dutch ICT $dutch= $results[11] MW\n";
print "EW ICT $ew= $results[14] MW\n";
print "Oil $oil= $results[2] MW\n";
print "OCGT $ocgt= $results[1] MW\n";
print "Bio $bio= $results[8] MW\n";
?>

Live data from the National Grid is provided courtesy of <a href="http://www.gridwatch.templar.co.uk/">GridWatch</a>
[/php]

I’ve added a couple of HTML tags into the code as an example of HTML formatting that can be applied to the code. This can be further modified with CSS styles to improve the visual layout of the data.

Please keep the link to GridWatch in the widget as the site allows for more data comparisons to be made, including downloading historical data, and most importantly, GridWatch gave me the initial code I would need to query their database, so they deserve most of the credit.

Limitations & Future Development

Currently when a page is loaded that contains the widget code, it will show you the latest data parsed from GridWatch, however, unlike the GridWatch site, the data will not automatically refresh itself. The data will only be refreshed if a user manually refreshes the page or visits another page on the site that contains the code.

I will be modifying the code further, so that it can be launched as a downloadable, stand-alone widget, to make it easier to implement in other sites. This will take some time as I will have to reacquaint myself with the PHP language. However, the end goal and functionality for the widget will be;

Admin interface to allow generation types to be selected for display

Use jQuery & AJAX to allow the data to be auto-refreshed at timed intervals

I have no idea when this will be achieved, but I’ll keep people that are interested updated. There is also another programmer that is interested in helping develop this as a widget, so we will just wait and see what happens, and as soon as we have a working model ready, we will provide it as a free download for others to use.

Featured Image: by Idaho National Laboratory and released under a Creative Commons Licence


0 Comments

Leave a Reply

Avatar placeholder

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