*

Welcome, Guest. Please login or register.

Get your own OLPC - Buy an XO laptop on eBay!
Pages: [1]
Print
Author Topic: Remotely Take and View Pictures  (Read 7636 times)

Remotely Take and View Pictures

anna
Master Contributor
***
Posts: 326


January 12, 2010, 05:18:39 PM

...using only boa!  Boa is a very lightweight webserver which works great on the XO.  The instructions below are for a Sugar install, but something similar will work with other distros.  I've successfully tested it with DebXO as well, though the setup was slightly different.

Streaming the webcam is possible, but I've found it highly unstable and the setup a lot more complicated.  Besides, it's a bit of overkill if you only want an image on demand.  Using boa and a little cgi script, you can remotely take and view a picture using the XO's webcam from any web browser.

Become root

Code:
su -

Install boa

Code:
yum -y install boa

Edit /etc/boa/boa.conf

Code:
nano -w /etc/boa/boa.conf

It's a good idea to change the port to 8080, but this is optional.

Code:
Port 8080

Change the user and group to olpc

Code:
User olpc
Group olpc

Disable logging by commenting out:

Code:
#ErrorLog /var/log/boa/error_log
#AccessLog /var/log/boa/access_log

Make note of your DocumentRoot.  This may be different with other distros.

Code:
DocumentRoot /var/www/boa/html

Increase the Timeout from 10 to whatever you like.  20 should be OK unless you run into lag issues.

Code:
KeepAliveTimeout 20

Make sure this line is uncommented.  That should be the default, but again, it might depend on the distro.

Code:
AddType application/x-httpd-cgi cgi

Save your changes to boa.conf with ctrl+x then y and enter to write out.

Give the olpc user ownership of the DocumentRoot

Code:
chown -R olpc:olpc /var/www/boa/html/

Restart the boa server

Code:
service boa restart

Tell boa to start on boot

Code:
chkconfig --level 345 boa on

Type exit to drop back to the olpc user.  This is important, as you may run into permissions issues if you don't.

Now create webcam.cgi (or whatever you want to call it, as long as it has the file extension of cgi) in your DocumentRoot.

Code:
#!/bin/sh
# CGI script to take and display an on-demand image
echo "Content-type: text/html"
echo
echo "<html><head><title>A Picture from the XO Webcam</title><body>"
echo "<h1>Here's a Real Time image from the XO Webcam</h1>"
echo "<b>"
gst-launch-0.10 v4l2src ! ffmpegcolorspace ! pngenc ! filesink location=webcam.png > /dev/null
echo "<br />"
echo "<IMG SRC="webcam.png">"
echo "<br />"
echo "<h2>Refresh this page to take another picture</h2>"
echo "</b></body></html>"

This is some kludgy cgi and html, but it seems to work OK.  Suggestions are welcome!  Of course, you can always customize the verbiage.

Make webcam.cgi executable.

Code:
chmod +x webcam.cgi

Get your XO's IP with ifconfig.  Now from a browser on another computer on your LAN, you can take and view a picture by simply going to this link (here's my real life example):

http://192.168.1.6:8080/webcam.cgi

You can allocate that port in your router's firewall to the XO, go to your external IP at that port, and remotely take and view a picture from anywhere in the world!  Or point your XO at the porch and check if that package has been delivered yet without going downstairs.

And don't keep your XO in the bathroom.  There is no access control with the boa webserver, so keep that in mind.

Edit:  Removed an extraneous line in webcam.cgi and included a short explanation of what boa is.
« Last Edit: January 12, 2010, 06:05:56 PM by anna » Logged

#1 Re: Remotely Take and View Pictures

eden
Global Moderator
Master Contributor
****
Posts: 420


G1G1 2007, 2008


January 12, 2010, 07:16:00 PM

This looks like fun!  Thank you!
Logged

#2 Re: Remotely Take and View Pictures

mavrothal
Administrator
OLPC News Forum Expert
*****
Posts: 1289


January 12, 2010, 11:03:55 PM

