Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create a semi-failsafe automated webcam system Reviews
I'm putting this in the "Reviews" category, because I can't really decide where it might best fit. We have a G3/500 iBook that hasn't been getting much use lately, so I thought I'd try it as a webcam for while, just to put it to some sort of use (I hate selling off my older Macs!).

Using a combination of built-in programs, OS X features, and EvoCam, our little iBook is now a fully-automated, somewhat failsafe, webcam serving machine. There's really nothing new in this hint/review, just a combination of things that have been covered here before all put to use in one solution. So read the rest of the hint if you'd like to see what I did...

First, none of this would be possible without EvoCam, a previous PotW winner and a great webcam application. EvoCam takes care of most of the hard part of the setup, as its feature set includes these very useful features:
  1. Built-in webserver for live camera functionality
  2. Snap a still image every certain number of seconds and write it to disk
  3. Create a time-lapse QuickTime movies from the stills automatically
  4. Operate according to a schedule
  5. Add text and graphic overlays on top of the webcam image
I used all of these features when we set up the camera -- for now, I'm using the iSight camera, but EvoCam will work with nearly any camera that QuickTime supports. The EvoCam server starts at 5:45am each day, and shuts itself down at 6:00pm (it's an outside cam, so not much to see when it's dark!). During the day, it snaps an image every 30 seconds and writes it to the iBook's drive, and builds the QuickTime time-lapse movie while doing so.

The second part of the solution was trying to failsafe the camera, so that I wouldn't have issues with it going offline during the day. The first stop was the Energy Saver preferences panel. First, I made sure the iBook didn't fall asleep on the job by setting the Sleep section to "Never," (but the screen dims after one minute). Next, on the Options tab, I enabled the "Restart automatically after a power failure" to take care of temporary power outages. I also created a new "Webcam" user for this project, and put Evocam in that user's startup items folder, and enabled automatic login. So after a power outage, the machine should reboot, login the Webcam user, and launch EvoCam. I haven't tested this yet, but it should work :).

I then switched to the scheduling tab of Energy Saver, and told the iBook to wake up every day at 5:40am (five minutes before the camera starts snapping pictures), and to put itself in sleep mode at 8:00pm each evening (so I have time to deal with the day's image captures, transferring them to our main Mac -- 1,500+ images per day fills that little hard drive quite quickly!).

These steps took care of the "easy" part of the project: the machine would now wake/sleep itself and recover from a power outage. Next, I wanted to make sure EvoCam was always running. It's a great little app, but I have had it unexpectedly quit on occasion, but I couldn't ever figure out the cause. Thanks to hayne in this thread on the forum site, and some digging through older macosxhints tips, I cobbled together a solution. First, I had to disable the Crash Reporter, so that those lovely "Application X has crashed..." dialog boxes no longer appeared onscreen. This was handled with a quick trip to the Terminal and this command:
defaults write com.apple.CrashReporter DialogType none
There are other choices for the CrashReporter setting; they're covered in this hint. Next, it was time to figure out how to relaunch EvoCam if it crashed, and to hopefully create a rudimentary log of the events, just so I could see that my efforts paid off. Between hayne's example and the other scripts on the site, here's what I came up with. I saved this in the Webcam user's ~/bin folder, and made sure it was executable (chmod 755 stayup):
#!/bin/sh
#Script name: stayup
ps ax | grep EvoCam | grep -v grep
if [ $? = 0 ] ; then
  #it's up, do nothing
  echo "it's running" > /dev/null
else
  #not up, launch it
  date >> /Users/Webcam/Desktop/evocam_crash.txt
  echo "EvoCam restart successful" >> /Users/Webcam/Desktop/evocam_crash.txt
  echo "-------" >> /Users/Webcam/Desktop/evocam_crash.txt
  open -a EvoCam
fi
I'm sure there are probably much more efficient ways of accomplishing this task, but this one works for me. For the real beginners out there, I'll try my best to explain what this script does (though I'm mostly a shell scripting beginner myself, so apologies in advance for mistakes).
  • #!/bin/sh -- This is a standard shell script, not perl or some other scripting language.
  • ps ax | grep EvoCam | grep -v grep -- This lists all running processes (ps ax), then sends that output (via the pipe, |) to grep to search for EvoCam in the output. Finally, that output is again sent to grep, this time to exclude (via the -v) the grep EvocCam command itself which also shows up with the EvoCam output.
  • if [ $? = 0 ] ; then section -- I don't completely understand this line, other than $? represents the result of the grep, and if the result is zero, then EvoCam was found via grep. If it was found, that means it's running, so we don't need to do anything else. However, I found I had to include a command of some sort, otherwise the script failed, so I echoed a meaningless message, but then redirected it to /dev/null, which means it doesn't go anywhere.
  • else #not up, launch it section -- This is where the heart of the work happens. If the grep failed, that means EvoCam isn't running, so we need to create a log and restart EvoCam:
    • date >> /Users/Webcam/Desktop/evocam_crash.txt -- This appends the dates and time to my homemade crash log; using the >> redirection symbol means "add to existing file," instead of >, which means "replacing existing file."
    • echo "EvoCam restart successful" >> /Users/Webcam/Desktop/evocam_crash.txt -- Add a line stating what just happened.
    • echo "-------" >> /Users/Webcam/Desktop/evocam_crash.txt -- Add a divider line, so that it will be easy to distinguish between events in the log file.
    • open -a EvoCam -- Relaunch EvoCam.
  • fi -- End the "if" loop.
By itself, this script isn't much good. It runs, but it needs to run automatically every so often, otherwise I'd have to be sitting here running the command. That's where cron enters the picture. cron can execute commands at predefined intervals, which is exactly what I needed. I won't cover crontab again in detail, as there have been quite a few hints on it here -- this one provides a general overview and explanation of how it works. The particular crontab lines for my script are:
#min     hour     mday     month     wday       command
*/1      *        *        *         *          /Users/Webcam/bin/stayup > /dev/null
This command executes my stayup script once per minute, all day long. If EvoCam ever crashes, it will be down at most for 60 seconds, and it will then restart, and log the event in my log file. While this may put a bit of load on the CPU, this machine isn't doing anything else at all at the moment (and when I have been using it while the cronjob is active, I haven't noticed any slowdowns).

As I stated up front, there's nothing new or dramatically exciting in this hint, but hopefully it shows you how you can use the GUI and Unix sides of OS X together in a meaningful way. I'm sure the script can be improved upon (I really don't do a lot of shell scripting), but hopefully this is enough to get you started if you're interested in a similar project.
    •    
  • Currently 2.85 / 5
  You rated: 2 / 5 (20 votes cast)
 
[18,902 views]  

Hint Options


Create a semi-failsafe automated webcam system | 14 comments | Create New Account
Click here to return to the 'Create a semi-failsafe automated webcam system' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a semi-failsafe automated webcam system
Authored by: balston on Jun 07, '04 02:10:20PM

Which camera did you use ... iSight?

Did you need to use any 3rd party software to get the iSight to work with a G3 processor < 600MHz?



[ Reply to This | # ]
Create a semi-failsafe automated webcam system
Authored by: robg on Jun 07, '04 02:16:47PM

Yes, using the iSight. It works fine with EvoCam, but it cannot be used by iChat as is. I think there's a third-party hack to enable it, but I've never gone looking for it...

-rob.



[ Reply to This | # ]
use iSight on a G3 500
Authored by: scorpion on Jun 07, '04 06:31:14PM

Rob, thanks for this hint. My iBook G3 500 will be retiring soon and this is the perfect use for it. To use iSight on such a computer, you have to download Application Enhancer and check out this link:

http://www.xlr8yourmac.com/isight/iSight_reports.html

I think I tried it and it worked, but it was slow and I have heard some bad things about haxies, so I removed it.
But I really appreciate this hint -- it's exactly what I'm planning to do with my iBook!



[ Reply to This | # ]
use iSight on a G3 500
Authored by: Bruce Miller on Jun 07, '04 07:09:16PM

iChatUSB from ecamm.com enables any USB webcam and any G3 speed to work with iChat, I have it and it works fine.



[ Reply to This | # ]
yes, but...
Authored by: scorpion on Jun 07, '04 11:42:44PM

Here's a quote from the ecamm.com web page:

"IMPORTANT: iChatUSBCam is an Application Enhancer module and requires that Application Enhancer be installed. "

... and a lot of people aren't fond of that. I seem to recall when I tried this my system was sluggish. But if it works fine for you, more power to you. I think I ended up using Yahoo Messenger.

Best of luck!



[ Reply to This | # ]
Create a semi-failsafe automated webcam system
Authored by: rlaan on Jun 08, '04 06:23:14AM

Hi,

Most likely you don't need a haxie for this hint because the iSight is controlled by the Webcam app. iChat's restriction is coming from the fact that the image is mirrored on the fly when you look in your own camera, so it looks like you are watching a mirror, because this is done on the fly it takes some processing power, hence the 600 Mhz minimum. If I recall well the haxie disables that, freeing the CPU for iChats chat functions, thus enabeling slower cpu's. The correspondant sees you normally at all times, not mirrored.

Ruben

---
The box said, Windows 95 or better, so I bought OS X.



[ Reply to This | # ]
Create a semi-failsafe automated webcam system
Authored by: scorpion on Jun 08, '04 09:20:00AM

You're right -- you don't need a haxie for the original hint. But to run iChatUSBWebcam, referenced above (which allows the iSight to be used "live" on sub-600 mhz G3s) you do. That's what I was responding to, so I'm sorry for the confusion.



[ Reply to This | # ]
Create a semi-failsafe automated webcam system
Authored by: prk on Jun 07, '04 05:18:08PM

I use SecuritySpy for my Web Cam. It has auto-restart if the app crashes built in. It's actually a really nice package. It works with my iSight.



[ Reply to This | # ]
SecuritySpy CPU usage
Authored by: outofcontrol on Jun 08, '04 09:14:39AM

Having been an Evocam user for quite some time and since I had never heard of Securityspy, I was curious what it was like. So I downloaded a copy and installed it.

The configuration is more intuitive than Evocam. Setting it up was a breeze. Like Evocam, it was running within 3 or 4 seconds of installing it.

On the downside, it costs $50. It hogged 25-35% of my CPU in normal background operation, compared to 3-6% with Evocam in the foreground or background. There appeared to be no way to customize the HTML page for *pretty* viewing by family members.

So, for me and my old 866 single Hoover, Evocam rocks. Though having auto restart would be nice on Evocam.



[ Reply to This | # ]
Short grep tip
Authored by: vansie on Jun 08, '04 02:57:35AM
Instead of doubling up on greps with the
grep EvoCam | grep -v grep 
construct, use this:
grep "[E]voCam"
By enclosing the first letter of the process you want in square brackets you negate the second grep and it will only return a single match for EvoCam (or whatever else app name you stick in there.) Just nitpicking but everytime you save a cpu cycle, a sysop gets their wings... ;-)

[ Reply to This | # ]
Can't part with old Mac.
Authored by: macmath on Jun 08, '04 08:05:08AM

I know what you mean about not wanting to part with your old Macs. A Macintosh, through its OS, has a personality and becomes a member of the family, much in the same way a pet does. [Even without the Easter Eggs and the Happy Mac, they still feel like they have a personality: they are dependable, they have their own unique look/style, they behave consistently between applications, and you can often predict how they'll behave (even if you've never done a particular task before, it feels like something a Macintosh would do, so you try it and it works).] It has to go to a good home, if it goes anywhere. I still have my old Power Mac 6100/60 (with the crayons that look worn if you advance the clock enough, etc).



[ Reply to This | # ]
Oops...wrong parent! more....
Authored by: macmath on Jun 08, '04 09:27:26AM

Oops. I replied to the wrong parent. I wish these boards would allow you to delete within 120 seconds of posting.

Also relating to personality, even though you might know your Macintosh really well, occasionally it will do something which will (pleasantly) surprise you (you'll find some feature which you were unaware of).



[ Reply to This | # ]
Clever trick
Authored by: mzs on Jun 08, '04 02:01:25PM
I was about to write a post about how that cannot work, then I figured it out ;) Smart one aren't you!? I think I will use grep '[/]foo' from now on personally since I can make use of grep '[/]'"$arg" easily in scripts.

Thanks

[ Reply to This | # ]

Create a semi-failsafe automated webcam system
Authored by: tmass1 on Jun 10, '04 08:47:53AM
Can anyone recommend a wireless webcam?

[ Reply to This | # ]