{most recent webcam shot}
To run an iSight webcam first make a directory off your home directory. Call it webcam or something like that.
I downloaded isightcapture from Intergalactic. This free, but not open source, program will grab a picture from your iSight. Put this program in your new webcam directory.
To ftp the pictures up to your website you need to create a perl program ‘webcam.pl’
This perl program takes and uploads a picture every 300 seconds ( 5 minutes ) change the number of seconds to suit you.
#loop forever or until program terminated
while (){
$takepicture = “./isightcapture snapshot.jpg”;
print $takepicture.”\n”;
if ( system($takepicture)) { print “failed to take picture\n”; }
$uploadpicture = “ftp < upload”;
print $uploadpicture.”\n”;
if ( system($uploadpicture)) { print “failed to upload picture\n”; }
sleep(300);
}
Now make that file executable at a command prompt type
>chmod 755 webcam.pl
Next create a .netrc file in your home directory substituting yourwebsite.com, yourloginame and yourpassword. Be sure permissions are set to 600 ( chmod 600 .netrc ).
machine yourwebsite.com
login yourloginname
password yourpassword
{this is highly insecure, your password is in plain text so use this at your own risk!}
Finally create the upload file. snapshot.jpg is the name of the picture that isightcapture takes. Change yourwebsite.com and yourwebcamdirectory to be the name of your website and the directory on your website you are uploading your snapshots into.
open yourwebsite.com
prompt
binary
cd yourwebcamdirectory
put snapshot.jpg
bye
Once all this is done and everything is in the same directory except .netrc open a new terminal window, cd to your webcam directory. Type ./webcam.pl and you’re taking and uploading pictures. You will see the output from isightcapture and the ftp program. So any problems should be clear to you and easy to fix.
Now in your webpage just put in a link to the picture to have the current picture appear in a webpage.
*All these sample files can be downloaded osxwebcam.tar.gz
5 responses so far ↓
1 Jacob // Mar 9, 2007 at 10:01 pm
I would like to add a command in the loop to remove the picture from the local drive. How would I do that?
2 herself // Mar 10, 2007 at 2:31 am
You use the ‘unlink’ command
unlink “unwantedfile.jpg”;
3 Jacob // Apr 29, 2007 at 7:24 pm
I am having trouble still when it tried to connect to the ftp server it is still using my local username and prompting for a password and not using the username and password from the .netrc file. I have made sure it has the right permissions and is in the /~ directory. Is there anything else that I need to check?
4 herself // Apr 30, 2007 at 3:33 am
Every command in the webcam.pl file you should be able to run from a command line by hand.
Try running through each command by hand one at a time and see where the error is specifically happening.
Network stuff, especially ftp can be a nightmare, and that is how I find my problems.
Just to double check, no harm in that. .netrc should be in your home directory. And set to 600, it will not work if the permissions are incorrect. Setting them looser is as bad as having them too tight.
I note in my .netrc I used timestocome.com not http://www.timestocome.com So I probably had trouble connecting with the www in front of the domain. Check that also.
Let me know if that helps.
5 herself // Apr 30, 2007 at 3:40 am
One more thing that may or may not matter, I’m running the webcam program in a sub-directory off my home directory.
It may or may not ( I haven’t tried ) pick up the .netrc info if you run it from somewhere not in or under your home directory.
You must log in to post a comment.