Download and Install Weewx – Part 7

From the Beginning: An Introduction – Part 1

Previous: Download and Setup Meteotemplate – Part 6

According to the Weewx website: “WeeWX is a free, open source, software program, written in Python, which interacts with your weather station to produce graphs, reports, and HTML pages. It can optionally publish to weather sites or web servers.”

This image has an empty alt attribute; its file name is Screenshot-2018-12-19-15.57.05-1024x576.png

You’ll be installing and configuring Weewx on your RPi, which will communicate and publish information to your Meteotemplate website, as well as Weather Underground, etc, should you decide to do so. Using Terminal on your RPi, follow the instructions on the Weewx website to download and install Weewx on your Raspberry Pi (using Terminal).

However, I have found not adding “sudo” (w/o quotes) before each command sometimes means they don’t work. So I recommend adding “sudo” before each command.

In Terminal (press enter after each command):

sudo wget -qO - http://weewx.com/keys.html | sudo apt-key add -
 
sudo wget -qO - http://weewx.com/apt/weewx.list | sudo tee /etc/apt/sources.list.d/weewx.list [note: this command should be entered on a single line]
 
sudo apt-get update
 
sudo apt-get install weewx

In some cases, I get the message “Permission denied” even when using “sudo”. If that happens, switch to being the ‘root’ user. For example:

sudo su (then press enter)

Then type your command, pressing enter after each one. When done, type ‘exit’ and press enter to leave ‘root’ user mode.

Meteotemplate Extension for Weewx

Download and install the third-party Meteotemplate extension (add-on) for Weewx on your Raspberry Pi. This will allow Weewx to communicate with your Meteotemplate website.

This image has an empty alt attribute; its file name is unnamed.jpg

1. Download the extension. Open Terminal and type (please note the commands are case sensitive):

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

OR download it from my Dropbox:

sudo wget -O weewx-meteotemplate.zip https://www.dropbox.com/s/eptdcmyzlywrdbw/weewx-meteotemplate.zip?dl=0

2) run the installer:

sudo wee_extension --install weewx-meteotemplate.zip

3) In Terminal, open Weewx using the following command:

sudo nano /etc/weewx/weewx.conf

This image has an empty alt attribute; its file name is 31114557427_99ee799136_b-1024x768-1024x768.jpg

4) enter (copy/paste via the ‘edit’ menu in Terminal) the following information parameters (“server_url” and “password” – your Meteotemplate admin password) in weewx.conf:

[StdRESTful]

[[Meteotemplate]]

server_url = http://yourwebsite.com/Meteotemplate/api.php

password = your Meteotemplate Admin password

This image has an empty alt attribute; its file name is RPi-sudo_nano_weewx_conf3-1024x768-1024x768.png

Your server url will be where the ‘api.php’ file is located. If you’re not sure, login to your server using an FTP client (such as FileZilla) and find it that way, paying close attention to the server directory file path.

5) Now, save and exit weewx.conf by pressing CTRL+X, Y, and enter.

6) restart weewx:

sudo /etc/init.d/weewx restart

Now, after all that hard work, you’ll want to view your Weewx website on your Raspberry Pi. To do this, you will need to do two things:

Install the NGINX Web Server:

Install the NGINX web server according to this guide.

NGINX allows weewx info to be presented on a web page. Scroll down to step 9 on that page if you haven’t installed the Apache web server. If you’re strictly following this guide, you haven’t installed Apache.

For the sake of convenience, and to completely document this process, here are the steps:

Open Terminal, and use the following commands:

sudo apt install nginx php-fpm
sudo nano /etc/nginx/sites-available/default

Look for the line:

index index.html index.htm index.nginx-debian.html;

Replace it by the line:

index index.html index.htm index.php;

We will now activate php-fpm for Nginx. To do this, look for the lines:

#location ~ \.php$ { 
# include snippets/fastcgi-php.conf; 
#
# # With php5-cgi alone: 
# fastcgi_pass 127.0.0.1:9000; 
# # With php5-fpm: 
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
#}

Modify that to look this this:

location ~ \.php$ { 
include snippets/fastcgi-php.conf;
 fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

We’re done with making changes to that file. Press CTRL+X, Y, and enter to exit the file and go back to Terminal.

Now we need to change some permissions so everything plays nicely with each other:

sudo chown -R www-data:pi /var/www/html/ 
sudo chmod -R 770 /var/www/html/

Now we need to add an “index.php” file to verify that PHP is working (if you get a “permission denied’ message, switch to “sudo su” (root user) and try the command again):

sudo echo "<?php phpinfo(); ?>" > /var/www/html/index.php

Now we need to restart the NGINX web server:

sudo /etc/init.d/nginx restart

Follow ALL of the instructions on that web page, including the ‘403 Forbidden’ section. You may or may not encounter this error (I have with each of my RPi Weewx/NGINX installs). No harm in doing those steps anyway, as it ensures proper permissions.

Forward Port 80 (HTTP) On Your Router/Modem:

To allow access on your local network and via the internet to Weewx on your Raspberry Pi, you MUST forward port 80 to your RPi’s local IP address (something easily done on most routers), access your router’s home page (usually something like: 192.168.0.1), and enter your credentials. If you’re not sure, ask whoever manages it for you to forward the port for you, or if it hasn’t been modified since you got the router/modem, there should be a label on it with the details.

This image has an empty alt attribute; its file name is router_port_forwarding-1024x425.png

Find the Port Forwarding section, and create a new ‘rule’, forwarding port 80 to your Raspberry Pi’s local IP address as shown above. (if unsure, type “ifconfig” without the quotes in Terminal), as shown above. The IP address will obviously be different. After that, save changes and log out of your router/modem.

Give it a few minutes, and hopefully the next time you visit your RPi’s local IP address with “/Weewx” (http://192.168.0.XX/weewx), or using your external IP address (type “what is my ip” in Google to find it), and add “/weewx”. Hopefully you’ll see your Weewx website! If not, you’ll have to investigate to find out what’s going on.

“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.

Changing the Theme of the Weewx Web Page:

Sometime late in 2018 or early 2019, the developers of Weewx released a new version that change the default theme the Weewx uses for web page display. This also affected the RSS feed, meaning that the URL used for the “Standard” theme no longer worked, and if you setup a service like dlvr.it to tweet current conditions (covered on the next page of this guide), that was now broken. Presumably, you could just change the url path to the new path for dlvr.it to use it, but that didn’t work in my case. Not sure why.

Personally, I prefer the “Standard” theme compared to the “Seasons” theme, and thankfully it’s an easy fix to switch back to the “Standard” theme. Open the “weewx.conf” file again and do the following:

In the [StdReport] section, under [[SeasonsReport]], change “enable = true” to “enable = false”, and under [[StandardReport]], change “enable = false” to “enable = true”

Now, save and exit weewx.conf by pressing CTRL+X, Y, and enter.

That will also fix the URL path to the RSS feed back to the way it was, to dlvr.it will tweet current conditions again.

Then, restart for good measure:

sudo reboot

Previous: Download and Setup Meteotemplate – Part 6

Next: Automatically Publish Current Conditions to a Twitter Account – Part 8

From the Beginning: An Introduction – Part 1