Installing a USB Weather Station on a Raspberry PI part 2

In the first article I covered how to install a weather station on a Raspberry PI. In the second part I’ll cover how to get it to upload data on an hourly basis to a website using FTP.

Getting the station to run hourly

First we need to get the station to run hourly. To do this I created a script called weatherupload which I placed under /usr/local/bin

pi@kell: ~$ sudo vi /usr/local/bin/weatherupload

Enter the following:

#!/bin/bash
cd /usr/local/weather
python Hourly.py -vvv data

Once saved make it executable and then edit the main crontab:

pi@kell: ~$ sudo chmod +x /usr/local/bin/weatherupload
pi@kell: ~$ sudo vi /etc/crontab

At the end of the file you need to add the following:

0 * * * * root /usr/local/bin/weatherupload

Save it and now every hour it will now run.

Note: I’ve placed it there and not under /etc/cron.hourly because

  1. cron.hourly runs once an hour, but not necessarily at the top of the hour. I a later article when I add twitter you want the tweet to be close to 0m rather than at a random time.
  2. I’ve found in the past that using crontab -e doesn’t always work, even for root but in the core crontab it just works

Uploading to a website

First to generate the graphs pywws uses gnuplot so we need to install it:

pi@kell: ~/sudo apt-get install gnuplot

Next we need to add some details to the stations weather.ini file. At the top theres a section called paths. Make sure those point to the relevant templates and graph_templates directories in your pywws install.
Next under the hourly section you should see a pair of lines:

plot = []
text = []

You need to add the plots and pages that need to be generated:

plot = ['7days.png.xml', '24hrs.png.xml', 'rose_24hrs.png.xml', 'rose_7days_nights.png.xml']
text = ['current.html', '24hrs.html', '6hrs.html', '7days.html', 'feed_hourly.xml', 'allmonths.html']

Finally theres the ftp section which needs configuring with the remote ftp server (your web host will give you these):

[ftp]
secure = False
site = ftp.example.com
local site = False
user = myaccount@example.com
directory = /weather/
password = mypassword

That’s about it. Now when you run the hourly script it will generate some simple pages & images to your website.

You can see an example of this over at maidstoneweather.com – although the uploaded templates only form part of that site.

Author: petermount1

Prolific Open Source developer who also works in the online gaming industry during the day. Develops in Java, Go, Python & any other language as necessary. Still develops on retro machines like BBC Micro & Amiga A1200

27 thoughts on “Installing a USB Weather Station on a Raspberry PI part 2”

    1. In theory it should be. Your main issue will be power, primarily the Pi itself and the 3G dongle.

      The station uses AA batteries for the instrumentation & the base station but they do last. I should replace mine at some point as it’s almost 2 years on the original batteries. Tip: the base station uses usb power when connected & switches to its own batteries when usb power is lost. Also for some of the higher end stations they have an option of the instrumentation to recharge with a solar panel on top – should be an easy conversion.

      As for the Pi, it uses just above 700mA for itself and although I don’t know what a typical 3g dongle uses when I used to use one on a netbook it did cause the battery to drain. More so if in a weak 3g area.

      Saying that as there are custom weather stations available with on board 3g it must be solvable – perhaps if a dongle is causing power consumption issues then a dedicated 3g/gprs module might be better as they tend to have a low power mode. I’ve seen some on farnel from £38, similar on Ebay.

      So in short: yes it should be doable, you just need to ensure you have enough power from the solar panels to supply the pi & 3g.

  1. Peter this is really nice application for the Rpi. I’m going to replace the scripts you wrote above with my automation solution that can run on the Rpi now. It’s certainly a bit overkill for this project but it allows me to demonstrate how we can build significant process workflows across embedded devices or the like. E.g., Rpi.

    1. It’ll be interesting to hear how you get on. The RPI should cope, its surprising how they cope – the weather station was originally on a full sized Linux box (before it died) & the RPI has just worked with less maintenance.

      In fact the only major thing I’ve done to it was to enable SNMP.

  2. Hello , im comming from holland , end enjoy your project , how i can run pywws conversions , end add to witch map ? greets fer ,

    1. Sorry for late reply. Which map are you trying to add to?

      Looking at the templates the ycalc element is a python expression so you should be able to just call the conversions functions in there. Not tried it myself but thats the theory.

    1. Sorry for the late reply, the day job’s been getting in the way.

      weather.ini usually goes into your stations data directory. Once there you just put in the basic config then it will fill in the rest.

    2. create /data/weather.
      use this command ‘python pywws/LogData.py /data/weather’

      That will create your weather.ini file.

  3. Hello, verry nice Tutorial, thank you verry much for it …

    i’ve found the .ini file in /user/local/weather/data and edited it as shown above,

  4. Hello, I am novice here.. and sure don’t understand much of python nor other raspberry language. I am just following your tutorial step by step to get it done.

    Now, to reach what I want, I need to ask you two questions:

    Is it possible to upload to my website just the values of the weather station in a .txt or .shtml file so then my php functions deal with them as raw info? Like in strings or something?

    If so, how do I directly upload it by ftp in raspberry? I already arranged username and password to this situation.

    Regards

  5. Hello, very good tutorial. If i want to send the data upto http://www.underground.com where i have my weather station registered. What and where do i place my settings on the pi. To get the data upto the website via a pc i have to input the weather station ID and the Password in the program that came with the station for the PC. (EasyWeather).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: