{"id":233,"date":"2015-11-26T09:00:45","date_gmt":"2015-11-25T23:00:45","guid":{"rendered":"http:\/\/stevoz.com\/myweatherblog\/?p=233"},"modified":"2018-06-04T14:27:53","modified_gmt":"2018-06-04T04:27:53","slug":"adding-a-weather-cam-image-to-my-site","status":"publish","type":"post","link":"https:\/\/stevoz.com\/myweatherblog\/2015\/11\/adding-a-weather-cam-image-to-my-site\/","title":{"rendered":"Adding a weather cam image to my site"},"content":{"rendered":"<div style=\"width: 635px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1.jpeg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1-624x386.jpeg\" alt=\"image\" width=\"625\" height=\"386\" class=\"aligncenter size-large wp-image-254\" srcset=\"https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1-624x386.jpeg 624w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1-300x185.jpeg 300w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1-1024x633.jpeg 1024w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1.jpeg 1366w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">An evening shot from my Pi cam&#8230;<\/p>\n<\/div><p>Ever since I launched my <a href=\"http:\/\/http:\/stevoz.com\/weather\">weather site<\/a>, I have linked to the <a href=\"http:\/\/www.weathercamnetwork.com.au\/kalbar.html\">Kalbar webcam<\/a> 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&#8217;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.<\/p><p>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?<\/p><p>To put this into action, I&#8217;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 <a href=\"http:\/\/www.foscamaustralia.com.au\/Foscam-F18905W-30M-H264-720P-HD-Wireless-IP-Camera-Outdoor-Silver-Infrared-Cut-Filter-2yr-Warranty\">Foscam F18905W<\/a> which sells for about AUD$180 has all the features I would need.<\/p><p>But then I have also been interested in the <a href=\"http:\/\/elinux.org\/Rpi_Camera_Module\">Raspberry Pi camera module<\/a>. This is a 5 MP 1080p camera which to my mind is much better than the 1.3 MP 960p Foscam. I&#8217;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&#176; compared to 70&#176; on the Foscam.<\/p><p>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.&nbsp;<\/p><p>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.<\/p><p><a href=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image.jpeg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image-624x624.jpeg\" alt=\"image\" width=\"450\" height=\"450\" class=\"aligncenter size-large wp-image-251\" srcset=\"https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image-624x624.jpeg 624w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image-150x150.jpeg 150w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image-300x300.jpeg 300w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image-1024x1024.jpeg 1024w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image.jpeg 1738w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><\/p><p>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.<\/p><p>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 <code>raspi-config<\/code> and enabled the camera.<\/p><p>I didn&#8217;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 <code>raspistill -o cam.jpg<\/code> command. Easy as!<\/p><p>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.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo apt-get update\r\nsudo apt-get install imagemagick<\/pre><p>ImageMagick has a number of commands like <code>convert -resize<\/code> or <code>convert -annotate<\/code> 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: <code>mogrify -strip<\/code>. It&#8217;s a powerful little program that I feel I&#8217;m only scratching the surface of.<\/p><p>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:<\/p>\n<pre class=\"brush: bash; light: false; title: camera.sh; notranslate\" title=\"camera.sh\">#!\/bin\/bash\r\n\r\n# Take image with camera\r\nraspistill -vf -hf -w 1366 -h 844 -q 30 -th none -o \/path to\/camera\/weathercam.jpg\r\n\r\n# Create a smaller resolution copy for weather page\r\nconvert \/path to\/camera\/weathercam.jpg -resize 550x340 \\\r\n    \/path to\/camera\/weathercam-550x340.jpg\r\n\r\n# Overlay text on original image\r\nconvert \/path to\/camera\/weathercam.jpg -pointsize 18 -fill white \\\r\n    -gravity southwest -annotate 0 'WeatherCam' \\\r\n    -gravity south     -annotate 0 'Boonah - looking SSW' \\\r\n    -gravity southeast -annotate 0 %&#x5B;exif:DateTimeOriginal] \\\r\n    \/path to\/camera\/weathercam.jpg\r\n\r\n# Overlay text on copy of image\r\nconvert \/path to\/camera\/weathercam-550x340.jpg -pointsize 12 -fill white \\\r\n    -gravity southwest -annotate 0 'WeatherCam' \\\r\n    -gravity south     -annotate 0 'Boonah - looking SSW' \\\r\n    -gravity southeast -annotate 0 %&#x5B;exif:DateTimeOriginal] \\\r\n    \/path to\/camera\/weathercam-550x340.jpg\r\n\r\n# Remove EXIF data to reduce filesize\r\nmogrify -strip \/path to\/camera\/weathercam.jpg\r\nmogrify -strip \/path to\/camera\/weathercam-550x340.jpg<\/pre><p>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.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo apt-get install wput<\/pre><p>Then after playing with it to see how it works, I created another shell script upimg.sh to automate uploading the images.<\/p>\n<pre class=\"brush: bash; light: false; title: upimg.sh; notranslate\" title=\"upimg.sh\">#!\/bin\/bash\r\n\r\n#Upload main image to web server\r\nwput -B -u -nc \/path to\/camera\/weathercam.jpg ftp:\/\/user:password@web-server.com\/path\/weathercam.jpg\r\n\r\n#Upload smaller image to web server\r\nwput -B -u -nc \/path to\/camera\/weathercam-550x340.jpg ftp:\/\/user:password@web-server.com\/path\/weathercam-550x340.jpg<\/pre>\n<blockquote><p>4th June 2018 Edit: I no longer use wput to upload the images. I now use sftp. See <a href=\"http:\/\/stevoz.com\/myweatherblog\/2018\/06\/changing-my-weathercam-uploads-from-ftp-to-sftp\/\">this post<\/a> for details<\/p><\/blockquote><p>Both shell scripts had to be made executable before they could be run. As I&#8217;d saved both files in a directory bin in my home directory, I was able to do this by running:<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">chmod +x ~\/bin\/camera.sh\r\nchmod +x ~\/bin\/upimg.sh<\/pre><p>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.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">crontab -e<\/pre>\n<pre class=\"brush: bash; light: false; title: crontab; notranslate\" title=\"crontab\"># Edit this file to introduce tasks to be run by cron.\r\n#\r\n# Each task to run has to be defined through a single line\r\n# indicating with different fields when the task will be run\r\n# and what command to run for the task\r\n#\r\n# To define the time you can provide concrete values for\r\n# minute (m), hour (h), day of month (dom), month (mon),\r\n# and day of week (dow) or use '*' in these fields (for 'any').\r\n#\r\n# Notice that tasks will be started based on the cron's system\r\n# daemon's notion of time and timezones.\r\n#\r\n# Output of the crontab jobs (including errors) is sent through\r\n# email to the user the crontab file belongs to (unless redirected).\r\n#\r\n# For example, you can run a backup of all your user accounts\r\n# at 5 a.m every week with:\r\n# 0 5 * * 1 tar -zcf \/var\/backups\/home.tgz \/home\/\r\n#\r\n# For more information see the manual pages of crontab(5) and cron(8)\r\n#\r\n# m h  dom mon dow   command\r\n0,15,30,45 * * * * \/path to\/bin\/camera.sh\r\n1,16,31,46 * * * * \/path to\/bin\/upimg.sh<\/pre><p>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&#8217;m recording their house. To avoid this, I disabled the LED by editing the config file.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo nano \/boot\/config.txt<\/pre><p>and adding the following line to the end of the file before saving it.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">disable_camera_led=1<\/pre><p>So now I have my own weather cam image on my weather page.<\/p><p><a href=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image2.jpeg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image3.jpeg\" alt=\"image\" width=\"550\" height=\"340\" class=\"aligncenter size-full wp-image-273\" srcset=\"https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image3.jpeg 550w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image3-300x185.jpeg 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><\/p><p>Now I want to look at setting the camera up permanently and mounting it somewhere with a better view like on my roof. I&#8217;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&#8217;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!<\/p><p>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. <\/p><p>So these are the next steps. In the meantime, we can all enjoy the view of the weather from my son&#8217;s bedroom window.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":254,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[10],"tags":[],"class_list":["post-233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-weather-site"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/11\/image1.jpeg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5uBIO-3L","_links":{"self":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":2,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts\/233\/revisions\/369"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/media\/254"}],"wp:attachment":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}