WeeWX Weather Station Post Install Configurations

So the WeeWX Journey Continues

(This is mostly written for me to remember things – and for anyone else going down this path)

WeeWX Logo

A couple of months back I posted about migrating my Davis Vantage Pro2 Weather Station from running WeatherCat software on a Mac Mini to WeeWX software on a Raspberry Pi. The solution has been working pretty flawlessly since then, but I haven’t had a lot of time to write the follow-up post about any customizations or configurations I made to make everything work the way I wanted.

In order to replicate the functionality I had with WeatherCat, I needed to (obviously) get things running with the base software, then look for a few extensions and write a few hacks. I strongly recommend that you read (and re-read) the User’s Guide – it is well written and will help get you up and running quickly. 

So if you follow the previous post, you installed the software on your Pi using apt-get. When installing you will be asked for your location (latitude and longitude), altitude (and units – feet or meters), what weather station hardware you are running, as well as specific parameters for your station hardware. These are pretty straight forward and created your /etc/weewx/weewx.conf file. You now need to get a few house keeping bits in order.

Post Install Configurations 

After validating everything is working, you need to verify that WeeWX is configured for running as a daemon at startup, setup the local web server (optional, but highly recommended). You should also set up rsyslog to put all the WeeWX logs in a dedicated file, this will help troubleshooting (trust me on this one).

To make sure that WeeWX is properly configured to run as a daemon (done automatically as part of the apt-get install) check to see that you have a file /etc/init.d/weewx – this file can be called with sudo /etc/init.d/weewx start|stop|restart at the command line. If this file exists, go ahead and test it out with a restart. As we haven’t updated rsyslog yet, you can check by looking in the /var/log/syslog file for weewx calls.

One of the beautiful things about WeeWX is you can run a local web server with a base weather website out of the box. You can do this in parallel of running more intricate web templates such as Meteotemplate, which I use to power my weather site.

If this is a Pi that doesn’t yet have apache installed, you should look at this guide. You don’t need to install PHP but it wont hurt either. Once you have apache up and running, try opening a browser and go to http://your-raspberrypi-ipaddress/weewx/ – you should have a basic weather site and graphs. If not, head back over to the WeeWX Install Docs and re-read them. Getting this bit right is critical to other use-cases, such as home automation, which will be covered in another post.

Getting rsyslog service configured is a snap! Simply use the configuration file provided as part of the install as follows. The first command creates a symbolic link to the rsyslog configuration file into the proper directory, the next two commands stop and start the logging service to read the new configuration.

sudo ln -s /etc/weewx/rsyslog.d/weewx.conf /etc/rsyslog.d
sudo /etc/init.d/rsyslog stop
sudo /etc/init.d/rsyslog start

If all goes well, and you have not changed the contents of the file above, you will have a new weewx.log file in /var/log containing all the output from WeeWX. You will most likely get to know this file very well over the first little while you run this 🙂

Tweeting Weather Reports

I have a twitter account for the weather station, and this is how I set up hourly tweets of current conditions. I am still working on daily reports for High/Lows, records set, etc.

The biggest hurdle I had was finding a command line interface for Twitter that could take a file as input for the tweet. After a lot of trial and error, I found Oysttyer which is a perl Twitter client. Follow the install instructions on the GitHub page, and then in order to enable long tweets (~280 characters) you need to edit the oysttyer.pl file. On line 660 change $linelength to 280 and on line 661 change $quotelinelength to 256. I installed Oysttyer in /home/pi/bin/oysttyer so if you install it in a different location change the information below accordingly.

You need to create a WeeWX template file, I simply added this to the Standard skin by editing the skin.conf file to include the following right before the CopyGenerator section of the file:

            encoding = strict_ascii
            template = twitterHourly.out.tmpl

And I created a twitterHourly.out.tmpl file with the following contents (edit to your liking) Keep this on one line:

Current Conditions for #Albrightsville PA\nTemp: 
$current.outTemp\nHumidity: $current.outHumidity\nBarometer: 
$current.barometer\nWind: $current.windSpeed from the 
$current.windDir.ordinal_compass\nRain Rate: $current.rainRate\n
Rain Total: $day.rain.sum\nSolar Radiation: $current.radiation\n
UV: $current.UV\nhttps://t.co/O5QrLrWXj9 
#weewx #nepa #nepaweather #poconos #poconomountains

Once I confirmed the twitterhourly.out file was being created in /var/www/html/weewx I created a cron job (as root) to tweet its contents 2m after every hour. Edit root’s crontab by typing sudo crontab -e at the command line and entering the following (update your latitude/longitude to your values!):

2 * * * *   /home/pi/bin/oysttyer/oysttyer.pl -location -lat=41.0081 
-long=-75.5362 -newline -script -status= < /var/www/html/weewx/twitterHourly.out

I did find that Oysttyer was not always closing cleanly and was leaving processes running, eating resources. I fixed this by using the following crontab entry (as root). I run this 15m after the hour to clean up and save resources.

15 * * * * /usr/bin/pkill -f oysttyer

The final output looks like:

Meteotemplate Setup

I use Meteotemplate to run my weather site, and WeeWX has an extension written by Matthew Wall to make getting the data over to the site a snap!

First, download the extension: 

wget -O weewx-meteotemplate.zip https://github.com/matthewwall/weewx-meteotemplate/archive/master.zip

Once downloaded run the installer:

sudo wee_extension --install weewx-meteotemplate.zip

Now you need to enter the following into /etc/weewx/weewx.conf:

binding = loop

The server_url is the full path to your Meteotemplate API (i.e.: https://your-site.com/path-to-meteotemplate/api.php). The password is the password you configured in Meteotemplate for API updates. The Loop Binding tells WeeWX to send the data every time it gets updates from your Weather Station hardware, and not to wait for the Archive process. This gives near real time updates to your weather station.

Now we simply need to restart WeeWX:

sudo /etc/init.d/weewx restart

You should be able to tail out the /var/log/weewx.log file and see that Meteotemplate is now getting data sent to it – if there are errors, its time to hit the docs again 🙁

What’s Next?

In the next post, I am going to talk about another use-case – creating a JSON file to be consumed by Home Automation systems such as Hubitat. I started going down this path when I saw Wunderground announce they are going to start charging PWS site owners to access their own data via the Wunderground API – a rant for another post …

I am also going to be building a Pi based weathercam and will post the details on that build as well.

Sharing is Caring

Related Posts

Home Automation and Smart Home

Home Automation Solution Mapping

Home Automation, or has my house become self-aware? SkyNet Be Damned! I’ve been playing around with Home Automation and SmartHome IoT technology for a couple of months and went searching

Read More »
Rock of Cashel Panorama ©2016 John P. Hoke

Rock of Cashel Panorama

Panorama of Rock of Cashel, Tipperary, Ireland Last month I had the luck (of the Irish?) to head over to Dublin for a business trip, and took a few extra

Read More »