Tag Archives: webcam

sSMTP Installing and Configuration and Use Tips

Recently I was looking at creating a method of sending a warning email when ever my house temperature went below a threshold. I remembered that sSMTP was a simple way to send automated emails and CRON emails. I have some simple notes on what I did.

Installation

Very easy, just use apt-get from the command line…

sudo apt-get install ssmtp

Configuring

The configuration file (/etc/ssmtp/ssmtp.conf) can be edited using any test editor you typically use.

 

Config at /etc/ssmtp/ssmtp.conf

Below is my config file with the critical info blocked out. Lines in Red are what I modded to get ssmtp working for me.

The key pieces to get it working for me at least were…

hostname = My ISP’s domain

root = my complete email that I use at the ISP

mailhub = I looked it up in Thunderbird, it is the smtp.myispsdomain.net part.

AuthUser=my complete email that I use at the ISP. It might be different for you. Years ago it used to be just the user name part of email without the domain.

AuthPass = The password that goes along with my email.

I commented out the defaults for the ones that existed in the code.

The config file is a bit ugly after I touched it but I was trying to get this up and running quick and didn’t clean it up. But, hey it works!

 

#
 # Config file for sSMTP sendmail
 #
 # The person who gets all mail for userids < 1000
 # Make this empty to disable rewriting.
 #root=postmaster  <--- comment out
 
# The place where the mail goes. The actual machine name is required no
 # MX records are consulted. Commonly mailhosts are named mail.domain.com
  #mailhub=mail <-- comment out
 
# Where will the mail seem to come from?
 #rewriteDomain=
# The full hostname
 #hostname=raspberrypi <--- I was testing and kill this, failed to work
 # hostname has to be the mail domain! Or else it complains about
  # the raspberrypi part! The STMP server at frontier does that is.
  hostname=myispdomain.net
# Are users allowed to set their own From: address?
 # YES - Allow the user to specify their own From: address
 # NO - Use the system generated From: address
 #FromLineOverride=YES <-- Commented out and set below, I was testing!
# New Code put here 11302015
  root=me@myispdomain.net
  mailhub=smtp.myispdomain.net
AuthUser=me@myispdomain.net
AuthPass=myemailpassword
FromLineOverride=YES
#UseSTARTTLS=YES <-- Tried this, I didn't need it for my ISP.

CRON Email

Once installed if you or root on the machine have any CRON jobs, you will start to get email from them. You can stop this by appending …

> /dev/null 2>&1

to the end of the commands that are being run by CRON. Which will cut back on the emails that you will receive.

 Testing

I installed mail utils to allow sending simple messages…

sudo apt-get install mailutils

Then I sent a message via the command line…

echo "Test" | mail -s "Test Subject" me@myispsdomain.net

…and I was able to see it work OK.

Send files via email

If you want to send files you have to install mpack.

sudo apt-get install mpack

 

Then you can send files to your email like this…

mpack -s "Test" /tmp/web/log.txt me@myispsdomain.net

 Command Line Usage

If you execute ssmtp with an email address it will let you create an email from the command line. Which is good for quick emails to for example remind yourself of something, or send a snippet of code to yourself. You edit the email in the form of the example below and hit Ctrl-D when done and then it will send out.
ssmtp recipient_email@example.com
The following is an example right off the command line. Note the one line of space after the Subject, this is a must have…
erick@raspberrypi ~ $ ssmtp me@myispdomain.net
To:me@myispdomain.net
From:me@myispdomain.net
Subject:This is a test of ssmtp from the command line!

Hello there this is a test of the ssmtp from the command line tool. It could be used to send a reminder or small snips of code. Use Ctrl-D when you are done.

It is called up by using ssmtp emailtosendto@domain.com

Bye,
Me

Example of Sending CPU Temp Warning Emails

