Automated browser of fish webcam sexyness


The aim of this project is to automate the display of my aquarium webcam for when I jet off on a future jaunt to the 'States. A little elbow grease before aeroplane lift-off will ensure my mates work colleagues can continue viewing the antics of my fin-fueled friends whether they like it or not... which they don't. But screw 'em, I'm doing it anyway.

So this is for Bolton Dan (bald server man), Sukhjeet the contractor, Curly Burd and Nigel the... uh... massive wanker.

I've already documented how I made my aquacam, the next step was how to display it at work while I'm jerkin' off on the other side of the planet. What I need is a computer that will launch a web browser pointing at my aquarium webcam during office hours Mondays to Fridays and displaying the output on a monitor that faces the office.

As it happens, we have a suitable monitor which is doing nothing too critical (it only shows the fire alarm status but I've never seen that change), so I can get it to do something far more interesting here.

 The lovely but bizarrely permed Curly Burd modelling my aquacam on Status Monitor 4

I'm hooking a laptop up to this monitor and I want it to work in a specific way, namely...

1. Launch a web browser at 08:15 weekday's only.

2. The web browser should show my aquarium webcam.

3. Close the web browser at 16:45.


The whole show should be one of those fire-and-forget deals so it needs to be completely automated from power-up. Once the laptop is on, it's left running until my return.

I don't want the computer to be accessing my webcam outside of office hours as it will be needlessly sucking pictures from my home webserver when nobody is there to view them which, on a two second refresh, will have a hit on the efficiency of the rest of the site.

Fortunately, this project ain't too difficult. I'm starting with a virgin build of Linux Mint 12 on a Toshiba U300 laptop. I've set it to login automatically and I've disabled the screensaver and the screen power save feature. The display output has been set so it drives the external monitor with the internal laptop screen disabled.

I'm going to use Firefox as the web browser of choice, mainly because it's slightly less shit than Chromium-Browser.... for some things. I find Chrome doesn't behave properly for this (more about that later), but I can get away with Firefox if tweaked.

The obvious candidate for the job is CRON. So let's edit the CRON Table by issuing the command:
crontab -e

Then set the cron job in the order of:

min  hour date month day-of-week    command
0-59 0-23 1-31 1-12  0-6 (Sunday-0) [Command to execute]
Asterisks are used where no specific value is given.

For this task my crontab is set as:

15 08 * * 1-5 export DISPLAY=:0 && /usr/bin/firefox
00 12 * * 1-5 killall -15 firefox
01 12 * * 1-5 export DISPLAY=:0 && /usr/bin/firefox
45 16 * * 1-5 killall -15 firefox

With this crontab, at 08:15 on a Monday to Friday regardless of date or month, the Firefox web browser will be launched on display 0 (the default monitor).

At 12:00, firefox is sent a termination request and closes.

At 12:01, Firefox is launched again and finally at 16:45 it is again told to quit.

I set a mid-day relaunch just in case there is any issue with my connection at the start of the day. This way, if Firefox can't find my webserver first thing in the morning for any reason, it should get it by the middle of the day once I've had a chance to grab my bag o' spanners and whack the bastard.

Now that I have Firefox starting and stopping when I want, I configured it with minimal menu bars and I set my aquarium webcam page as the homepage. I wanted FF to launch in full screen mode but I wasn't able to find a way to do that. No matter, there's plenty of screen space on the monitor I'm using and the minimal menu bars don't get in the way.

One issue I did have with Firefox was that when it was next started up, instead of my homepage I got a warning that it hadn't closed properly and it would ask me if I wanted to restart my last session. Clearly my pkill -15 command was more of a knee to the nuts than a clean close but despite some playing I couldn't find a way to close the browser without it subsequently moaning. In the end, to get around it, I went into about:config in Firefox and changed the browser.sessionstore.resume_from_crash function to be False instead of True. Firefox now launches cleanly to my homepage every time.

As for Chrome, that sucker wouldn't quit with the pkill command at all and just spewed up an "Aw, Snap" error every time, hence it's unsuitability for this project.




Post a Comment

 
Top