<<<Rasberry Pi Guides

Installing WeeWX 4

I bought a Rasberry Pi last year, with a view to moving my weather station software off of my main PC.

As I run my website from an AWS S3 bucket, I use awscli and boto3 as the api for the python calls to synchronise the pages and this requires the use of Python3 which in turn requires the use of WeeWX 4, see my other post to see how to setup Python3 as the default

This post documents the installation of version 4 WeeWX onto a Rasberry Pi using Python3

First make sure everything is upto date

First, update your system's package list by entering the following command:

pi@raspberrypi:~ $ sudo apt update
All packages are up to date.
    

Next, upgrade all your installed packages to their latest versions with the following command:

pi@raspberrypi:~ $ sudo apt full-upgrade
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    

Note that full-upgrade is used in preference to a simple upgrade, as it also picks up any dependency changes that may have been made.

Generally speaking, doing this regularly will keep your installation up to date for the particular major Raspbian release you are using (e.g. Stretch). It will not update from one major release to another, for example, Stretch to Buster.

However, there are occasional changes made in the Foundation's Raspbian image that require manual intervention, for example a newly introduced package. These are not installed with an upgrade, as this command only updates the packages you already have installed.

Install the Python3 libraries

Make sure you do this correctly and do not inadvertantly install the Python2 libraries as directed in theWeeWX Guide

If you inadvertantly install the Python2 libraries then you will get errors relating to configobj

Also DO NOT install python3-imaging, or python-imaging for that matter. They have been replaced by python_pil and will result in errors if you try to install them

pi@raspberrypi:~ $ python -V
Python 3.7.3

pi@raspberrypi:~$ sudo apt-get install python3-pil
pi@raspberrypi:~$ sudo apt-get install python3-configobj
pi@raspberrypi:~$ sudo apt-get install python3-cheetah
pi@raspberrypi:~$ sudo apt-get install python3-usb
pi@raspberrypi:~$ sudo apt-get install python3-dev
pi@raspberrypi:~$ sudo apt-get install python3-pip

pi@raspberrypi:~$ sudo pip3 install pyephem
    

Now install Weewx

First get the source files

pi@raspberrypi:~ $ wget http://www.weewx.com/downloads/weewx-4.4.0.tar.gz

weewx-4.4.0.tar.gz           100%[==========================================================>]   1.51M  1.18MB/s  in 1.3s

2020-03-06 07:47:20 (1.18 MB/s) - ‘weewx-4.4.0.tar.gz’ saved [1579890/1579890]
    

Then unpack the tar file and check the contents

pi@raspberrypi:~ $ tar xvfz weewx-4.4.0.tar.gz

pi@raspberrypi:~ $ ls -al weewx-4.4.0
total 120
drwxr-xr-x  7 pi pi  4096 Mar 15 01:41 .
drwxr-xr-x 21 pi pi  4096 Mar 19 07:49 ..
drwxr-xr-x 11 pi pi  4096 Mar 15 01:41 bin
drwxr-xr-x  6 pi pi  4096 Mar 15 01:41 docs
drwxr-xr-x  7 pi pi  4096 Mar 15 01:41 examples
-rw-r--r--  1 pi pi 32472 Mar  5 01:18 LICENSE.txt
-rw-r--r--  1 pi pi   176 Mar 14 22:09 MANIFEST.in
-rw-r--r--  1 pi pi  5157 Mar 15 01:41 PKG-INFO
-rw-r--r--  1 pi pi   400 Mar 12 15:56 README
-rw-r--r--  1 pi pi  3310 Mar  5 01:18 README.md
-rw-r--r--  1 pi pi   151 Mar 15 01:41 setup.cfg
-rwxr-xr-x  1 pi pi 12150 Mar 15 01:39 setup.py
drwxr-xr-x  8 pi pi  4096 Mar 15 01:41 skins
drwxr-xr-x 13 pi pi  4096 Mar 15 01:41 util
-rw-r--r--  1 pi pi 22162 Mar 15 01:41 weewx.conf
    

The next step is to build and install weewx

To specify a location different from the standard /home/weewx, modify the parameter home in the setup.cfg file.

pi@raspberrypi:~ $ python -V
Python 3.7.3

pi@raspberrypi:~ $ cd weewx-4.0.0b16