When I am away from home I can infer if my house is running to cold, which may indicate a problem with the furnace. The Raspberry Pi is light loaded, usually just idling, so the CPU temperature tracks the room temperature, with an offset. When I am away, I set the house thermostat at 47 degrees F. If it drops below this value the CPU temperature of the Raspberry Pi will drop below 34 degrees Celsius. So I can just have it send me an email if this happens. Then I can double check a log that is created of the temperature reading to see what is going on. Also I run a webcam pointed at an actual thermometer for a sanity check, this is logged by using fswebcam to take an hourly snapshot. So I have my bases covered for the most part. Obviously if the power is out, I am in the dark about the temperature, because the whole thing is down! Solving that is a future project.

Below is the snippet of code from a shell script that sits in /etc/cron.hourly that handles the warning emails that are sent to 2 addresses. variables mailaddr and mailaddr2.

temp is the CPU temperature in Celsius as an integer stripped using cut from the thermal_zone0 reading.

minimum and maximum are my temperature thresholds. I don’t care much about maximum but I have it set at 65 Deg. C. just in case.

# Read the temp and cut it to grab leftmost 2 characters, integer Temp
temp="`cat /sys/class/thermal/thermal_zone0/temp | cut -c1-2`"
#echo $temp

# Mail if about or below the limits
if (( $temp > $maximum )); then
   #echo "above"
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi HIGH CPU Temp > $maximum" $mailaddr
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi HIGH CPU Temp > $maximum" $mailaddr2

elif (( $temp < $minimum )); then
   #echo "below"
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi LOW CPU Temp < $minimum" $mailaddr
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi LOW CPU Temp < $minimum" $mailaddr2

fi

Boot Email

I want to know if an when the Raspberry Pi I run 24/7 ever reboots due to a power outage, so I have it send me an email. The line of code below handles it and is in the root crontab. I have it sleep for 180 seconds first, then send the email. This allows the cascaded routers which I have the Pi connected to and the cable modem, time to come on line.

@reboot sleep 180 && echo "Rasp Pi Rebooted" | mail -s "Rasp Pi Reboot!" me@myispsdomain.net

I also log boots in a file that I can view online, just to keep track in one record.

@reboot date >> /var/www/bootlog.txt

Keeping track of boots helps for instance if I am away from home and the power goes out. If I get the email that the Pi rebooted, I can check to see how long the power was down and what the temperature of the house is to see if all is well.

Every hour I take a time/date stamped webcam snapshot of a thermometer so I can just look to see how many are missing and have a rough estimate of how long the power was out and how cold the house got and verify that it is getting warmer because the furnace is on!

In the future I will connect a BME280 sensor to the Raspberry Pi that will be able to read ambient room temperature directly, along with humidity and barometric pressure. So I won’t have to infer the house temperature via the CPU temperature.

Resources

This is the page I used to configure ssmtp on the Rasp Pi.

http://www.raspberry-projects.com/pi/software_utilities/email/ssmtp-to-send-emails

Automatic Server Status Page Creation Update

In January 2015 I created a post about automatically creating a status page for a Linux server that I have. Typically this is put under a restricted directory and allows you to see a snapshot of what is happening with the server. I run it by putting the scripts in the /etc/cron.hourly directory on a Linux PC and a Raspberry Pi running Linux.

It serves as a simple way to check up on the server without having to use a tool such as Webmin that requires a login. It also keeps a trail of log files that get rotated on a monthly basis, so there is always a few old ones around to track down any problems and patterns in the operation.

I have found this information useful when I have traced down malfunctions that can occur when setting up a server and also when I was trying to get a webcam up and running and had the USB bus hang up a few times when the cam was overloaded with too much light.

In the new script file I fixed a bug by adding parenthesis around a line that I was trying to echo and I added code to run the w command to show a quick picture on who is logged in, how long the server has been up and running and the values for the average load on the server at the 1, 5 and 15 minute marks.

Logcreate Script

