A blog post especially for my friend Tom.
I have a very minor interest in a cooperative wind farm based in Lincolnshire, who kindly publish the current site wind speed on their website. It’s useful, but there is no historical data so it’s hard to know whether it’s a good day for power generation or whether last week was better or worse than normal. Time for an inelegant but effective approach using a bit of scripting and cosm
Here’s how:
The wind farm website displays the data in an iframe, so first I had to find the URL that pointed to the source. Easily done, right click -> this frame -> view source and make a note of the URL and have look at the code to see where/how the actual wind speed is displayed.
Armed with the above knowledge create a script that will grab the url and using a bit of regex extract the wind speed. I used PHP as I had the code ready to go from a similar project I’d done in the past. Choose what works for you.
Next push the data up to cosm. Register as a user if you haven’t already, create a feed, add a data stream and grab the API key.
Originally I had planned to to use MQTT and I’m already user of Mosquito. There is a well written howto, but I couldn’t get this to work and didn’t have time to investigate. So plan B was to use the standard API, which has served me well for sometime. The standard API simply requires the construction of a curl request that includes your API key, feed number, and the data itself.
The regex and curl request are then glued together with shell script. A cron job then executes every fifteen minutes which I felt was a sensible resolution and hopefully won’t upset the web site owners too much with my regular requests for data.
The results can be seen here.
I freely admit this is not the most efficient way of coding this. With more time I would have written the whole thing in PHP or a single shell script, but it was quick to do and it works. Sometimes a hack is all you need…





