Ever since I launched my weather site, I have linked to the Kalbar webcam which is one of the many webcams published on the Brisbane Storm Chasers site. While this camera has excellent detail and gives a good indication of approaching storms, it is located about 10km from my place. This camera is pointed in the direction of Cunningham’s Gap on the Great Dividing Range from where we can get storms however it is more common for the storms to come from a slightly more southerly direction just out of camera shot.
I have always wanted to have my own webcam set up to keep an eye on the weather and as my place has a reasonable elevation, I always thought it was doable. Of course, as my son told me, I could just look out the window but where is the fun in that?
To put this into action, I’ve been toying with the idea of getting an IP security camera as the outdoor ones come in a weatherproof enclosure, are wireless and seem relatively easy to set up. Something like the Foscam F18905W which sells for about AUD$180 has all the features I would need.
But then I have also been interested in the Raspberry Pi camera module. This is a 5 MP 1080p camera which to my mind is much better than the 1.3 MP 960p Foscam. I’d need a dedicated Raspberry Pi (maybe an A+ model), a Wi-Fi dongle, a power supply, the camera module and an enclosure. I should be able to put this together for around AUD$100. One negative with the Raspberry Pi module is the field of view is only 54° compared to 70° on the Foscam.
So this is what I have done albeit on a trial basis. I already had a Raspberry Pi 2 Model B with a micro SD card, power supply and Wi-Fi dongle so I purchased a camera module to go with it for AUD$39.00.
I put it all together without any enclosure and temporarily taped the camera module to the inside of a bedroom window that had a suitable view. This was the easy bit.
Actually it all ended up being reasonably easy. Here is the process I used to get the camera working and publishing a regular photo to my web site.
First up I loaded a fresh Raspbian image (the operating system) on a micro SD card, plugged it into the Pi and configured it so that the Pi ran headless (remote access over SSH without an attached keyboard or monitor) and used Wi-Fi over the attached dongle. I also went into
raspi-config and enabled the camera.
I didn’t have too many false starts after this. After doing some research on the web, I got the camera to take some stills using the
raspistill -o cam.jpg command. Easy as!
So I can take a photo but I also want to resize and overlay some text on the photo such as the time the photo was taken and what it shows. So after some research I installed ImageMagick.
sudo apt-get update sudo apt-get install imagemagick
ImageMagick has a number of commands like
convert -resize or
convert -annotate that I then used to do what I wanted. To minimise the size of the images being uploaded to the web I also looked at stripping the exif data from the images. ImageMagick has a command to do this as well:
mogrify -strip. It’s a powerful little program that I feel I’m only scratching the surface of.
Okay, I can produce images and overlay text on them by running commands at the command prompt but I want to automate this. So I put the commands together in this shell script that I called camera.sh. I wanted two images: one normal size image and a smaller thumbnail for inclusion on my main weather page. As the images are different sizes, the overlayed text also had to be a different font size to remain readable. So this is the script I came up with:
#!/bin/bash # Take image with camera raspistill -vf -hf -w 1366 -h 844 -q 30 -th none -o /path to/camera/weathercam.jpg # Create a smaller resolution copy for weather page convert /path to/camera/weathercam.jpg -resize 550x340 \ /path to/camera/weathercam-550x340.jpg # Overlay text on original image convert /path to/camera/weathercam.jpg -pointsize 18 -fill white \ -gravity southwest -annotate 0 'WeatherCam' \ -gravity south -annotate 0 'Boonah - looking SSW' \ -gravity southeast -annotate 0 %[exif:DateTimeOriginal] \ /path to/camera/weathercam.jpg # Overlay text on copy of image convert /path to/camera/weathercam-550x340.jpg -pointsize 12 -fill white \ -gravity southwest -annotate 0 'WeatherCam' \ -gravity south -annotate 0 'Boonah - looking SSW' \ -gravity southeast -annotate 0 %[exif:DateTimeOriginal] \ /path to/camera/weathercam-550x340.jpg # Remove EXIF data to reduce filesize mogrify -strip /path to/camera/weathercam.jpg mogrify -strip /path to/camera/weathercam-550x340.jpg
The next hurdle is to upload the images to my web-server. I installed wput to do this. Wput is a command line ftp-client used to upload the files.
sudo apt-get install wput
Then after playing with it to see how it works, I created another shell script upimg.sh to automate uploading the images.
#!/bin/bash #Upload main image to web server wput -B -u -nc /path to/camera/weathercam.jpg ftp://user:firstname.lastname@example.org/path/weathercam.jpg #Upload smaller image to web server wput -B -u -nc /path to/camera/weathercam-550x340.jpg ftp://user:email@example.com/path/weathercam-550x340.jpg
4th June 2018 Edit: I no longer use wput to upload the images. I now use sftp. See this post for details
Both shell scripts had to be made executable before they could be run. As I’d saved both files in a directory bin in my home directory, I was able to do this by running:
chmod +x ~/bin/camera.sh chmod +x ~/bin/upimg.sh
The final step is to set the timing of when the scripts are run. I did this by modifying the crontab file to automatically call the above files every fifteen minutes. This means that at every quarter of the hour, a photograph is taken, processed into two images and uploaded to the web. The last two lines of the following crontab script are the ones that do this.
# Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any'). # # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command 0,15,30,45 * * * * /path to/bin/camera.sh 1,16,31,46 * * * * /path to/bin/upimg.sh
One concern I had is upsetting my neighbour if they saw the LED on the camera light up when it was taking a photo and thinking I’m recording their house. To avoid this, I disabled the LED by editing the config file.
sudo nano /boot/config.txt
and adding the following line to the end of the file before saving it.
So now I have my own weather cam image on my weather page.
Now I want to look at setting the camera up permanently and mounting it somewhere with a better view like on my roof. I’ve thought about getting one of the cheap dummy security cameras you see available and mounting the RPi and camera in that. This should be able to be hacked into a good weatherproof enclosure. I’ve also considered powering the camera from a battery pack and using a solar panel to charge the batteries. As long as the Wi-Fi signal can find its way back to my modem I should be laughing!
It would also be good to store the daily images and at a set time each day, merge them into a time lapse video for the day.
So these are the next steps. In the meantime, we can all enjoy the view of the weather from my son’s bedroom window.