#!/bin/dash
# Remove old log
rm /var/www/status/log.txt
# Print logged outputs into new log.txt
date >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
tail /var/log/syslog >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
free >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
df -h >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
# Top memory using processes http://www.commandlinefu.com/commands/view/3/display-the-top-ten-running-processes-sorted-by-memory-usage
#ps aux | sort -nk +4 | tail >> log.txt
echo "USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND" >> /var/www/status/log.txt
ps aux | sort -nrk 4 | head >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
# Logged in User info using w command
w >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
echo >> /var/www/status/log.txt
# Copy log.txt into the full log that is collected
cat /var/www/status/log.txt >> /var/www/status/fulllog.txt
# Create a free standind copy of the process tree
pstree > /var/www/status/pstree.txt

Alternate Version

I also created a version of the script for a desktop Linux PC that does not have Apache installed.  In it I use a DIR variable to contain the directory that I want the log.txt file stored.

 #!/bin/dash

# User defined variables
# No trailing / on DIR!
DIR=/home/erick/status

# Remove old log
rm $DIR/log.txt
# Print logged outputs into new log.txt
date >> $DIR/log.txt
echo >> $DIR/log.txt
tail /var/log/syslog >> $DIR/log.txt
echo >> $DIR/log.txt
free >> $DIR/log.txt
echo >> $DIR/log.txt
df -h >> $DIR/log.txt
echo >> $DIR/log.txt
# Top memory using processes http://www.commandlinefu.com/commands/view/3/display-the-top-ten-running-processes-sorted-by-memory-usage
#ps aux | sort -nk +4 | tail >> log.txt
echo "USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND" >> $DIR/log.txt
ps aux | sort -nrk 4 | head >> $DIR/log.txt
echo >> $DIR/log.txt
# Logged in User info using w command
w >> $DIR/log.txt
echo >> $DIR/log.txt
echo >> $DIR/log.txt
# Copy log.txt into the full log that is collected
cat $DIR/log.txt >> $DIR/fulllog.txt
# Create a free standing copy of the process tree
pstree > $DIR/pstree.txt

Rotation of Log

In the /etc/cron.monthly directory I have created a file that is called status-log-rotate and it will save backup copies of 2 months worth of the full concatenated server status logs.

#! /bin/bash
DIR=/home/erick/status
mv $DIR/fulllog.txt.1 $DIR/fulllog.txt.2
mv $DIR/fulllog.txt $DIR/fulllog.txt.1

Tweaks for Raspberry Pi

For the Raspberry Pi which has an SD card that I am trying to be conscious of writing to often. I have recently made some modifications to put the /tmp folder onto RAM using tmpfs. I create the hourly log underneath a folder there. Daily via a script it cron.hourly it gets concatenated into a daily log which is under a status folder that has restricted access. This gets appended once per day to the fulllog which actually lives on the SD card. The end result, no multiple hourly writes to the log file, just one append to the full log per day. The only downside is if the power drops and then some log entries will be lost for the day.

Logcreate runs from /etc/cron.hourly for Raspberry Pi

#!/bin/dash
# Set DIR, on Pi this is a temp location for log
DIR=/tmp/web

# Set fixed DIR FIXDIR for files that have to be stored on SD card
# Nevermind, just make a daily log and then copy that to the full log daily.
#FIXDIR=/var/www/status

# Remove old log

rm $DIR/log.txt
# Print logged outputs into new log.txt
date >> $DIR/log.txt
echo >> $DIR/log.txt
tail /var/log/syslog >> $DIR/log.txt
echo >> $DIR/log.txt
free >> $DIR/log.txt
echo >> $DIR/log.txt
df -h >> $DIR/log.txt
echo >> $DIR/log.txt
# Top memory using processes http://www.commandlinefu.com/commands/view/3/display-the-top-ten-running-processes-sorted-by-memory-usage
echo "USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND" >> $DIR/log.txt

