Setting up WeeWX with a Raspberry PI

This is a quick setup guide on how to configure the open source software WeeWX for a Personal Weather Station (PWS).  I highly recommend you check out the WeeWX User Guide as this information is very well documented.  Here is a reflection of how I was able to get WeeWX installed on a Raspberry PI with a brand new weather station.

  1. Setup your Raspberry PI
    1. How to setup your Raspberry PI: http://jackstromberg.com/2018/03/setting-up-a-new-raspberry-pi-via-ssh/
      1. Note: Raspbian is a distribution based upon Debian.  In this case, we will follow the Debian instructions for setting up WeeWX.
        1. http://weewx.com/docs/debian.htm
  2. (Optional) Configure the Raspberry PI to be localized to your environment
    1. sudo raspi-config
      1. Here you can arrow down to Localization Options and configure the timezone to match that of your console/weather sensor.  Keeping time is critical, so if possible, try to keep the date/time between your weather station and the Raspberry PI as close as possible.
  3. Configure Apt-Get to look for the WeeWX packages
    wget -qO - http://weewx.com/keys.html | sudo apt-key add -
    sudo wget -qO - https://weewx.com/apt/weewx-python3.list | sudo tee /etc/apt/sources.list.d/weewx.list

    Note: Use https://weewx.com/apt/weewx-python3.list for Debian 10.X (latest version of raspbian as of 2021-07-23 will use this); otherwise use https://weewx.com/apt/weewx-python2.list for Debian 9.X.

  4. Update your Raspberry-PI to use the latest packages
    sudo apt-get update
    sudo apt-get upgrade
  5. Before installation, ensure you have your console or device setup and connected to your Raspberry PI for WeeWX to pull the data
  6. Determine the interface the console is connected to (if using a directly attached data loggerm skip if using an IP based source)
    1. Execute the command dmesg and look for what interface the data logger is connected to
      1. In my example, you can see the data logger is connected to ttyUSB0
  7. Launch the installation wizard for weewx
    1. sudo apt-get install weewx
      1. Note: You will likely be prompted to install a few dependencies, type Y for yes to install them
  8. Installation
    1. Enter the location of your weather station: Santa's Workshop, North Pole
    2. Enter in the latitude, longitude of your weather station
      1. Note: If you don't have GPS, you can easily find this by using Bing Maps or Google Maps, navigating to your location, and right clicking.
        1. For Bing, it will just show you the lat/long values when you right click
        2. For Google, click on "What's Here" and it will list these values
      2. Note: You can be more specific than 3 digits behind the decimal, so if you want to use a more specific set of coordinates like 40.689167, -74.044444, that is acceptable.
    3. Enter in your Altitude of where the weather station is
      1. You can use Google Earth to find the altitude or this tool here: https://www.freemaptools.com/elevation-finder.htm
    4. Set your preferred unit of measurement
      1. US (Imperial) or Metric
    5. Select your weather station type
      1. I.e. AcuRite, Vantage (if using Davis), etc.
    6. Select the interface the device is listening on
    7. For those using serial port, select the interface that the data logger is connected to.  You should have found this in step 4 above; if using ethernet, go ahead and type in the IP, Port, etc. of the data logger.
  9. At this point WeeWX is technically installed, however many individuals will want to present the WeeWX reports via webpage.  In this case, we'll install nginx, which is a lightweight webserver
    1. sudo apt-get install nginx
      1. More details on this can be found here: http://www.weewx.com/docs/usersguide.htm#integrating_with_webserver
  10. Configure WeeWX to minimize disk IO
    1. Why do we need to do this?  Since Raspberry PI's leverage SD cards, there is typically a finite number of reads/writes to the SD Card.  In this case, it is recommended to either leverage an external database/fileserver for WeeWX to write its reports.  Alternatively, we can also configure WeeWX to leverage ram to host the reports, which will prevent IO to the SD card (in this case, theoretically increasing the life of the drive)
      1. Three approaches are outlined here--in this guide I'll reflect the GitHub page in saving reports to a temporary file system using tmpfs
        1. Add an entry to fstab
          1. echo "weewx_reports /var/weewx/reports tmpfs size=20M,noexec,nosuid,nodev 0 0" | sudo tee -a /etc/fstab
        2. Mount the new file system
          1. sudo mkdir -p /var/weewx/reports
          2. sudo mount -a
        3. Update weewx.config file to point to new directory
          1. sudo sed -i -e 's%HTML_ROOT =.*%HTML_ROOT = /var/weewx/reports%' /etc/weewx/weewx.conf
        4. Restart WeeWX service
          1. sudo service weewx restart
        5. Create symbolic link to point webserver to the reports
          1. sudo ln -s /var/weewx/reports /var/www/html/weewx
        6. Give the web server the ability to read from the directory
          1. sudo chmod -R 755 /var/www/html/weewx

At this point, go ahead and browse out to http://youripaddress/weewx/ to see your weather.

Notes:

WeeWX updates the webpage every 30 minutes (1800 seconds) out of the box.  You can force a report update by executing wee_reports weewx.conf or you can modify the /etc/weewx/weewx.conf file by changing the archive_interval variable (in seconds) under the [StdArchive] section.

You can modify the Weewx configuration by editing: /etc/weewx/weewx.conf

You can validate if WeeWX is running by executing: service weewx status

You can look at diagnostics logs by following the guide here: http://www.weewx.com/docs/usersguide.htm#monitoring

Best practices guide on using WeeWX + Raspberry PI: https://github.com/weewx/weewx/wiki/Raspberry%20Pi

18 thoughts on “Setting up WeeWX with a Raspberry PI

  1. dunbrokin

    I seem to be having a problem with the code above.....here is what I get
    .
    .
    pi@Weatherpi:/var/www/html $ sudo mkdir -p /var/weewx/reports
    pi@Weatherpi:/var/www/html $ sudo mount -a
    mount: /etc/fstab: parse error: ignore entry at line 6.
    pi@Weatherpi:/var/www/html $ sudo sed -i -e ‘s%HTML_ROOT =.*%HTML_ROOT = /var/weewx/reports%’ /etc/weewx/weewx.conf
    sed: -e expression #1, char 1: unknown command: `�'
    pi@Weatherpi:/var/www/html $ sudo mount -a
    mount: /etc/fstab: parse error: ignore entry at line 6.
    pi@Weatherpi:/var/www/html $ sudo sed -i -e ‘s%HTML_ROOT =.*%HTML_ROOT = /var/weewx/reports%’ /etc/weewx/weewx.conf
    sed: -e expression #1, char 1: unknown command: `�'
    .
    .
    What am I missing?

    Reply
    1. Jack Post author

      Hello,

      I think the reason why it's not working is the website converted the ASCII characters to extended ASCII. If you copy and paste the commands into notepad/terminal and manually remove the 's and "s and retype them, that should fix this problem. I've reedited the article so if you try to copy and paste the commands again, it should work properly now as well.

      Please let me know how it goes,
      Jack

      Reply
  2. Loopy

    Hi Jack
    Thank for this, it's awesome!
    Since I made as per #10, my nginx webserver stopped updating, only reflecting the last saved files before the change.
    A bit extreme maybe but I eventually deleted /var/www/html/weewx and then created the symbolic link again and that seemed to do the trick. (perhaps there's a better way?)

    under "Notes", my time was already set at 300 seconds but server only updated every 30 minutes.
    That was also solved after the above "fix".

    Reply
    1. Jack Post author

      Can you help provide a little more information? Even though you are using nginx, you should be able to navigate to http://ipaddress/weewx and the page should load after installing nginx, provided you have executed the command in step 10.3 to have weewx generate reports in the default directory nginx points to.

      Reply
  3. Kevin weaver

    Jack. Love your write up. The problem I am having is NGINX and Interceptor are fighting for port 80. I have tried using different ports but they are only happy on 80. If Interceptor is on 80 it works but web page is error 404 page not found. The web page comes up and will show the last updated info from the smart hub. If I do the opposite I get an error in weewx ref interceptor. Address already in use.
    My set up is a acurite smart hub with 5n1. Raspberry Pi

    Reply
  4. Dave A

    Great site here. I am having a problem with step 6 because I have very bad vision. I have my acurite connected tp raspberry pi with the cable that came from Acurite. The problem is I am not sure wher to go at this point of the install.

    Reply
    1. Jack Post author

      Hello Dave,

      The picture shows a series of lines after executing the dmesg command. Specifically, the picture tries to call out the following text listed in the output "[ 3914.514062] usb 1-1.2: cp210x converter now attached to ttyUSB0". This output confirms which interface the device is connected to (in this case ttyUSB0). Here's a direct link to the picture which may make it easier to see: https://jackstromberg.com/wp-content/uploads/2018/06/cp210x-converter-now-attached-to-ttyUSB0-1024x594.png

      Hope this helps!
      Jack

      Reply
  5. Jim M

    Stumbled across this site tonight. Very interesting, I have a AcuRite weather station that the Ethernet bridge died on several years ago. I have not been willing to spend over a hundred dollars just for a simple bridge. I have a Pi I am not using for anything right now. Will your method work with an off the shelf RF dongle, a Pi and the Acurite station? or will I still need another Acurite RF device to read/decode the signal from the station?
    Thanks!

    Reply
    1. Colin

      Have a look at weewx-sdr.
      You will need an RTL-SDR, but that's cheeper than a console, and much more versatile.

      Reply
  6. Pingback: WeeWX Wetterstation mit einer Renkforce WH2300 im APRS Netzwerk - MPDX.at

  7. Allan Tyson

    I have used the instructions several times successfully. However lately, after completing the steps exactly, when attempting to bring up my Weewx page using the IP address/weewx I get a 403 forbidden error. I tried everything I could think of until I found a posting that suggested entering the following commands into a terminal program connected to your RPi that is running Weewx with ngenix.

    "403 forbidden" NGINX Error

    If you encounter a "403 forbidden" error from NGINX, enter these commands in Terminal (again, full credit to HowToRaspberryPi.com):

    Use "sudo" at the beginning of each command if you need to, or switch to root user, as described above.

    sudo echo 'Nginx work’s !' > /var/www/html/index.html
    sudo chown www-data:www-data /var/www
    sudo chmod 744 /var/www

    That’s it. You’re done. For good measure, reboot your Raspberry Pi (sudo reboot) and wait 10-15 minutes before trying to access the web page again. Refresh the page a couple of times to ensure you’re viewing the latest version.

    Worked for me

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *