- Installation of ConsoleWD - Weather Display for Raspberry Pi
- Streaming a live video feed from your weather webcam
- Automating the retreival of files from a source such as a webcam
Looking at options
- FTP - a less secure (passwords are sent as readable text) method and many places mentioned it was tricky to set up
- SFTP - a secure method, but again I was warned it was tricky to set up
- SCP - based on SSH and is a secure method - can be setup so that a password is not required to be sent at all
- SSH needs to be enabled on your Raspberry Pi. To do that, from the desktop under the main menu find Preferences - Raspberry Pi Configuration. Open that up and go to the Interfaces Tab and enable SSH. Click on OK
- SSH needs to be enabled on your webserver. This is normally done in the user.conf file for your account. Each hosting setup is different so I'd recommend asking your web host to help you with this if you don't know how. Of course for those hosting their weather sites with us, we can do that for you.
- SCP should also be installed on your webserver. It normally is by default, but if it isn't, check with your webhost.
- Your website will need to have a fixed IP - most have, but you should know what that IP address is
- You should know what your connection port is on your webserver (Computer 2). If it's port 22 then SSH will connect by default on that. If it's not then it needs to be specified.
Generating and copying the SSH keys
cd mkdir -p .ssh cd .ssh
SSH looks for keys in certian directories so we need to create a .ssh directory and then be in that directory when we generate the keys so they get saved there. Next type
ssh-keygen -t rsa
- id_rsa. This file needs to stay where it is. DO NOT share this file with anyone as if someone else has it they can access your Computer 2 or webserver
- id_rsa.pub - this is the public key file that needs to go on Computer 2 / your webserver
- look for a file called authorized_keys. If it doesn't exist, create it and then paste the key from id_rsa.pub into it, and then save the file.
- If the authorized_keys file already exists, open that file in a text editor and paste the key from id_rsa.pub, on the last line of this file. One key must be on one line, and each key must be on seperate lines.
chmod 0600 authorized_keys chmod 0700 /.ssh/
Testing the SSH key setup
ssh -p 23
Setting up the SCP connection
scp command syntax take the following form:
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
OPTION- scp options such as cipher, ssh configuration, ssh port, limit, recursive copy …etc.
[user@]SRC_HOST:]file1- Source file.
[user@]DEST_HOST:]file2- Destination file
Local files should be specified using an absolute or relative path, while remote file names should include a user and host specification. If you are looking for further options to use with SCP you can find them listed here.
#Now Use SCP to send to website # Options: C=compress, v=verbose logging,-P specifies the port if not port 22, -i specifies the location of the local key # tidied script scp -C -P23 -i /home/pi/.ssh/id_rsa $IMGFILE
- /home/huttweat/public_html/data is the destination file location. Not specifying the actual file name means scp will use the original filename
- $IMGFILE is the sourcefile, which is the variable used by our previous script to pull the file from a webcamera.
Putting everything together
#!/bin/bash # modifications by weather.net.nz with credit to alvinalexander.com # a shell script used to download an image from an IP Cam URL and scp to a website. # this is executed from a crontab entry. #Next line sets logging detail #set -x #Set Download variables # Put images in this directory (must exist) IMGDIR=/home/pi/myssd/WeatherD/webcam_images # wget output animated file ANIFILE=webcam.`date +"%Y%m%d%H%M"`.jpg # wget output webcam snapshot IMGFILE=jpgwebcam.jpg # Specify wget log files. If not specified these end up in the script output LOGFILEANI=wgetani.log LOGFILE=wget.log # Specify wget download url. NOTE: &characters are escaped URL=https://192.168.2.119/cgi-bin/api.cgi?cmd=Snap\&channel=0\&rs=wuuPhkmUCeI9WG7C\&user=admin\&password=123456 #Now go and get the file(s) from the webcam #Options -O is the output file -o is the log output file cd $IMGDIR wget $URL -O $ANIFILE -o $LOGFILEANI wget $URL -O $IMGFILE -o $LOGFILE #Now Use SCP to send to website # Options: C=compress, v=verbose logging,-P specifies the port if not port 22, -i specifies the location of the local key # tidied script scp -C -P23 -i /home/pi/.ssh/id_rsa $IMGFILE
Note that not all options are required, however these were the ones I needed to specify to get it to work for me.
One of the really nice things about this script is that it doesn't just work for webcam images. It will pull any file off your local machine / internet and publish it to your website/another machine, just by changing a few of the variables in the script around!
Finally a quick word about the cron job that calls this script every 15 mins that we set up in the previous article. Does it need changing? Well no not really. It's still going to call this script with the scp command in it and send an updated image to the website every 15 mins.
Supporting us and feedback