Weather Station Technical Detail


This page documents the weather station a little bit for the benefit of those taking over the project or otherwise involved with the project in the future. The station is a reasonably complex system and requires a decent understanding of its operation before work can be safely carried out. If you need any more information contact me at jon@hexoc.com.

The Hardware

The station is based around a PICAXE 28X1 microcontroller. This is in the control box on the station itself. The PCB was designed and made by us and is currently on rev.3. Information from the station is transmitted via the SGS LAN out to the internet and then to the weather station server, which is owned and run by Jon (hexoc.com).

The basic PICAXE functions are to wake up once every 15 minutes and read data from all the sensors. Some small amount of processing of the information is completed on the PICAXE before the data is sent to the server, but the operational model we adopt is to leave as much data processing as possible to the server. This is because changing code on the server is quick and easy, and it is significantly more powerful than the PICAXE.

The programme for the PICAXE is on github here: github.com/jonsowman/weather

The Sensors

  • Temperature: We have two temperature sensors; one in the white box on the station and one on long wires tucked underneath the station. These are Dallas 1-wire digital sensors, part number DS18B20. They are wired in active power mode and care must be taken to shrink wrap and insulate the electrical connections on the sensors.
  • Light: We have two light sensors. One is a simple LDR wired to an 8-bit ADC, the other is a photodiode. Since the photodiode has a massive dynamic range (from microvolts in the dark to a couple of volts in daylight). Due to this, a programmable gain amplifier is used. This amplifier has its gain set to 1, and an ADC reading is done. If the voltage is off the bottom of the ADC read, the gain is increased to 2, and the process is repeated. This continues until the ADC read is roughly in the middle of the ADC range. The ADC read and the gain values are sent to the server, which then converts this into a light value in Lux.
  • Wind direction: This is a continuous turn pot, and is simply ADC read and converted to a bearing by the server.
  • Wind speed: A spinner with a magnet on the spindle causes a reed switch to close once per revolution. The PICAXE counts the number of pulses in a 10-second period and sends it to the server, which converts the value to MPH.
  • Pressure: The pressure sensor is of Freescale analogue variety which is fed through a 12-bit ADC. The ADC read is sent to the server which converts the value to a pressure level in mb.
  • Moisture: The moisture sensor is a piece of stripboard, whose resistance changes depending on the water on its surface - this needs removing or replacing as it corrodes and becomes useless very quickly.
  • Humidity: This is currently non-functional. A humidity sensor needs to be implemented.

The Website

The website for the weather station is at weather.hexoc.com, and is written almost entirely in PHP. There is some AJAX/JavaScript that powers the "live" updating of the frontpage. The database engine is MySQL and the SQL server also runs on the Hexoc server. The code is mostly well commented and the best way to understand it is to have a good look through it and make sure you understand what each piece does.

All of the code for the weather station except config.inc.php (as it contains database access credentials) is available on github here: github.com/jonsowman/sgsweather-web. This code can be cloned to get your own copy, and I will give people access to the server who want to work on the website. You will also have access to a development server for testing things before they go onto the live site.

All of the website is kept under version control with "git", so you will need to learn the basics of git before you can work on the site. Version control is very important for a project such as this where lots of people are working on a rather large project.

The AJAX system is written in jQuery (a JavaScript framework) and contacts the server ('ajax.php') to check for updates and the times when updates are expected.

There are a few scripts and functions that deal with adding data to the database, namely 'add.php' and 'includes/functions.inc.php'. Most of the rest of the website deals with displaying the data and making useful things like graphs.

Data for the current and previous months are kept in the database and are archived into CSV files by a PHP script running under cron on the 1st of every month.

The admin interface contains useful configuration parameters for the station - these are shown and described below:

  • Last Update: This shows the IP address and rDNS entry of the place from which the last weather station update came from. If the request was forwarded to this server by another server (in this example, "pippin") it will be shown here. If the request came directly from SGS, this field will show "Direct Hit".
  • Clear Database: What it says on the tin. Be careful, you probably never want to do this!
  • Text on next update: The station is set up with the TM4B SMS gateway service, so it will text a configured number when it updates. You can buy 10 texts for about 80p, paid via Paypal, and is extremely useful when testing as you don't have to sit at a computer to make sure the station is still working.
  • Tweet on next update: Force the weather station to send a message to Twitter on next update.
  • Force Records DB update: This forces the server to trawl through all the past CSV archives to refresh the records page (here). Take heed of the warning.
  • Update status: allows changing of the STATUS message displayed on the station homepage.
  • LDR correction. The LDR value will be multiplied by this value before being displayed - can be used to bodge a dodgy LDR.
  • Photodiode Constant of Proportionality: The photodiode voltage is directly proportional to light level. This value can be set here.
  • Trackers: these files hold useful information from around the site:
    - Last hit: Where and when the last update to the station was
    - Last rejected reading: The server sanity checks the updates as they come in. If they fail, what reading and why it failed will be logged in this file.
    - Photodiode ADC and gain: The values of gain and ADC from the photodiode from the last update.
    - Station Time Vars and Pressure: From when we were thinking of getting the system to use the clock on the station itself. At the moment it uses server time, so this file is useless.
    - Pressure gradient and PMCC: Because it is rate of change of pressure that matters, this is a script that calculates the gradient and PMCC for the last 4 hours of pressure.
    - CWOP APRS String: From when the station used to update to Citizen's Weather Observers Programme. This is disabled for now.

External Websites

The station updates to twitter once every few hours. The times when it does so are in the config.inc.php file.