ps aux | sort -nrk 4 | head >> $DIR/log.txt
echo >> $DIR/log.txt
# Logged in User info using w command
w >> $DIR/log.txt
echo >> $DIR/log.txt
echo >> $DIR/log.txt
# Copy log.txt into the full log that is collected
cat $DIR/log.txt >> $DIR/dailylog.txt
# Create a free standing copy of the process tree
pstree > $DIR/pstree.txt

dailylog-to-fulllog script, runs from /etc/cron.daily

#! /bin/bash

DIR=/tmp/web
FIXDIR=/var/www/status

echo "----------------------------------------------" >> $DIR/dailylog.txt
date >> $DIR/dailylog.txt
echo "----------------------------------------------" >> $DIR/dailylog.txt
cat $DIR/dailylog.txt >> $FIXDIR/fulllog.txt
rm $DIR/dailylog.txt

Logcreate Output from Raspberry Pi

Below is what the logcreate script will output to the log.txt file on a Raspberry Pi that I have running as a web server.

Sun Jul 12 14:17:01 EDT 2015

Jul 12 13:47:51 raspberrypi dhclient: DHCPACK from 192.168.1.1
Jul 12 13:47:52 raspberrypi dhclient: bound to 192.168.1.17 -- renewal in 40673 seconds.
Jul 12 13:59:01 raspberrypi /USR/SBIN/CRON[28010]: (erick) CMD (aplay /opt/sonic-pi/etc/samples/guit_e_fifths.wav)
Jul 12 13:59:07 raspberrypi /USR/SBIN/CRON[28009]: (CRON) info (No MTA installed, discarding output)
Jul 12 14:00:01 raspberrypi /USR/SBIN/CRON[28013]: (erick) CMD (/home/erick/fswebcam/cron-timelapse.sh >> timelapse.log)
Jul 12 14:00:23 raspberrypi /USR/SBIN/CRON[28012]: (CRON) info (No MTA installed, discarding output)
Jul 12 14:01:01 raspberrypi /USR/SBIN/CRON[28022]: (root) CMD (/home/erick/bin/usbreset /dev/bus/usb/001/004)
Jul 12 14:01:02 raspberrypi /USR/SBIN/CRON[28021]: (CRON) info (No MTA installed, discarding output)
Jul 12 14:09:01 raspberrypi /USR/SBIN/CRON[28053]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Jul 12 14:17:01 raspberrypi /USR/SBIN/CRON[28064]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

             total       used       free     shared    buffers     cached
Mem:        445804     424488      21316          0     106768     260516
-/+ buffers/cache:      57204     388600
Swap:       102396          0     102396

Filesystem      Size  Used Avail Use% Mounted on
rootfs          6.3G  3.1G  3.0G  51% /
/dev/root       6.3G  3.1G  3.0G  51% /
devtmpfs        214M     0  214M   0% /dev
tmpfs            44M  240K   44M   1% /run
tmpfs           5.0M  8.0K  5.0M   1% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p5   60M   19M   41M  32% /boot

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      2071  0.0  3.0  24896 13652 ?        Ss   Jun28   2:24 /usr/sbin/apache2 -k start
www-data 27745  0.0  1.5  25412  7084 ?        S    09:58   0:00 /usr/sbin/apache2 -k start
www-data 27744  0.0  1.5  24960  6760 ?        S    09:58   0:00 /usr/sbin/apache2 -k start
www-data 27743  0.0  1.5  25428  7116 ?        S    09:58   0:00 /usr/sbin/apache2 -k start
www-data 27742  0.0  1.5  25396  7036 ?        S    09:58   0:00 /usr/sbin/apache2 -k start
www-data 27538  0.0  1.5  25396  7032 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
www-data 27502  0.0  1.5  25404  7036 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
www-data 27501  0.0  1.5  25396  7044 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
www-data 27747  0.0  1.3  24936  6188 ?        S    09:58   0:00 /usr/sbin/apache2 -k start
www-data 27746  0.0  1.3  24936  6188 ?        S    09:58   0:00 /usr/sbin/apache2 -k start

 14:17:02 up 14 days, 12:56,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
