This is a guide to configuring weewx on a debian-based plug computer attached to a Fine Offset weather station.
Collecting data on a plug computer requires a few additional changes from a standard installation. A plug computer installation should consider the following:
System restarts can be reduced by putting the plug on a battery backup system. For example, an old APC SmartUPS 1000 will keep a 5 watt plug computer running for about 5 hours without power.
Perhaps the easiest way to avoid problems on a plug computer is to have the plug computer upload data immediately to another computer. For cases where this is not possible, read on...
The basic idea is to move frequent writes from the flash disk to a ramdisk so that wear on the flash drive is reduced. Data on the ramdisk will be lost when the system shuts down, so provision must be made to save data from the ramdisk.
weewx makes frequent writes to the generated files (e.g. html and images in the Standard skin of a default installation, 10s of files every 5 minutes), the log file (e.g. /var/log/syslog in a default installation, especially when debug is enabled), and the database (e.g. weewx.sdb and stats.sdb in a default installation, every 5 minutes).
In the configuration described in this guide, database files must be retained but generated files and log files are considered disposable. The database will be saved once per hour, so at most one hour of data would be lost in the event of power failure.
Keeping the generated files on ramdisk is most important. If debug is disabled, then logging to ramdisk is not as important.
FIXME: need to quantify effects on flash of writing to database every 5 minutes versus copying entire database every hour.
Install pre-requisites and weewx as you normally would, for example:
sudo apt-get install python-usb sudo apt-get install python-cheetah sudo apt-get install python-configobj sudo apt-get install python-imaging sudo apt-get install python-dev sudo apt-get install python-pip sudo pip install pyephem cd /var/tmp tar xvfz weewx-x.y.z.tgz cd weewx-x.y.z sudo setup.py install
Create a ramdisk by adding the following line to /etc/fstab:
weewx /var/weewx tmpfs size=50M,noexec,nosuid,nodev 0 0
Mount the ramdisk with the following:
sudo mount weewx
How big should the ramdisk be? One year of weewx data equates to a weewx.sdb file of about 20MB. Generated files from the Standard skin typically total less than 1MB. If saving only generated files to ramdisk, the ramdisk can be 2 or 3 MB. If saving database to ramdisk, the ramdisk should be 40 to 50MB for up to 3 years of data.
Put the generated files into a directory on the ramdisk by modifying weewx.conf:
[StdReport] HTML_ROOT = /var/weewx/www
Point apache to the generated weewx files by putting the following in /etc/apache2/conf.d/weewx.conf:
Alias /weewx /var/weewx/www <Directory /var/weewx/www> Options FollowSymlinks AllowOverride None Order allow,deny Allow from all </Directory>
Put the database files into a directory on the ramdisk by modifying weewx.conf:
[Databases] [[archive_sqlite]] database = /var/weewx/archive/weewx.sdb ... [[stats_sqlite]] database = /var/weewx/archive/stats.sdb ...
Create a directory for database snapshots. The database files will be copied to this directory periodically while weewx is running, and they will be copied from this directory when weewx starts up.
mkdir -p /home/weewx/db
Modify the weewx rc script. In do_start, add lines to create directories and copy the database from flash to ramdisk:
do_start() { mkdir -p /var/weewx/archive cp -p /home/weewx/db/*.sdb /var/weewx/archive ...
In do_stop, copy the database files back to flash:
do_stop() ... rm -f $PIDFILE cp -p /var/weewx/archive/*.sdb /home/weewx/db return "$RETVAL" }
Create a crontab to periodically copy the database files from the ramdisk to flash. The more often the data are copied, the fewer data will be lost in a power failure but more wear on the flash drive.
To save the database once per hour at 5 minutes past the hour, put this into a file called crontab.weewx:
5 * * * * /bin/cp -p /var/weewx/archive/*.sdb /home/weewx/db
To install the crontab:
crontab crontab.weewx
Redirect the weewx log messages to a separate file on a ramdisk. Put the following into /etc/rsyslog.d/weewx.conf
if $programname == 'weewx' then /var/weewx/log/weewx.log if $programname == 'weewx' then ~
Restart syslog so that it picks up the changes:
sudo /etc/init.d/rsyslog stop sudo /etc/init.d/rsyslog start
Use logrotate to prevent the logfiles from getting too big. Put the following into /etc/logrotate.d/weewx:
/var/wx/log/weewx.log { weekly missingok rotate 12 compress delaycompress notifempty create 644 root adm sharedscripts postrotate /etc/init.d/weewx reload > /dev/null endscript }
Copyright © 2013 Matthew Wall, all rights reserved
Last modified: