Raspberry Pi

Raspberry Pi (RPi) Single Board Computer

Installing Apache Web Server on a RPI

Install Apache

First, update the available packages by typing the following command into the Terminal:

sudo apt update

Then, install the apache2 package with this command:

sudo apt install apache2 -y

Test the web server

By default, Apache puts a test HTML file in the web folder.

This default web page is served when you browse to:


on the Pi itself, or (whatever the Pi’s IP address is) from another computer on the network. To find the Pi’s IP address, type:

hostname -I

at the command line (or read more about finding your IP address).
Browse to the default web page either on the Pi or from another computer on the network and you should see the following:

This means you have Apache working!
Changing the default web page
This default web page is just an HTML file on the filesystem. It is located at :


Navigate to this directory in a terminal window and have a look at what’s inside:

cd /var/www/html
ls -al

This will show you:
total 12
drwxr-xr-x 2 root root 4096 Jan 8 01:29 .
drwxr-xr-x 12 root root 4096 Jan 8 01:28 ..
-rw-r–r– 1 root root 177 Jan 8 01:29 index.html

This shows that by default there is one file in /var/www/html/ called index.htmland it is owned by the root user (as is the enclosing folder). In order to edit the file, you need to change its ownership to your own username.

Change the owner of the file (the default pi user is assumed here) using

sudo chown pi: index.html

You can now try editing this file and then refreshing the browser to see the web page change.
Your own website
If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.

Additional – install PHP

To allow your Apache server to process PHP files, you’ll need to install the latest version of PHP and the PHP (8) module for Apache. Type the following command to install these:

sudo apt install php libapache2-mod-php -y

Now remove the index.html file:

sudo rm index.html

and create the file index.php:

sudo nano index.php

Put some PHP content in it:
<?php echo “hello world”; ?>

Now save and refresh your browser. You should see “hello world”. This is not dynamic but still served by PHP. Try something dynamic:

<?php echo date(‘Y-m-d H:i:s’); ?>

or show your PHP info:

<?php phpinfo(); ?>

Further – WordPress

Customise Site with CSS

Click the help icon above to learn more.
#page {
background: #e0e0e0;
#imgformat {width:100%; height:auto;
border:1px solid black;
.wpcf7 input.wpcf7-text { width: 100%; } .wpcf7 textarea.wpcf7-textarea { width: 100%; } .wpcf7-form textarea { height: 200px; }

Now you have Apache and PHP installed you can progress to setting up a WordPress site on your Pi. Continue to WordPress usage.

RPi Benchmark

sudo curl https://raw.githubusercontent.com/TheRemote/PiBenchmarks/master/Storage.sh | sudo bash

Installing WEEWX Server on a RPI

Download the DEB package from weewx.com/downloads. It will have a name similar to weewx_X.Y.Z-R_all.deb.


Install with the command:
sudo dpkg -i weewx_X.Y.Z-R_all.deb

The installer will prompt for a location, latitude/longitude, altitude, station type, and parameters specific to your station hardware.

If dpkg complains about dependency problems, use apt-get to resolve the dependencies and complete the installation:
sudo apt-get update
sudo apt-get -f install

When you are done, weewx will be running in the background as a daemon.

Check Status

To make sure things are running properly look in the system log for messages from weewx.
sudo tail -f /var/log/syslog


After about 5 minutes, open the station web page in a web browser. You should see your station information and data.

If your hardware supports hardware archiving, then how long you wait will depend on the archive interval set in your hardware.


To enable uploads such as Weather Underground or to customize reports, modify the configuration file /etc/weewx/weewx.conf. See the User Guide and Customization Guide for details.


weewx must be restarted for configuration file changes to take effect.


To start/stop weewx:
sudo /etc/init.d/weewx start
sudo /etc/init.d/weewx stop


To uninstall weewx but retain configuration files and data:
sudo dpkg -r weewx

To uninstall weewx, removing configuration files but retaining data:
sudo dpkg –purge weewx

To remove data:
sudo rm -r /var/lib/weewx
sudo rm -r /var/www/html/weewx


The installation will result in the following layout:

executable: /usr/bin/weewxd
configuration file: /etc/weewx/weewx.conf
skins and templates: /etc/weewx/skins
sqlite databases: /var/lib/weewx/
generated web pages and images: /var/www/html/weewx/
documentation: /usr/share/doc/weewx/
utilities: /usr/bin/wee_*

Setting up Dynamic DNS using DDClient

# Configuration file for ddclient generated by debconf

#Edit the configuration file: sudo nano /etc/ddclient.conf

# /etc/ddclient.conf

use=web, web=checkip.dyndns.org/
login=<dynu  username>
password='<dynu password>’

Forwarding RPi IP address to Dynudns

You can make a script in Raspberry Pi and setup a cron job to run every 5 minutes to keep your hostnames updated to the most current IP address.

1. You can make a directory to put the files in.

cd ~
mkdir dynudns
cd dynudns
vi dynu.sh

2. Move to dynu.sh and make the script. Copy and paste the following into the file and save it.

echo url=”http://api.dynu.com/nic/update?hostname=<domain>.dynu.com&password=<password>” | curl -a -k -a -o /home/pi/dynudns/dynu.log -K –
echo >> /home/pi/dynudns/dynu.log
echo “Time: $(date)” >> /home/pi/dynudns/dynu.log

*/10 * * * * bash -l -c /home/pi/dynudns/dynu.sh >/dev/null 2>&1

3. Make dynu.sh executable.

chmod 700 dynu.sh

4. Use a cron job to make the script run every 5 minutes.

crontab -e

copy and paste the below to the bottom of the crontab:

*/10 * * * * bash -l -c /home/pi/dynudns/dynu.sh >/dev/null 2>&1

To verify that the command was added to the cronjob you can list the cron jobs to make sure it is there:
crontab -l

It should show

*/10 * * * * bash -l -c /home/pi/dynudns/dynu.sh >/dev/null 2>&1

You can adjust the update interval by modifying the */10 to */60 for every 60 minutes or whatever interval you need.

Setting up DDSCLIENT DNS forwarding of Rpi IP address to Dynudns

  1. Installation

    Some DNS providers offer their own dynamic DNS clients, but most of them are proprietary. The one I am going to use is called ddclient, it’s free and open source, and written in Perl. Use this command to install ddclient:

    1.  sudo apt-get install ddclient
    2. ddclient configuration

      Now you have everything you need to configure ddclient.

      The main configuration file for ddclient is at /etc/ddclient.conf, you can open this file to edit it with a text editor of your choice – this command will open it in nano:


      sudo nano /etc/ddclient.conf

    3. Here is a sample “normal” configuration file for ddclient:
      password='your password'
    4. protocol is set by your dynamic DNS provider.
    5. server is the hostname of the dynamic DNS server.
    6. login is your domain name
    7. password is the dynu credential
    8. The last line is the domain to be updated with your WAN IP address
  2. The configuration file should look like this:
    1. # Configuration file for ddclient generated by debconf
      # /etc/ddclient.confprotocol=dyndns2
  3. Testing your configuration

    You can check if the pre-defined use values can detect your WAN IP by running this command:

    sudo ddclient -query

    If your server is connected with a wireless connection, the output should look something like this:

    use=if, if=eth0 address is NOT FOUND
    use=if, if=lo address is
    use=if, if=wlan0 address is
    use=web, web=dnspark address is NOT FOUND
    use=web, web=dyndns address is
    use=web, web=loopia address is

    To test your ddclient configuration with really verbose output, printing all possible configuration parameters and their values, you can use this command:

    sudo ddclient -debug -verbose -noquiet

    I won’t print a sample output because it’s too long, but somewhere near the bottom you should see a line like this:

    SUCCESS:  updating backup: good: IP address set to

Installing an FTP Server

FTP (File Transfer Protocol) can be used to transfer files between a Raspberry Pi and another computer. Although with default program sftp-server of Raspbian the users with sufficient privilege can transfer files or directories, access to the filesystem of the limited users is also required often. Follow the steps below to set up an FTP server:

Install Pure-FTPd

First, install Pure-FTPd using the following command line in Terminal:
sudo apt-get install pure-ftpd

Basic Configurations

We need to create a new user group named ftpgroup and a new user named ftpuser for FTP users, and make sure this “user” has NO log in privilge and NO home directory:
groupadd ftpgroup
useradd ftpuser -g ftpgroup -s /sbin/nologin -d /dev/null

FTP Home Directory, Virtual User, and User Group

For instance, make a new directory named FTP for the first user:
sudo mkdir /home/pi/FTP

Make sure the directory is accessible for ftpuser:
sudo chown -R ftpuser:ftpgroup /home/pi/FTP

Create a virtual user named upload, mapping the virtual user to ftpuser and ftpgroup, setting home directory /home/pi/FTP, and record password of the user in database:
sudo pure-pw useradd upload -u ftpuser -g ftpgroup -d /home/pi/FTP -m

A password of that virtual user will be required after this command line is entered. And next, set up a virtual user database by typing:
sudo pure-pw mkdb

Last but not least, define an authentication method by making a link of file /etc/pure-ftpd/conf/PureDB, the number 60 is only for demonstration, make it as small as necessary:
ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb

Restart the program:
sudo service pure-ftpd restart

Test it with an FTP client, like FileZilla.

More Detailed Configurations:

The configuration of Pure-FTPd is simple and intuitive. The administrator only needs to define the necessary settings by making files with option names, like ChrootEveryone, and typing yes, then storing in the directory /etc/pure-ftpd/conf, if all FTP users are to be locked in their FTP home directory (/home/pi/FTP). Here are some recommended settings:
sudo nano /etc/pure-ftpd/conf/ChrootEveryone

Type yes, and press Ctrl + X, Y, and Enter.


Make a file named NoAnonymous and type yes;

Make a file named AnonymousCantUpload and type yes;

Make a file named AnonymousCanCreateDirs and type no;

Make a file named DisplayDotFiles and typeno;

Make a file named DontResolve and type yes;

Make a file named ProhibitDotFilesRead and type yes;

Make a file named ProhibitDotFilesWrite and type yes;

Make a file named FSCharset and typeUTF-8;

Restart pure-ftpd again and apply the above settings.
sudo service pure-ftpd restart

For more information of Pure-FTPd and documentation, go to the official website of Pure-FTPd.

Adding Image Uploads to Weather Underground

  1. Create a script to upload the images, create a new file called ‘wunder.sh’ and enter the following in the file:
    1. #!/bin/bashfilename=””http://g6ejd.dynu.com:8082/html/cam.jpg”
      lftp ftp://$username:$password@$hostname -e “put $filename ; quit”
  2. Save and exit
  3. Make the script file executable:
    1. sudo chmod +x wunder.sh
    2. Copy the file to /home/pi with cp wunder.sh   /home/pi/
  4. Create a PYTHON script file:
    1. sudo nano wunder.py
    2. Add to the file the following:
      1. #!/usr/bin/env pythonimport shutil
        import os
        os.system(“bash -c /home/pi/wunder.sh”)
  5. Make the PYTHON script executable:
    1. sudo chmod -x wunder.py
  6. Add to the CRONTAB  an updating call to the script:
    1. sudo crontab -u pi -e    (-u for User that is pi and -e for Edit)
    2. Add the following for 15-min updates intervals:
      */15 * * * * python /home/pi/wunder.py >> /home/pi/script.log &
  7. FInished

Weewx General Topics

Corrupt station memory

If you have a Vantage station, the problem might be because the data on board your console has gotten garbled. The way the Davis Vantage series works is that the software (weewx in this case) asks the console for all archive data “since” some time. The console then downloads the records one at a time. After it gets to the very last one, the memory wraps around, and the timestamp will suddenly jump backwards in time a couple weeks — this how the software knows it has downloaded the last record and so it stops. However, if the internal memory gets garbled, the console will immediately return archives in the past, and so it looks like the timestamps have decreased in value and so weewx figures that is it: there is no more data. I have received reports from a couple of users who have had this problem. There seems to be two fixes: Unplug the console, take out the batteries, and wait a minute or two. This will cause the console software to internally reboot. In one case this has fixed the problem without data loss. If all else fails, clear the memory of the console using the utility wee_device. This may cause loss of data, but usually works.

adjust paths as necessary: wee_device –clear-memory

Weewx and running a report on-demand

sudo wee_reports /etc/weewx/weewx.conf

Camera Installation


General Utilities

  1. Check how much RAM is installed:

free -h

total used free shared buff/cache available
Mem: 3.8Gi 470Mi 1.7Gi 136Mi 1.6Gi 3.1Gi
Swap: 99Mi 0B 99Mi

2. Check Disk Free Space

DF -h

Filesystem Size Used Avail Use% Mounted on
/dev/root 117G 7.4G 105G 7% /
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 2.0G 24M 1.9G 2% /dev/shm
tmpfs 2.0G 8.6M 1.9G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 53M 200M 21% /boot
tmpfs 391M 0 391M 0% /run/user/1000

MariaDB Notes

Editing the database schema:

  1. First log on to MYSQL:
    1. sudo mysql -u<username> -p
    2. enter <password>
  2. General utilities:
    1. SHOW DATABASES; # lists all databases created
    2. DESCRIBE <table>; # e.g. socdata in records
  3. Select a database to work on:
    1. USE <database>;
    2. SELECT * FROM <tablename> # shows all rows
    3. ALTER <tablename> ADD COLUMN  <name> <type> #e.g. ALTER socdata ADD COLUMN kwh float
    4. UPDATE <<databasename>.<tablename> SET <columnname>=’value’ WHERE <columnname>=’value’ && date=”2021-05-15 15:25:00″
  4.  Access database:
    1. sudo mysql -uroot -p
  5. Show databases:
    1. show databases;
  6. Connect to database:
    1. use ‘database name’;
  7. Show Tables:
    1. show tables;
  8. Show Columns:
    1. show columns from ‘database name’;
  9. Show Rows:
    1. select * from ‘database name’;
  10. Add a Column
    1.  ALTER TABLE battery_data ADD COLUMN batterycharge FLOAT;

Argon One M.2 Case – auto power on after power failure

  1. Install i2c tools
    1. sudo apt-get install i2c-tools
  2. Modify i2c settings for case by entering this at the command-line and you have an auto-power-up Pi:
    1. i2cset -y 1 0x01a 0xfe