I'll have ti fix my camera again just for that Grin

Note: Ubuntu users must also install "gstreamer10-tools"
Logged

XO-1: Is never going to run Flash, but is certainly flashy!
(If you want Flash, get an XO-1.5 running OLPC 11.2.0 or XOpup Grin )

#3 Re: Remotely Take and View Pictures

anna
Master Contributor
***
Posts: 326


January 13, 2010, 10:43:56 AM

Oh, you can also add this to the html to make the page auto-refresh every X seconds:

Code:
<meta http-equiv="refresh" content="X">

Put that in between the <head> and <title> tags on the 5th line of the cgi script.  Here's an example refreshing every 30 seconds.

Code:
echo "<html><head><meta http-equiv="refresh" content="30"><title>A Picture from the XO Webcam</title><body>"

Now it's almost like having a security camera!
Logged

#4 Re: Remotely Take and View Pictures

Sam J.
Commenter

Posts: 21


May 13, 2010, 03:17:08 PM

Thanks for this idea. I'm happy to know about Boa, and I look forward to using the camera, which I haven't yet done at all.
...
Note: Ubuntu users must also install "gstreamer10-tools"
Would that be gstreamer0.10-tools? I'm trying this with Teapot's Ubuntu. I installed boa and gstreamer0.10-tools. I'm able to access the page but there's no image. Boa error-log reads:
Code:
ERROR: pipeline could not be constructed: no element "v4l2src"
Maybe I need some other part of gstreamer, or does it have to be activated somehow?
Also, I see that chkconfig isn't part of Ubuntu; what would be an alternative?
Thanks.
Logged

#5 Re: Remotely Take and View Pictures

anna
Master Contributor
***
Posts: 326


May 13, 2010, 07:34:26 PM

@Sam J.:

I've only tested and used this on Debian Squeeze, not Teapot's Ubuntu, but in addition to gstreamer0.10-tools you need gstreamer0.10-plugins-base for v4l2src.  Hopefully that'll work for you.

As far as chkconfig goes, all that does is start the boa service at boot on Fedora systems.  On Debian/Ubuntu, look in /etc/init.d.  The boa service should already be in there and thus start automatically at boot.  Check your processes to be sure.
« Last Edit: May 13, 2010, 07:47:45 PM by anna » Logged

#6 Re: Remotely Take and View Pictures

Sam J.
Commenter

Posts: 21


May 14, 2010, 01:54:53 PM

Yes, I found that gstreamer0.10-plugins-good (not base) was needed.
Thanks again.
Logged

#7 Re: Remotely Take and View Pictures

anna
Master Contributor
***
Posts: 326


May 14, 2010, 05:57:42 PM

Yes, I found that gstreamer0.10-plugins-good (not base) was needed.

Argh!  Sorry about my gstreamer plugin confusion.

I do hope it's working for you.  I set this up on an XO and made it viewable outside my LAN.  My friends got a kick out of taking pictures from across the continent.  I had to put a clock in front of the XO's camera, as one of the guys didn't believe me.

I also put a dime store thermometer in front of the camera for "remote temperature monitoring."
Logged

#8 Re: Remotely Take and View Pictures

Sam J.
Commenter

Posts: 21


May 15, 2010, 09:24:19 AM

Argh!  Sorry about my gstreamer plugin confusion.
Please don't apologize! I only mentioned that v4l2src is in the 'good' (as opposed to 'base') plugins in case someone else has trouble with this. It works very well and I too am having great fun with it. Knowing about command-line control of the camera opens up lots of possibilities and, as I mentioned before, I'm delighted to have learned about Boa. So your tips are  greatly appreciated. I can't do the your pandora thing because it's not available outside the US; maybe I'll try your twitter idea ....

Logged
Pages: [1]
Print
Jump to:  

Members
Total Members: 2406
Latest: sembik
Stats
Total Posts: 31943
Total Topics: 3843
Online Today: 30
Online Ever: 238
(April 18, 2011, 09:48:50 PM)
Users Online
Users: 0
Guests: 27
Total: 27