Tuesday 29 September 2015

The Weather System

My weather server is a Linux (Ubuntu) server configured with Apache2.


The server runs 24/7 as a high-availability system.  I also have a test server running on a VM (VirtualBox) on another machine, and it's saved my bacon more than once.


The server system as a whole is comprised of a number of programs which interact with one another.  For example, there is wxOCR (a GUI program, which I'm going to have to rename before open-sourcing it), which captures local data from an LCD panel.  When it rains, the system knows it and automatically appends a second condition (Rain)  to the sky condition.  Every five minutes, a cron job fires off another suite of programs which capture information from the web--statistics, records, forecasts and normals from 27 locations.  Another GUI program captures the webcam image and deduces the sky condition from it.  These all feed into the server system.


The server captures data as it comes in, after a short delay to eliminate file collisions. Each location has an independent database which tracks all data. Pages are updated every five minutes from templates.


The template language is fairly simple and yet highly complex.  Housed in <@ > tags, there are thousands of tags for data-output; every statistic tracked by the database can be output in this way.  Optional suffixes, separated by colons, control the way the data are formatted (including alternate measuring units, dependent upon the source data), and the source itself (any tag can pull data from any location, allowing multiple locations' data on one page).  There are loops and constants, to make it easier to show ordered data (hourly, daily, monthly, yearly). Essentially, the weather engine is acting as a HTML pre-processor.


A number of tags can be used to pull statistics from the system, as you'll see on the Diags page.  In addition, a number of control parameters can be set and modified using a system configuration file.


A number of queries are possible, from raw data to webcam archives and even recalculation of the database from source readings (not as relevant now that the system is working properly).  Extra web pages allow input of daily statistics and a second sky condition (ie; Cloudy, Snow).


Graphics are another big part of the system. Both canned graphics and on-the-fly charts are used.  A special facility allows such graphics as wind direction to be displayed.

The system also maintains an events database (meant for astronomical events, seasonal markers and time changes, but applicable to anything, really) and associated output tags. Events can be listed forward and backward in time.

The entire system is written in a modern, OOP version of Pascal, known as Lazarus, which includes an IDE. It compiles to native code.
Given Lazarus' write-once, compile-anywhere philosophy, I could come up with a version for Windows in about 15 minutes; I prefer Linux for its stability and open-source tools. Pascal is not that different from Java or C; in fact, in my last job, as Java Developer, on my first day I hadn't written a line of Java code.  By the end of the day I had designed a page and underlying services, with the help of Apache Tapestry, a GUI add-on for Java. But I digress.

Bugs are tracked through Bugzilla, and the source code is backed up on a Subversion server.  Both of these are also on the weather server itself.


The project consists of about 20,000 lines of source and is slowly growing to the point where it's difficult for one person to maintain.  This, too, will be open-sourced eventually.


You've got to see it to truly understand.  It's available at 

http://mizar64.dyndns-home.com:64180/weather.html.

-Bill