pi@raspberrypi:~/weewx-4.0.0b16 $ python ./setup.py build
running build
running build_py
running build_scripts
pi@raspberrypi:~/weewx-4.0.0b16 $ sudo python ./setup.py install
    

Setup WeeWX to run as a daemon

If your system uses systemd to manage the starting and stopping of daemons, and the Rasberry Pi does, you should configure WeeWX specifically for systemd (weewx.service) instead of using the traditional rc script (/etc/init.d/weewx). On most systems with systemd, the WeeWX rc script will still work.

Further documentation on systemd is availabe in the Rasberry Pi and fedora Docs manuals

The WeeWX distribution includes a systemd "unit" file called weewx.service that tells systemd how to run weewx. It looks something like this:

pi@raspberrypi:~ $ cat util/systemd/weews.service

# systemd configuration for weewx

[Unit]
Description=WeeWX weather system
Requires=time-sync.target
After=time-sync.target
RequiresMountsFor=/home
# The following two lines are not in the current distribution version, but should be uncommented and used if you
# have changed the [Service] section to automatically restart the WeeWX service if it crashes. As noted below,
# this can be particularly useful if WeeWX has an IP connection to the weather station it is monitoring, since
# transient WiFi network problems are quite common, and may cause WeeWX to crash.
# StartLimitIntervalSec=100
# StartLimitBurst=5

[Service]
ExecStart=/home/weewx/bin/weewxd --daemon --pidfile=/var/run/weewx.pid /home/weewx/weewx.conf
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
PIDFile=/var/run/weewx.pid

# The following two lines are not in the current distribution version, but may be uncommented and used if you
# want the WeeWX service to automatically restart if it crashes. This can be particularly useful if weewx
# has an IP connection to the weather station it is monitoring, since transient network problems are quite
# common, and may cause the daemon to crash.
#Restart=on-failure
#RestartSec=10

# See notes; by default WeeWX will run with root privileges
#User=weewx
#Group=weewx

[Install]
WantedBy=multi-user.target
    

If you intend to run WeeWX as a background process then you will need to modify it so that it looks something like this

Some things to be aware of:

The order in which things are started is based on their dependencies — this particular script should start fairly late in the boot process, after a network is available (see the After parameter).

You can configure different dependencies and orders based on your requirements.

pi@raspberrypi:~ $ vi util/systemd/weewx.service

# systemd configuration for weewx

[Unit]
Description=WeeWX weather system
Requires=time-sync.target
After=network.target
After=time-sync.target
RequiresMountsFor=/home
StartLimitIntervalSec=100
StartLimitBurst=5

[Service]
ExecStart=/home/weewx/bin/weewxd --daemon --pidfile=/run/weewx.pid /home/weewx/weewx.conf
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
PIDFile=/run/weewx.pid
Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target
    

Once you are happy with your changes, copy this file into /etc/systemd/system as root, for example:

pi@raspberrypi:~ $ sudo cp util/systemd/weewx.service /etc/systemd/system/weewx.service
    

Running the WeeWX Service

Once this has been copied into the appropriate directory, you can start and stop the service using the following commands:

pi@raspberrypi:~ $ sudo systemctl start weewx

pi@raspberrypi:~ $ sudo systemctl stop weewx
    

When you are happy that this starts and stops your app, you can have it start automatically on reboot by using this command:

pi@raspberrypi:~ $ sudo systemctl enable weewx
    

Note:The systemctl command can also be used to restart the service or disable it from boot up

To check that status of the WeeWX service run the following command:

pi@raspberrypi:~/.aws $ sudo systemctl status weewx
● weewx.service - WeeWX weather system
   Loaded: loaded (/etc/systemd/system/weewx.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2020-03-16 16:58:33 GMT; 19h ago
 Main PID: 32160 (weewxd)
  Tasks: 1 (limit: 2200)
   Memory: 52.0M
   CGroup: /system.slice/weewx.service
       └─32160 /usr/bin/python /home/weewx/bin/weewxd --daemon --pidfile=/run/weewx.pid /home/weewx/weewx.conf

Mar 17 12:40:19 raspberrypi weewxd[32160]: weewx[32160] INFO weewx.reportengine: Copied 0 files to /var/www/html/MountWeather
Mar 17 12:40:19 raspberrypi weewxd[32160]: weewx[32160] INFO botocore.credentials: Found credentials in shared credentials file: ~/.aws/credentials
Mar 17 12:40:22 raspberrypi weewxd[32160]: weewx[32160] INFO user.s3upload: S3UploadGenerator: AWS-S3 copied 16 files to S3 in 3.45 seconds
Mar 17 12:45:16 raspberrypi weewxd[32160]: weewx[32160] INFO weewx.manager: Added record 2020-03-17 12:45:00 GMT (1584449100) to database 'weewx.sdb'
Mar 17 12:45:16 raspberrypi weewxd[32160]: weewx[32160] INFO weewx.manager: Added record 2020-03-17 12:45:00 GMT (1584449100) to daily summary in 'weewx.sdb'
Mar 17 12:45:18 raspberrypi weewxd[32160]: weewx[32160] INFO weewx.cheetahgenerator: Generated 8 files for report SeasonsReport in 1.57 seconds
Mar 17 12:45:19 raspberrypi weewxd[32160]: weewx[32160] INFO weewx.imagegenerator: Generated 9 images for report SeasonsReport in 0.78 seconds
Mar 17 12:45:19 raspberrypi weewxd[32160]: weewx[32160] INFO weewx.reportengine: Copied 0 files to /var/www/html/MountWeather
Mar 17 12:45:19 raspberrypi weewxd[32160]: weewx[32160] INFO botocore.credentials: Found credentials in shared credentials file: ~/.aws/credentials
Mar 17 12:45:22 raspberrypi weewxd[32160]: weewx[32160] INFO user.s3upload: S3UploadGenerator: AWS-S3 copied 17 files to S3 in 3.64 seconds
pi@raspberrypi:~/.aws $
    

Setting privileges

The final step is to set the privileges of the WeeWX code so that you can modify the files. By default, the WeeWX installation process leaves all files with root privileges and this precludes anyone other than root making changes.

The easiest way to do this is to set the ownership of the WeeWX files to be the user that you use to connect to your Rasberry Pi, which is pi in my case

pi@raspberrypi:~ $ ls -al ../weewx
total 132
drwxr-xr-x  9 root  root   4096 Feb 12 13:40  .
drwxr-xr-x  4 root  root   4096 Feb 12 08:52  ..
-rw-r--r--  1 root  root  32472 Apr 14  2020  LICENSE.txt
-rw-rw-r--  1 root  root   3325 Jan  8 21:10  README.md
drwxr-xr-x  2 root  root   4096 Feb 16 13:15  archive
drwxr-xr-x 11 root  root   4096 Feb 12 08:52  bin
drwxr-xr-x  6 root  root   4096 Feb 12 08:52  docs
drwxr-xr-x  7 root  root   4096 Feb 12 08:52  examples
drwxr-xr-x  4 root  root   4096 Feb 12 13:30  public_html
drwxr-xr-x 10 root  root   4096 Feb 12 13:30  skins
drwxr-xr-x 15 root  root   4096 Feb 12 08:52  util
-rw-r--r--  1 root  root  22158 Feb 12 13:30  weewx.conf
-rw-rw-r--  1 root  root  22427 Feb 12 08:52  weewx.conf.4.4.0

pi@raspberrypi:~ $ sudo chown -R pi ../weewx

pi@raspberrypi:~ $ ls -al ../weewx
total 132
drwxr-xr-x  9 pi    root   4096 Feb 12 13:40  .
drwxr-xr-x  4 pi    root   4096 Feb 12 08:52  ..
-rw-r--r--  1 pi    root  32472 Apr 14  2020  LICENSE.txt
-rw-rw-r--  1 pi    root   3325 Jan  8 21:10  README.md
drwxr-xr-x  2 pi    root   4096 Feb 16 13:15  archive
drwxr-xr-x 11 pi    root   4096 Feb 12 08:52  bin
drwxr-xr-x  6 pi    root   4096 Feb 12 08:52  docs
drwxr-xr-x  7 pi    root   4096 Feb 12 08:52  examples
drwxr-xr-x  4 pi    root   4096 Feb 12 13:30  public_html
drwxr-xr-x 10 pi    root   4096 Feb 12 13:30  skins
drwxr-xr-x 15 pi    root   4096 Feb 12 08:52  util
-rw-r--r--  1 pi    root  22158 Feb 12 13:30  weewx.conf
-rw-rw-r--  1 pi    root  22427 Feb 12 08:52  weewx.conf.4.4.0