erick    pts/0    192.168.1.5      14:04   10:39   1.70s  1.70s -bash
U.S.D.A. Forest Service Webcam Image - Cloud Peak, WY

Active Desktop Wallpaper using wget

It is nice to have a desktop wallpaper that is not static, I like to see some outdoor scene that has a good view and a dynamic sky. Wyoming certainly has some ever changing skies and nice terrain so I have a wallpaper background set to show the Cloud Peaks Wilderness in Wyoming that updates every hour.

It is possible to load a JPG file periodically from a source using the Linux built-in wget command. In the example below, I am loading a scene from Cloud Peak Wyoming that is captured by a US Forest Service Webcam. It is loading right into my home folder, it could be put in any place that you prefer.

There is a nice bunch of pictures taken by the Forest Service from all over the country and they provide some nice high resolution scenery. See the links at the bottom of this post.

Code for script file

#! /bin/bash
 rm /home/erick/cpwa1_large.jpg
 wget http://www.fsvisimages.com/images/photos-large/cpwa1_large.jpg

The code first removes the old copy of the image and then it uses the wget command to fetch a new copy.

.wgetrc

It is not necessary to modify .wgetrc to use wget, but I put this here as an FYI. There is a configuration file for wget. It is located at /usr/local/etc/wgetrc. More info on wget locations. You can make a copy of it and put it in your home directory. Once in the home directory any modifications to it will work for your user profile. I have mine modified to do a few non-standard things, one is to use timestamping which will make wget only download when the file it is trying to download is newer than the local copy.

# Set this to on to use timestamping by default:
timestamping = on

Secondly, I also added a line at the end of the file that puts an option for wget for limiting the rate of downloading. Otherwise wget will run as fast as possible and will use the entire bandwidth. This option can be used on a case by case basis by putting in the line when wget is called as well. Doing this makes it so wget doesn’t slow down your connection to the Internet a lot and doesn’t hit the server hard with high speed downloads, important if you are downloading multiple large files.

limit-rate=20k

It is also possible to add a bit of a delay between connections when downloading. This avoids hammering the server that you are downloading from when downloading multiple files. This makes it easier on the server load and makes your download activity less likely to be obnoxious to the folks running the server that you are downloading from. Obnoxious down-loaders and site scrapers are more likely to get banned I would imagine if someone notices a spike in server load and pins it down to the IP address.

# It can be useful to make Wget wait between connections.  Set this to
# the number of seconds you want Wget to wait.
wait = 1

Some sites go as far as prohibiting downloads unless the user agent has a string inside of it. I didn’t do this yet as I have not had a problem with this issue. But it is possible to set the user-agent via --user-agent=“Acceptable String Here”

More on user-agent modification

CRON entry

01 08-22 * * * /home/erick/cpwa1/wget-cpwa1.sh

Using crontab -e, a line can be loaded into your CRON file to run the script periodically. The one above runs every hour 1 minute after the hour between 8AM and 10PM. There is no sense in loading nighttime pictures so that is why the times are bounded to load pictures during daylight hours ( right now) for Mountain Daylight Time. The picture I load is update around 59 minutes after the hour so loading 1 minute after the hour provides a bit of a guard band of time.

USDA Forest Service Webcams

USDA Forest Service Real Time Image Description Page
USDA Forest Service Real Time Image Gallery

Fermented Figs Timelapse

Nothing beats combining two things that are interesting together. I’ve been into fermenting foods and beverages since the late 1990’s and have been experimenting with timelapse photography since late in 2013 ( One of the first projects I set up and Ubuntu Server for ). Combining them together has been an interesting experience lately.

Recently I bought a 50.5 Ounce glass container with a gasketed lid. I got the idea from reading The Art of Fermentation by Sandor Ellix Katz, a must have if you are considering getting serious about fermentation, it covers a lot of territory on the fermentation landscape. This jar is ideal for some fermentation experiments as any pressure built up in the container would vent via the gasketed lid.  A lot of times, I don’t worry about pressure build up, because I am close to home and can vent it manually. But this time I was going to be away so this jar would be good to use. I decided to try to ferment some figs in it and create a time lapse video by taking photos every 4 minutes. I ran it for a week, almost 2400 frames.

