Doing searches on the Internet I quickly found WeeWX, an open-source project that does all of this. It reads sensor data, generates a web page, and can optionally log to WeatherUnderground. I was ready to go with this option, but then I discovered it was written in Python which gave me pause for concern (more on that later).
I next found wview which, like WeeWx, is an open-source weather station project. It's written in C which is good, but it sounds like the project has grown rather large over the years. It's become a huge behemoth that's capable of doing almost everything when all I want/need is a simple targeted application.
In the end I decided to write my own weather station application. After all, isn't that was software engineers do, write software? I wrote a small simple program that reads all the sensors and outputs the data in 3 different ways.
- It generates a local HTML file which can be viewed from another computer using a web browser. My code is not a web server, it just outputs an HTML file. So you still need a web server such as Lighttpd or nginx.
- It sends all sensor data off to WeatherUnderground so the results can be viewed on their web site.
- The sensor data is written locally to a SQLite file for later analysis.
I wanted to go back and talk about my opposition to the use of Python in WeeWX. The main problem is I do not consider Python to be a "real" programming language. It is a scripting language, and scripting languages have their place. But not in final applications in my opinion. I also do not like the extreme performance hit Python incurs. And remember, this is running on a Raspberry Pi which is not a powerful machine to begin with, so any unnecessary overhead is exaggerated. How much of a performance hit are we talking about? Using the sample Python code from Adafruit, reading the temperature sensor takes approximately 5 seconds. Most of that overhead is spent loading the Python libraries and creating the runtime environment. Compare that to the C++ code I wrote to read the temperature sensor which is instantaneous. To me writing this application in C++ was not only the only way to go, but it was a fun project!
I have uploaded my C++ code to GitHub for anyone to download, use, or modify. Bear in mind this code was written specifically for my weather station. So it assumes the sensor hardware I'm using connected to the Raspberry Pi on the GPIO pins I'm using. But this could be a great reference for anyone doing a similar project.
And finally, the results. Here's a link to my PWS on WeatherUnderground.
Excellent write-up
ReplyDelete