Home

Welcome! Log in or Join us

call: 1300 889 851

Weather station + SEG API = SEGWeather!

published, Sep 18, 2010 11:16pm
views (1367)

Around a year ago I purchased an inexpensive weather station from Jaycar - a "Thermor" branded DG950R Weather Station. I knew it wouldn't be the most accurate piece of equipment on the market at only $80, but i figured it would be "close enough" for the purpose of keeping some basic records of the local weather.

created on: 09/20/10

The station consists of a wind vane, anemometer and a rain bucket, connected with telephone cable to a battery powered thermometer and transmitter which transmits the wind, rain and temperature data to an indoor display.

I had hoped the four pin telephone socket on the side would allow me to connect a PC to the display for recording the weather data, however with no documentation, limited skill and some lengthy playtime with a serial cable, I soon realised that the socket on the side could well be just for aesthetic purposes!

Then I read about Jon Oxer's book "Practical Arduino" and a project which used an Arduino and RF receiver to pick up the signal from a LaCross weather station. After weeks of hacking (including capturing the data from my weather station with a PC soundcard and decoding it by hand!), I had built an Arduino shield which received the weather station's signal, decoded it and dumped the data to the USB/serial interface.

created on: 09/19/10If you want more info on the Arduino shield and sketch, head over to my personal blog to read more.

The next thing to do was to report this data somehow and somewhere. I wanted to be able to check the weather when I was at work, away from home etc, so I needed to display it somewhere on the web.

I tried wfrog, however this was an end-to-end solution (it connected to specific weather station receiver via USB and captured data and rendered web pages) and didn't support my weather station. I did try and connect the wfrog interface to my data source (MySQL) however it was not very successful.

I then discovered SEG whilst researching energy monitoring, and noticed a "Weather station" device in "My things". The SEG widgets and graphs looked very cool, so I contacted Sam for some info on using SEG's API. Within a few hours Sam had pointed me to some doco outlining how to use the API.

The data coming from the Arduino that I would need to send to the SEG API looks like this:

TEMP,190,12.6
WIND,190,WSW,8.19
RAIN,190,0.00 

 

The "190" in the data is the station ID, and the rest should be self explanatory. I quickly wrote a script on my ubuntu server (which the Arduino and weather receiver shield is connected to) to read the data from the USB (serial) port and send it to the SEG API. I used PHP for this as I already had some code lying around for the serial reading. The basic nuts and bolts of it look like:

<?php
  $fp = fopen("/dev/ttyUSB0", "r");
  while($serial_data = fgets($fp)) {
    $data = explode(",", $serial_data);
switch($data[0]) { case "TEMP": $data_string = "data_post=(site site_e45ed23a (node weather ? (temperature {$data[2]})))"; break; case "RAIN": $data_string = "data_post=(site site_e45ed23a (node weather ? (rainfall {$data[2]})))"; break; case "WIND": $wind_speed_ms = round($data[3] / 3.6, 2); //convert km/h to m/s switch($data[2]) { case "N": $wind_direction_degrees = 0; break; case "NNE": $wind_direction_degrees = 22.5; break; ... }
$data_string = "data_post=(site site_e45ed23a (node weather ? (wind_direction {$wind_direction_degrees}) (wind_speed {$wind_speed_ms})))"; break; }
$url = 'http://api.smartenergygroups.com/api_sites/stream'; shell_exec("/usr/bin/curl -s -d '{$data_string}' {$url}"); } ?>

 

This script runs 24/7, reading the data from the serial port and sending it to the SEG API every 90 seconds or so. I then whipped up a simple dashboard on SEG to show me the weather: https://smartenergygroups.com/widgets/f50b243461e4393

A big thanks again to Sam for all his efforts putting SEG together, and for helping me along the way to get everything working on the SEG side. Cheers!

Add Your Comment!

Log in to leave a comment or Create an account

Nice work Kayne!  Great to see your persistence has paid off getting your weather station internet communicatable.

Sam.

@samotage

Im trying to do much the same type of thing with PHP and serial port to MySQL database. I am running Ubuntu and cant seem to figure out how to get the permisions right. Who did you add to what group?

John

Nice home made setup. If you want to use wfrog with your custom work, your script just has to issue events like this: http://code.google.com/p/wfrog/wiki/WeatherStationEventProtocol?show=content#Example either on standard output (and piped into wfrog) or http-posted to a wfrog instance.

» All comments
» Comments RSS

copyright © 2013 Smart Energy Groups pty ltd