The Ferment Mixture

The figs were a bit on the hard side so they were not getting used up to much and I decided that they would be good candidates for a fermentation experiment. The fermentation was started by cutting up the figs into small bits and added some sugar water and a pinch of bread yeast. Normally I would have let them ferment naturally based on what wild yeasts are present on the fruit, but I wanted a vigorous fermentation that got going quickly in order to capture the action for the timelapse video.

Timelapse Video Setup

The setup for the timelapse video was a laptop running Ubuntu with Apache and a webcam. The program used to take the frames for the timelapse video is fswebcam ( which I cover in the post on Bread Dough Rising Timelapse GIF ). The frames were taken every four minutes and saved into a folder underneath my home directory. Additionally a frame was copied to the /var/www directory to allow it to be seen on the web. Plus, I have a symbolic link from /var/www to a directory called fswebcam under my home directory. This directory holds the scripts to run fswebcam, under this is a directory called timelapse which collects all of the frames. This allows me to flip through these from the web as well, so I can keep track of the fermentation progress.

I went away for a few days while I was running the timelapse frame capture and it was nice to be able to view it to check on the progress. To get it online, I basically added a virtual server on the router for port 80, pointing to the internal IP address of the laptop, which was hooked to the router via WiFi. This worked flawless and I was able to periodically check in on the fermentation while on the road.

Fig Fermentation Timelapse Photography Setup
Fig Fermentation Timelapse Photography Setup

 

Timelapse Video AVI

Fermenting Figs 1 frame every 4 minutes for 31s of video

 

 

 

Bread Dough Rising Time Lapse GIF

I do a lot of baking of fresh home made bread and I play around with time lapse photography from time to time. It seemed natural to put together a time lapse video of bread dough rising.

How it was done

I have used the Fire Storm fswebcam program for Linux to trigger web-cams to take periodic frames to monitor my house when I was away last winter. By being able to take periodic frames, fswebcam also makes it easy to do time lapse photography.

Basically for this GIF animation, the camera is triggered 10 times per hour. I run it under Linux using a Bash shell script that  time and date stamps the images when they are saved and creates folders based on the date. Then I open up the GIMP graphics editor and use File-> Open as Layers to bring all the images in, 140 in this case.  Then Filters-> Animation->Optimize (for GIF) creates the animation. I then save it as a GIF with 100ms delay between frames and allow looping. I did find another way to create videos found under the section How To Make a movie, under the section that talks about doing it via SSH on the Raspberry Pi, on the site, How To Capture Time-Lapse Photography With Your Raspberry Pi and DSLR or USB Webcam

Bread Dough Rising Animated GIF
Bread Dough Rising Animated GIF
 Bread Dough

The bread dough is a standard type of dough that I use often. It starts with 100g water and 100g white unbleached flour with a pinch f yeast as a poolish. This is left in a container overnight. Then 2 cups of flour, approximately 10 grams of salt and another pinch of yeast are added and thoroughly mixed. Water is added to the poolish, I start with about 1/2 cup. It is all mixed together adding more water if needed. It forms a dough ball that is worked for 1-2 minutes. Then I let it sit for 15 minutes. Water is contained in the starch bonds, this water is released during the working of the dough, it has a bit of a time delay and it will release even more water for a while after it has been worked. Allowing it to rest for 15-30 minutes allows the water to come out of the bonds and at that point you can judge whether or not the proper amount of water/flour ratio exists by the feel. Then I let the dough rise in a bowl that was coated with olive oil. My standard practice would not dictate letting it rise in open air overnight, effectively this dough has over proofed, but to take the pictures, I decide to just let it go and do it’s thing. Normally, it would be punched down a few times and if I am not ready to make it, it might go in the fridge overnight.

