Take photo with laptop webcam when lid is opened
Recent news reports of a school in the USA causing controversy with its pupil issued laptops being used to spy on them. Made me think that taking a snap image when laptop lid is opened could be a cool pseudo security feature to catch if a snooper uses a laptop without permission. Would at least be a use for an otherwise unused laptop camera. How to do it though?
Brief search of the web turned up a howto for making the computer play a different sound for opening and closing the lid, something easily adapted to my needs.
To take the photo I used a command-line application called fswebcam which can be installed through the Synaptic Package Manager. fswebcam is a neat and simple webcam application with several useful configuration options. Once installed you can take snapshots with the example command:
fswebcam --no-banner --delay 1 -save ~/Desktop/%Y%m%d%H%M%S.jpeg
The above example is configured to turn off the overlay banner in the photo, delays the camera by 1sec before taking a photo (to make sure light is adjusted etc) and saves the jpeg image file to the desktop with a time/date stamp. Using a time stamp like this allows multiply files to be saved instead of over writing the same file each time which would be useless.
Now that photos can be successively taken the next thing to do is set up the system (I'm using Ubuntu 9.10 64bit) to take a shot whenever the lid is opened. This is where the "Advanced Configuration and Power Interface" (ACPI) is employed.
ACPI has a file called lid.sh which is located in Ubuntu under /etc/acpi, this script is run whenever the lid of the laptop is opened or closed. Opening this script file (sudo gedit /etc/acpi/lid.sh) in a text editor will show what commands are run when lid is opened or closed.
I added the following commands near the top of the file.
test -f /usr/share/acpi-support/state-funcs || exit 0
# take camera shot when lid opens
grep -q closed /proc/acpi/button/lid/LID/state
if [ $? != 0 ]
then
fswebcam --delay 1 --no-banner -save /home/yourusername/Pictures/LID_OPEN_CAPTURES/%Y%m%d%H%M%S.jpeg
fi
The command that grabs information about the state of the lid is the line:
grep –q closed /proc/acpi/button/lid/LID/state
This line is followed by an if statement. This statement is used to discover if the lid has been opened or closed. So if [ $? != 0 ] (if not zero) means the lid has been opened so then do the following command...
fswebcam --delay 1 --no-banner -save /home/yourusername/Pictures/LID_OPEN_CAPTURES/%Y%m%d%H%M%S.jpeg
Which is the one that tells fswebcam to take the photo. Note because this script is run by the system (root) we have to use the full path of where to store the photos instead of the ~/ home short cut. (least that is the way I got it to work with my limited linux understanding).
The rest of the lid.sh script is left as is. Once saved it should be ready to work. Close the lid, open lid and camera LED will briefly light and the photo should be stored in the specified folder. That's it!
fswebcam can be configured to run further commands so it could in theory be used to trigger for example an ftp script which uploads the photo to a webserver, send as an email or sms alert to a phone etc.
Current Defender Config.
How the landy currently looks. Lightbar gone. Spare gone back to rear door. Barebox fitted in rear. Tree sliders blacked up. X-lites mounted on bumper either side of winch. XZL tyre remounted onto max offset 8 spokes to bring them out by 2 inch (still skinnies but not so lost under arch). Headlamp surrounds renewed.


candle power
When I removed the wing the other day I was puzzled by the large high wattage resistor in attached between the inner and out wing panels. Bit of research turned up that this is landrover partnumber XBL10003 with the description of "DIM-DIP assembly"... That's was news to me.

Bit more digging and turns out the vehicle was fitted with a Dim-Dip headlamp feature which originated from a piece of defunct short lived UK legislation which required (when engine running) the headlamps to come on at same time as sidelamps at a greatly reduced (dimmed) level of the normal dipped headlamps. Landrovers solution to this was to fit a high wattage 1ohm resistor feed to headlamps via a dim-dip relay feed. The EU forced the UK to retract that law.
Anyway thing is my headlamps have always been working normally else I would noticed this feature before now! Even though it no longer leagally required and probably is a silly feature I still wanted to knwo why it didn't work and also curious as to how it looked. So bit of fault finding turn up that the resistor was at fault - was reading in the high 10's of Meg ohm instead of the expected 1 ohm. Instead of paying silly money in replacing the whole assembly I sourced a suitable 50w 1 ohm resistor (£3.99 off ebay!) and swapped the faulty one out.
Dim-Dip works now! But boy that resistor and heatsink(read whole inner wing) gets hot, so not sure it will live long (would fail safe anyway).
Here how it looks from FULL BEAM - DIPPED BEAM - DIMMED BEAM



Rats with WIngs
Forgot to blog that I replaced the driver wing on the Defender last week. Obtained wing not long after hitting an iceberg back in 2007! The been sitting around in garden for awhile asking for some paint and fitting. Although it's a used panel and a little battered it better than the one that I had on there. At least now I can refit some finisher panels around the head lamps.
Other Defender news:
Noticed a fluid patch on driver floor mat and a tasting declares it is vintage DOT4 fluid. So seals are weeping fluid in the clutch master cylinder. Do not recall ever doing that job on this truck before. Something to look forward to *joy*
lappy died
My laptop died last weekend, screw had come loose in the cooling assembly and did dirty deeds while it rolled around the motherboard. Gutted as I had just got the system the way I wanted it and was enjoying the new lease of life it had under linux. Not a cheap machine either and now no budget to replace with one of the same quality.
So here we are again with new lappy Mark III. This time it's a DELL....OMGZ! INSPIRON 1545 2.2ghz Dual Pentium, 3 GB RAM, 350GB drive. It came with Windows7 (yuck) which I ditched within the hour for Ubuntu 9.10. I swapped out the dell WIFI card (which doesn't work under linux out of box) for the better one from the Lenevo.
Laptop seems quite nice so far but with two gripes... the max resolution is 1366x768 which is a kick in nutz when used to at 1600x1200 on other laptop. My other gripe is fixable, there is no built in bluetooth. I can sort that quite easily.
So long live new lappy mk3, or is it the 4th? in reality it's about the 8th but they not all new. My laptops have a hard live being on 24/7 pretty much year in year out - keyboards and power connectors and harddrives wear out and get replaced more than once during the life span.











23/02/10 06:52:47 pm, 