How did it come out by just letting it go and rise on it’s own? Surprisingly  the end product was OK, I actually baked it as in the Pyrex bowl and it was a fairly good bread after all. Baked at 400 F for about 40 minutes. I preheated the oven with small bowls of water in it to add moisture as well, leaving them in while the bread baked. This enhances the crust of the bread.

Technical details on capturing the frames

fswebcam

I used Fswebcam to capture the images. It has to be compiled from the source code. Below are my notes related to fswebcam. I had a bit of a hard time getting it to run last year, but the essence of what I had to do is captured below.

————————————————————————————
fswebcam – Small and simple webcam software for *nix.

Created by Philip Heron <philATCHARACTERsanslogic.co.uk>
http://www.sanslogic.co.uk/fswebcam/

This is the program used to generate images for a webcam. It captures a number
of frames from any V4L or V4L2 compatible device, averages them to reduce noise
and draws the details on it using the GD Graphics Library which also handles
compressing the image to PNG or JPEG.

Installing fswebcam
sudo apt-get install fswebcam

Alternatively install via the DEB packages below if you want a newer version that apt can install, especially if it installs the 2009 version, which it will do if you are using an older version of Ubuntu Linux. Try the latest one that will work, I was able to get a new version that did not complain about missing packages.

DEB packages, try one of these first

I first ran fswebcam on Ubuntu 10.04 and ran into issue with an old webcam (Using palette SGRBG8 was not supported and I got an unsupported palette error), plus all of the features advertised for the fswebcam such as labeling the photos and printing a time stamp on them was not working. It was probably in the works and didn’t make it into the release, or something on my installation was not supporting the label adding feature. But I was able to get the 20101118 installed via a DEB package above.

If using dpkg to install one of the deb packages fails. Or in the case you want to work through compiling this code, follow the guidelines below, which do not cover all cases.

I did compile from scratch years ago to get a newer version of fswebcam installed, beyond what the package manager would install. I have found out that dpkg will install version 20101118 on Ubuntu 10.04 without complaint. Beyond that version, dpkg will complain about missing dependencies. I was able to compile the version labelled 20110707 and that ran on 10.04. If you need to find the version of fswebcam use….

fswebcam --version

The versions currently run to 20140113, trusty release, as of 11/26/2014.

 

Installing GD Library, do this before installing fswebcam

This part gave a bit of a hard time as my notes below state that there was a few failed attempts to get fswebcam up and running.

sudo apt-get install libgd2-xpm-dev
 ./configure --prefix=/usr
 make
 sudo make install

NOT SURE IF THIS IS NEEDED

But I actually tried this first, instead of the command sequence above…
Downloaded libgd-2.1.0
cd to the libgd-2.1.0 directory
then ran…

./configure
 make
 sudo make install

Then tried to compile fswebcam again and it complained about missing JPEG GD package, so did  the compile again for GD with this command sequence instead…

./configure --with-jpeg --with-png --with-freetype
 make clean
 make
 sudo make install

FAILED

Tried this…

install php-gd

FAILED

So I think the first method of config,make,install of libgd2-xpm-dev is the one to try, first!
I only put the failed stuff here because I am not sure if doing the failed stuff first put in JPG, freetype or something that made things work once ibgd2-xpm-dev was loaded in.

Compile and Install fswebcam

Download the source code from http://www.sanslogic.co.uk/fswebcam/ and unzip in a directory named something useful under you home folder. Use tar to extract it.

tar xvzf fswebcam-DATECODE.tar.gz

Best to use sudo make install so that the files wind up being able to be put where they need to be.

Run the following commands in the source folder to build and install fswebcam:

./configure --prefix=/usr
 make
 make install

It’s only requirements are that the GD library be installed with JPEG, PNG
and FreeType support.

Checking to see if the webcam is being read by the PC

Command to see what devices are hooked up to the USB for video…

ls /dev/video*

There is also a porgram called Cheese that can be installed via the package installer for Ubuntu. This lets you see the video live from the web cam. It makes it easy to adjust distance, angles, lighting and focus the cam while setting up the shot.

Autocam/Breadcam

I created autocam.sh to be called by watch periodically in order to snap a photo, name it the yr,month,day:time.jpg and put it in a created folder label for the date. Then I used to copy to Wuala mirrored path, which would automatically load it onto a Wuala cloud drive. The script below has the Wuala stuff ripped out. At the bottom of this post there is an explanation on how to use Wuala as an NFS drive.

For example, call bash script every 10 seconds…

watch -n 10 bash autocam.sh

Remember to chmod u+x autocam.sh so that it can be made into an executable script.

Autocam.sh code
#!/bin/bash
# this is the command to run this with watch -n 3579 bash autocam.sh for hourly rate at 255 frames to image
 # this is the command to run this with watch -n 350 bash autocam.sh for 10x hourly rate
# /%Y%m%d/hour-%H/%Y-%m-%d-%H:%M:%S
#now is the filename for the date stamped jpg file
 now=$(date +"%Y-%m-%d-%H:%M:%S")
#dir is the directory that is dated as the date of the picture. I need an IF statement around this so it doesn't keep creating the same dir.
 dir=$(date +"%Y%m%d")
mkdir $dir
#pathnow, I don't think is needed anymore.
pathnow=$(date +"%Y%m%d")
#filename="webcam.$now.jpg"
#filename="$now.jpg"
 # example filename: my_program.2012-01-23-47.log
#fswebcam  -S 15 --flip h --jpeg 90 --shadow --title "erick cam" --subtitle "Home" --info "Monitor: Active @ 1 fph" --save $now.jpg  --device  /dev/video0
 fswebcam  -S 15 --jpeg 90 --shadow --title "erick webcam" --subtitle "Dough Rising" --info "Monitor: Active @ 10 fph" --save $now.jpg  --device /dev/video0 -F 50
# Copy cam pic to file that the FTP program will send to the frontiernet.net site.
 cp $now.jpg cam1.jpg
#move local copy to local directory only and copy for FTP!
 mv $now.jpg $dir
#put on website to embed into page
HOST='ftp.ftplocation.net'
 USER='xxxxxxxxx'
 PASSWD='xxxxxxxx'
 FILE='cam1.jpg'
ftp -n $HOST <<END_SCRIPT
 quote USER $USER
 quote PASS $PASSWD
 cd public_html
 put $FILE
 quit
 END_SCRIPT

 

Wuala

I was saving the pictures onto a Wuala cloud drive when I originally developed the autocam.sh script.

Might need this package so that Wuala can map as an NFS drive…

sudo apt-get install portmap nfs-common

Location of Wuala drive as it created by default…

/home/erick/WualaDrive



 

 Resources

Ubuntu Man Page for fswebcam

fswebcam web page

Webcam capture using fswebcam

Shows how-to install fswebcam via package installer, I have not tried this…

http://www.8devices.com/wiki_carambola/doku.php/carambola_fswebcam

To make a movie via the Linux Command line, go to the section on How To Make a movie, under the section that talks about doing it via SSH on the Raspberry Pi, on the site…

How To Capture Time-Lapse Photography With Your Raspberry Pi and DSLR or USB Webcam

From Some fun with a webcam , I like how the code to run the camera has it set the font as white against a transparent footer. The code in bold makes it happen…

Excerpt…

width=640
height=480

…………….

exec fswebcam –quiet –skip 14 \
–font $font \–timestamp ‘%d %b %y %H:%M:%S (%Z)’ \
–no-title -r $height\x$width \
–banner-colour ‘#FF000000’ \
–line-colour ‘#FF000000’ \
–exec $capture \
–loop $interval $output

—————

 

Very cool, a portable time lapse camera using a Raspberry Pi and a battery, stuffed in a tin can. This is the way to go!

Simple timelapse camera using Raspberry Pi and a coffee tin