Thursday 7 August 2014

Bootstrap Combobox templating issue

Just had to put a Combobox (http://en.wikipedia.org/wiki/Combo_box) on a Bootstrap site.  I've been playing with the bootstrap combobox plug in by Daniel Farrell (http://danielfarrell.com/).

You can find a demo at the github page - https://github.com/danielfarrell/bootstrap-combobox


I was trying to change the template slightly, but no matter what I did it ignored it.

Just found that you need to swap some of the arguments round in the constructor method if you're supplying options on start.

Basically, as seems common sense in hindsight, you need to move the line
this.$container = this.setup();
to be after the template 'option' declaration (which has to be a function returning a string, by the way).


Monday 28 July 2014

PHP Parse error: syntax error, unexpected '['

Encountered a strange PHP issue this morning when working on a client's server:

PHP Parse error:  syntax error, unexpected '['

The line in question was:

$intNumberOfChars = (int) substr(explode('(',$objField->DbDataType)[1],0,-1);



It turns out that PHP 5.3 and below (installed on the client's server) don't like to array dereference the result of a function or method call directly.  In essence, it means before PHP 5.4 you must use a temporary variable:

$arrTemporaryVariable = explode('(',$objField->DbDataType);
$intNumberOfChars = (int) substr($arrTemporaryVariable[1],0,-1);

I've never had this error before, so worth pointing out to people.  I'm amazed that the functionality has only been available since March 2012 (5.4's release date) as I use it all the time.


Thursday 17 July 2014

What is jQuery and Why Do Developers Love It?

This a post about something called jQuery and you probably have never heard of it if you don't build websites.

As some context, I've been programming for the web since 2000.  It's been a pretty rough ride at times, especially in the heady days when everything was achieved through a mix of standard PHP files, HTML and Macromedia Flash.  This saw you needing a plugin for your browser that took an age to download over dial-up and not much shorter if you were lucky enough to have early 256k 'broadband'.
But there's always been JavaScript, too.  A plucky little scripting programming language that's almost as old as the web, it was designed to allow user interactivity on web pages and in direct competition with Microsoft's Visual Basic Script.  In essence, JavaScript was a product of the Browser Wars of the mid-1990s; but without claiming a winner, I don't know anyone that uses VB Scripts anymore.  JavaScript allowed buttons to change when you clicked them, disable text boxes on forms and move items on the page depending on user input.  If you've ever encountered a little bit of text pop up telling you that your password isn't long enough or your email address isn't correct - you've probably been using JavaScript.
The problem that JavaScript faced, like many other web technologies both present and past, was one of cross-browser adoption and support.  Your browser (such as Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari) needs to support any language used on a given webpage.  There's a three main languages on many webpages today: HTML (HyperText Markup Language) describes the content of a page, CSS (Cascading StyleSheets) describe the look and design of a page and JavaScript controls the majority of the user interaction elements on a page.  All of these have had to fight for their place as the language for the job and have very good adoption nowadays as they've been standardised to describe how the browser should understand and implement their rules and instructions.  This has meant that you can reasonably expect any site to work in any browser.

JavaScript is a neat little language that is perfectly suited for the web.  Web development can be fast-paced, should be data-size efficient and genuinely do something useful.  This roughly can be translated as being experimental, lightweight and making things easier for users.  JavaScript can do all these things, but from a programmer's perspective it means a lot of lines of code and a lot of repetition.  A solution to this is home brewed libraries - that's a book of snippets of code that can be used as a recipe whenever you need to do things over and over.  So developers over time can build up a home brewed library with useful code snippets that make them faster at completing a task - they make a generalised library of snippets to do almost anything.  That was the situation on the web circa 2005.

One problem with generalised libraries in JavaScript is one of file size growing.  A browser needs to download the whole library when a page loads, so a large library can quickly grow to a megabyte or more.  If every developer has their own library, you need to download it if you haven't before.  This makes sites slow to load the first time, giving users a bad experience.  Browsers can cache a library so they remember they have that file and needn't download it every page load, but the problem remains for that first load.  So the solution is a ubiquitous library that every site uses such that you only need visit one site with that library and forever you have a copy of it for use on subsequent sites.  Voila, you've solved the problem.  For many years now, the Web has been using jQuery as this library.
The logo of jQuery has the strap line "write less, do more" and that's pretty much what's going on.  Before jQuery was released in 2005 programmers had to write the same lines over and over, precious development time given over to repetitious and tedious tasks which sap concentration and leads to mistakes.  jQuery takes these tedious tasks and makes shorthand available to cover a multitude of everyday things to free up development time so web developers can develop and build exciting and useful things.  Since many, many sites use it, it's never a problem to include it.  It's also grown up in a mobile-aware web, so there's a version with extensions written to better work with small touch screens.

What this means is that developers can throw something together to experiment, see how an idea might work with much less time cost to do so.  Developers can share other snippets based on this library to improve user experience or further shorten development time.  Sites can now do some really interactive things and allow users to better enjoy their visit.

Personally, time and again, jQuery surprises me with yet another feature that allows me to do something in a couple of minutes I thought would take a lot of code and a lot of time to write.

That's why I ♥ jQuery.

Sunday 15 June 2014

Weird graphics glitch OSX 10.9.3 on MacMini

Just had a mild panic when I switched on my Mac and displayed the desktop with very strange artefacts not dissimilar to a lower colour depth than necessary after updating OSX to 10.9.3

I wish I'd got a screen shot to aid recognition, but it may have not been relevant any way.  The areas that I now see that were problematic were predominantly white, and possibly even transparent or overlays.  It appeared on bitmaps, window chrome and the OSX Menu Bar and menu items when highlighted.  Essentially, it looked like a fog/glare or that anti-aliasing was incorrectly applied.  There was a few greens/purples punching through, too.  I've seen similar faults when a flatscreen monitor was dropped hard on a corner, but two at the same time?

I tried detaching both my monitors (one on HDMI, one on Thunderbolt) and cycling power on both monitors.  I tried using one at a time, but regardless of monitor/port combination, the glitch remained.

Had a Google about and noticed that 10.9.3, which I'd upgraded my Mavericks OS to the last time it was switched on, had a few users of older machines complaining of a similar but not the same glitch.  As I'm relatively new to the Mac OSX world, I sighed and thought I'd look into how to work around or try to ignore it until a fix is released.  I'd noticed that previous updates that involved graphics driver improvements had similar unintended problems for older hardware.

So only one thing left to try.  The IT Helpdesk standard "turn it off and on again".  It worked.  As silly as it sounds, it does work more often than I'd care to admit.  Hopefully this doesn't become a recurring fault.

I've tried looking for a screenshot of a similar glitch, but no one seems to have posted one - they seem to be much more broken than mine was.


Saturday 14 June 2014

Broadband Down

I've been dealing with Virgin Media to try and get a reliable internet connection at home.  I thought I'd put down a short resume of the trouble we have with their broadband.  I'll also post a review of their TV service too in the coming days as it is so full of niggles it's barely acceptable as a beta test version.

We've been customers for a number of years, with TV, phone and broadband, paying somewhere in the region of £80 per month.  We've got a number of gripes with the service, but predominantly, the main problem we have with the service is the broadband reliability.  It ranges from working perfectly and super fast to being none existent, you see.

We get a total drop out of signal to the router and we've had numerous and multiple engineers out to fix the issue. About eighteen months ago, it seemed fixed, one of the numerous engineers finally seemed to crack the problem.  It had something to do with the signal to noise ratio on our feed.  It seems Virgin broadband is very susceptible to fluctuations in the signal.  Whatever the engineer did, it didn't last.  About a month ago, it all started again.

So, as anyone unlucky enough to have to had reason to call Virgin Media will attest, I avoided calling 150 for as long as possible.  Finally, after it happened during Skype calls, trying to work on a server remotely and generally not being able to use any streaming service one night, we checked the service status page.  No reported faults. 

With a deep sigh, 150 is called and the endless loop of "are you on wireless?", followed by requests to restart the router begins. Being passed around, followed by promises that it's a temporary area fault that will resolve in X number of days. Not fobbed off by this, you explain that you know more about the fault than they do, and request to be passed to someone not reading from a script.  They promise a call will be made to you in the new day, which never happens.  Finally, your only option is being a pain in the arse on social media.

Fast forward a number of hoops jumped through, hours spent talking to them, and days waiting around for call backs that have a 66% chance of actually being made at current reckoning, we get a senior area engineer out. He arrives as advised (unusually from past experience - 12noon until 4pm included 6pm once) and does the usual triumvirate of new router (a different version this time), swapping the 'tap' we're fed from and a poke around with signal meters.  He can't see a fault and short of telling us the issue is in our heads, he leaves the set up and a resolution of "let's see if this fixes it".  No attenuator was fitted, swapped or fiddled with this time.  We're told to take a screen capture of the network status of the router when it goes down for aiding diagnosis.

I sit down today with internet radio on, after a few evenings of our Android phones reporting "unstable internet connection" but assumed they were just twitchy as they're relatively new.  My radio feed drops for a few seconds.  Annoying, but meh, could be wifi issues.  Drops again, this time long enough for me to see the device is trying to reconnect to the stream, but the wifi is at full signal.  Again, before I can grab my iPad, the device reconnects.  Next, it's down for a few seconds.  Okay, this is getting tedious.  I log my iPad into the router on the correct page to get a capture next time it happens.  I'm not left waiting for long.  It seems from my experience it actually happens every few minutes, for differing amounts of time.  Watching the status page, it's very common to happen and I only notice it drop when the radio cache is exhausted.  We've been watching YouTube and NetFlix all week since the engineer, but they're not live so can cache quite a lot of the stream.  Radio is a lot less cache happy by it's very nature, and so it's much more noticeable.  Luckily neither of us play online games and have been avoiding using our broadband for important Skypes and remote connections to servers.

So, I'm back at square one.  To be fair to Virgin Media this time, they are trying to fix the problem, but I did have to call, tweet and email a lot of people to get an engineer out.  I'll post updates as and when I get a resolution to the fault, but for now, I'll just have to live with musical statues FM.


Friday 6 June 2014

I hate TV

That is kind of a lie. I don't hate TV, I hate most of what is on it. It's not a semi-pompous "I'd rather read a book" or "I'd rather do something interactive", it's just I get bored of most television series or shows. I'm sure I'm not alone in this predicament. So I need your help if you're the same. I do like some TV, so I'll start here.

I loved seasons of the Scandinoir drama "The Bridge" and awaited each episode, I adored the BBC parody 2012 and the follow up W1A. I liked The Thick Of It and really enjoyed Sherlock and Luther was amazing. I watch Doctor Who and all the seasons of Star Trek. I liked ITV's Cracker back in the 1990s, recently watched like a fiend all the episodes of the sometimes difficult to follow French political drama "Spiral" and regularly end up watching other detective shows that are admittedly dated and poorly acted, like Taggart.

I've been recommended shows as "I know it'll be your thing" and ended up so, so bored of them after a few episodes. I'm not talking I dislike them per se, just I can't really be bothered making time to watch them, apathetic to them if you like. I've tried watching the stand out favourites people rave about Lost, 24 and Game of Thrones. All of them just annoy me by being so predictable or just so monotonous and, for a better way of putting it, long. I've watched hoping I'd get into it Battlestar Galactica and watched Firefly under some duress of my other half. I never caught on with Buffy, Angel or Xfiles back when I was younger, or really understand the appeal of many American made serials, even with British actors in them.

Like I say, I've had numerous series suggestions and I look into them and they just appear too daunting to attempt, combined with a complete lack of willing on my part as they seem so... magnolia. So boring. So monotonous. So expected, even or especially while they are attempting to be bombastic and novel. I think the "look at me, look at me" nature of them make me switch off. I want something to tease me in, almost surprise me that I've found it. Like Cracker, The Bridge or The Thick Of It.

I thought I'd found that with the BBC's recent series Happy Valley: it was acted okay, I enjoyed the overarching story but haven't watched past episode four. And yet I can't really say why. It should be up my street, it's based up north, police based and has some good actors in. But it's just a bit drawn out. The low key approach I was just hoping for back fired. It was too dull. I had a bad taste in my mouth from the first episode, but I listen to the voice inside that suggests this kind of attitude means I'll never enjoy anything new, so I continued and persevered for another three weeks and gave up.

This post is brought up after my other half just asked me to watch the Netflix original drama Orange Is The New Black. I have nothing really against it, but I can't be bothered watching it and paying attention. It would be okay as wallpaper TV, to have on while I did something more interesting, or perhaps snoozed on the couch. But that's not really watching TV, that's just having TV on. Similarly I couldn't really watch Fringe, I watched the odd episode but commitment to that much TV was beyond my patience so I left him to watch it whenever he liked and I dipped in and out of it. I didn't feel like I missed much story-wise and enjoyed the little of it I watched but I'm not tempted by more. I don't know how the story of Fringe ends, but I really don't care. I suppose I'll trip over the storyline on some page at some point or I'll find out by social osmosis, but I won't be tempted to watch it.

For the future however, I'm hoping I'll find out why I dislike series so much. I'm not after suggestions for series, I'm asking if anyone else is in the same boat when it comes to this. Could you please offer an explanation so I can at least understand how to try and enjoy series from the first episode. I just seem to dislike them from the start and then like a child sulk through them. Maybe there's no way through this and I should just take up a TV friendly hobby like knitting, doodling or snorting crack.


Monday 2 June 2014

What your coffee says about you

I've augmented something on twitter and added a few personal options.  Don't ask me for sugar in your coffee.


Wednesday 28 May 2014

Where is my driverless car, Google?

I'm a person who mistrusts corporations. They work with the premise that they exist to make profit, and in economics terms, that means the purchaser gets a worse deal. If a producer of a primary product (raw materials) adds profit, then a manufacturer makes things and adds profit, then a retailer adds profit, the end consumer is paying the profit margins of three companies. This isn't inherently bad if each is adding value.

The hardest one to argue for is the retailer. In essence, they buy finished goods, put them on shelves and allow you to purchase them. Their added value is choice and convenience; perhaps after sales or maybe even advice presale. However, if we think of a market like the supermarkets, this does point to the only areas of value added are choice and convenience. I won't go all Veblen or Marx on you here, that's for another post, but I thought I'd make my standpoint clear from the start.

Google have announced today they're making driverless cars, and I immediately loved the idea. It's like Sci-Fi and I want one now. I don't understand people who reckon that they enjoy driving. It's brain numbing monotony and repetition, I only look forward to driving now as I am an odd ball who is wise enough to drive an automatic transmission vehicle (I can drive a manual car, I did for many years) as I see no one manually cranks their cars to start or manually adjusts the choke to change fuel air mix when starting.

This last thing is probably lost on most people born after 1980, cars used to have a knob to pull out when you started it, on the steering column. It changed the fuel air mix and as you drove and the car engine got hotter, you pushed it back in. My first car (C registration Vauxhall Nova)  had one and on cold, wet mornings, they were a nightmare: push it back in too early and the car would splutter and stall. Mine had a spring that pulled it gradually back in and if you got to traffic lights before it was hot, the car just conked out, kangaroo style. So I augmented it with a wooden clothes peg that I clipped on to hold it out.

Anyway, Google's car sounds awesome. Yes, it'll make taxi drivers redundant for car owners who have a drink, but that was said about email - apparently email would make Royal Mail bankrupt, but of course it was their pension scheme, not the universal postage costs to blame there. In the end it takes us away from doing something we'd rather not do and gives us more time to do things we'd rather do. So instead of paying attention to the back of a truck on a winding country road, we can admire the gorgeous views to our side.

This is where my unease comes in usually with companies. I mistrust them but Google seem to give us toys and gadgets we like. This can be said of many firms, but for me Google's approach is something special. Yes, they have a monopoly on search. Inherently that's a bad thing, but while I could use another service just as easily, I find myself not doing. The reason? Their search is better. A monopoly based on a better product is something to knock from its pedestal, and no one seems to be able to no matter how much Microsoft throw at the problem, so I'm comfortable with it.

I end up with the same conclusion whatever Google does (some specific examples omitted): they make something I'd actually use, they make the best of breed and they give it out on an advertising funded model or use the data to better understand you. I wish Tivo actually did this, but it seems to always tell me I'd love stuff on channel 5 or something with James Corden in. With a slight unease, I accept Google's products much more readily than other corporation's products simply due to them using science, maths and software engineering to make better and better things.

It's going to be a long time until they're on the road, but the Google car is a step forward and perhaps the battle to make them legal will make them better still. I look forward to driving one. Hang on, don't I mean riding one?

Thursday 22 May 2014

Voting 2014

I seriously have no idea for whom to vote today.  I can vote in the European Elections, but there's no other ballots in my local area.

Too Long; Didn't Read version:

I think I'm going to vote Labour tactically, as I do not believe in their party at all, but it'll help keep out the nasty and racist parties (you know who I mean).  Perhaps if you don't know how to vote either read this for inspiration, but free kisses available from me to anyone that bothers to vote today.

I'm Bored, I Want Your Poorly Qualified Opinion version:

A short hop around my voting history sees me voting for the first time in the 2001 UK General Election as I grew up attracted to the values of the Labour party, but my vote for them left me feeling a small part of the blame for military involvement in Iraq amongst other things.   I vowed never to vote Labour again, even though later I quite liked Gordon Brown as Prime Minister.  

In 2005 I voted Liberal Democrat, as I did in 2010.  This had the unintended consequence of feeling that my vote supported a Conservative government through the Coalition Government.  I never imagined that Liberal Democrats would form a coalition with the Conservatives.  One saving grace is that my constituency of Ribble Valley returned a Conservative MP with 50% of the vote so my vote didn't count anyway.  I'm therefore not looking forward to voting in the 2015 election as it's a lost cause, but with our MP being Nigel Evans, this might rock the Conservative vote a bit.
See: http://en.wikipedia.org/wiki/Ribble_Valley_(UK_Parliament_constituency)#Elections_in_the_2010s

Back to today.  Here's my choice of candidates:
http://www.bbc.co.uk/news/uk-politics-27126227

We can quickly discount a couple from the ballot paper.  I'm pro-Europe, so I'd never vote for the parties centred around even slight anti-Europe sentiment.  Furthermore, I'd remove any restrictions on immigration if I had my way, as I only vaguely acknowledge the concept of arbitrary lines on a map designating national boundaries, so the parties who campaign for tighter immigration laws as their raison d'être are out.

The younger me might be tempted by either the Socialist Equality Party (http://en.wikipedia.org/wiki/Socialist_Equality_Party_(UK)) or even Pirate Party (http://en.wikipedia.org/wiki/Pirate_Party_UK) but that would be a mostly wasted or, at best, a protest vote.

So sensibly, I'm left with Labour, Liberal Democrats or Greens.

I am turned off by past experience of voting both Liberal Democrats and Labour, so I resign myself to considering the Green Party.  However, while I agree with most of what they say - as much as you can take to heart what political parties say - I disagree with one major bullet point in their manifesto (http://issuu.com/lifework/docs/minimaniissuu?e=7496317/7612527).  In it, they talk of ending building Nuclear Power Stations.  I can't abide this stand point and so I cannot vote for them especially as their share of the result will be too small; I can go into why but that's not the point of this post.

I really want to use my vote, but that would mean choosing between sensible and 'wasted' votes.  So after paring it down, my vote would be best served voting Labour.  Not for one moment because I support them, but because I want the nasty parties to stay out.

You see, I don't want my constituency represented by the flag waving thugs and morons who hide behind a veneer of political respectability in order to appear in the media alongside other parties; or the 'entertaining' lunatics who are unfathomably averse to simple things like change and social cohesion thus appear on television and radio so often I'm frightened my sanity can't take more of their incomprehensible pseudo-naïve bigotry.  You know who I mean.

So, Labour it is for me as the Liberal Democrats are a weaker choice if you're trying to keep minor parties out.  I wish there was another option, but I can't waste my vote on a protest, or vote on a genuine match for my views when both of these would essentially be a vote for the people I'd hate to see in any government.

No matter how little your vote goes towards the end result, no matter how little you care about politics, I implore you to vote today if you can.

Monday 28 April 2014

Recipe for a Webcam Server using Debian

An old "XP vintage" PC
Sorry for this if you're only a casual reader, this is more aimed at people wanting to make the same thing: a kind of self-uploading security camera thing using webcams and old PC.  Hopefully this guide is easy enough to follow for anyone!

I meant to write this up a few months ago, but there wasn't really an audience or platform to do it.  I guess my blog is the best place for it.  I basically wanted to combine and use a few old bits at home and around the office to make a computer that would take pictures from web cams and upload them to the web.  Here's my recipe based on a very hastily put together method, which possibly could've been a lot more secure, a lot more failure resilient and a lot more efficient - maybe suggest changes and I'll link it through.

Ingredients


Time
Probably a couple of hours in all


Skill level
This could be done by anyone, if your ingredients are similar to mine


Overview
The idea is to have a headless (i.e. no need for keyboard/mouse/monitor) computer running Debian that regularly captures webcam images and uploads these via FTP as a cron.  This means I can have it running under a desk, doing it’s job without any input from me.


Notes
Please note this guide is not designed as a “best practice guide”; it is designed to tell you how we did it so you might have a go at doing something similar.


The PC I used was a 64bit machine, mostly working in that all of it worked apart from the optical disc drive - I had to use a USB 'pen' drive to install Debian.


Debian is a funny beast and you might be better using Ubuntu (derived from Debian, but has more non-free sources).



A very old webcam that worked
I also discovered webcams aren’t exactly plug and play - especially the older ones we were using.  I bought a modern one with a fisheye lens, and had three old ones laying around at home and the office.  The only one that we couldn’t get to work was a Microsoft one of a 10 year vintage.

Method
  • You should have a burned disc of Debian, from the link above - it includes the non-free firmwares so you won’t be caught out by hardware needing them.  I'd advise at this stage to have the cameras plugged into the USB ports while installing, plus you’ll need a monitor and keyboard connected to do the installation of Debian.  After this, we’ll move to Terminal App in OSX/Putty on Windows.  Also, make sure your box will boot to an OS without a monitor and keyboard before leaving this stage - use BIOS settings to confirm “halt on errors” or the like is not set.
  • Install Debian as one big drive, set up users and note these down - you’ll need these.  Make sure you uncheck installing a user interface (you won’t need it!) and you have selected to be an SSH server.
  • Once you’re back and installed the base system, you’ll need to fix the IP and connect via SSH.
    • Change to root user:su
    • Open interfaces in nano:nano /etc/network/interfaces
    • Change this to be:# This file describes the network interfaces available on your system
      # and how to activate them. For more information, see interfaces(5).

      # The loopback network interface
      auto lo
      iface lo inet loopback

# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
       address
192.168.0.100
       netmask
255.255.255.0
       gateway
192.168.0.1
Change the last three lines to match your set up - the address line should be the address you’d like the system to stick to for SSH access.
  • Save the file (ctrl+O), and exit nano (ctrl+X)
  • Try and connect via SSH on your normal system, on OSX open terminal app and type:ssh username_you_setup@the_ip_address_of_system
    • you should get a question about security keys - this is fine, just accept and type in the password you set up debian with.
    • if all is well, you should be logged in as a system user on your debian box.
  • We need to check which (if any) of the webcams are working.  These are set up as devices and we’ll see a numerical list of video capturing devices.
    • So, change to root if you’re not already:su
    • Change directory to the devices directory:cd /dev/
    • And list the devices:ls -la
    • You should see a list of “video” devices, numbered from 0.
    • If you’ve got less video devices than cameras attached, one or more do not work - this guide will not tell you how to get a camera working, you’re probably best to buy a newer one and check if it works with Linux in general.
  • Okay, we’ve got some cams working but we need to make them stick to particular references: as the system boots, the device’s video number may change and if you’ve got a motley crew of cams like us, they’ll all need different settings in a later stage.  We need to use rules for udev, which is a facility that reacts to usb and other devices being connected.  They also change when you unplug and plug, too
    • Change to the udev rules folder:cd /etc/udev/rules.d/
    • Probe the devices in turn (changing video0 to each camera):udevadm info -a -n /dev/video0
    • Copy the outputs to text editor windows for perusal and then create a new rule file:nano 00-webcam.rules
    • Okay blank file, and here’s where your mileage may be very different to mine.  Hang in there, it’ll be fine if you use a bit of common sense - but do have some patience.
      • Remember the probing output?  Okay, that’s the USB tree of how the computer speaks to the device.  The way I understand - or at least attempt to explain this - is that the top-most output is the device itself, and as you go down the entries, you’re approaching the PC itself.
      • Mine has a section like this:
        looking at device
        '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1:1.0/video4linux/video2':
           KERNEL=="video2"
           SUBSYSTEM=="video4linux"
           DRIVER==""
           ATTR{name}=="Logitech QuickCam Zoom"
           ATTR{index}=="0"
           ATTR{button}=="1"
      • udev works by matching rules to given search criteria for a device when connected - so in this case, I used one piece of information
        • ATTR{name}=="Logitech QuickCam Zoom"
      • Basically, the rough guide is you can use any information to identify a device (some devices don’t give you a name, like this one unfortunately) but not from multiple parent devices.
      • So our rule looks like this:
        • SUBSYSTEM=="video4linux", ATTR{name}=="Logitech QuickCam Zoom", SYMLINK+="webcam1"
      • To explain this, it looks on SUBSYSTEM, then looks for ATTR{name} and for this device creates a symlink (a copy of the device reference) as webcam1.  You might set up similar rules for webcam0, webcam2, etc.
      • Save the file (ctrl+O) and exit (ctrl+X)
      • We restarted at this stage and probing the devices we created (webcam0 etc) revealed our rules worked and the expected cam was on the right number.  Note: webcam0 might actually be a symlink to video3, so you’ll use the webcam0 referencing.  You might need to use different ATTR or what-have-you until the rule works.  Patience, be a good Hitchhiker and don’t panic.
  • Now we created a new user called webcam and gave it a password.  We added this user to the group “video” to allow it access to the devices.  You might not want to use this step, but adding users etc. can be found searching Google for full explanation, but here goes:
    • useradd -G video webcam
  • I restarted here to make sure everything worked and checked webcam user could log in and access video devices via the webcam symlinks.
  • Next step, install fswebcam tool and ncftp from the repository as root (there may be prerequisites, that’s fine):
    • su
    • apt-get install fswebcam
    • apt-get install ncftp
  • Okay now switch to the user webcam (or the user you’ll be running to upload the images):
    • su webcam
  • ..and make sure you’re in that home directory..
    • cd ~/
  • ..and create a new batchfile to run.
    • nano webcamrun.sh
    • contents:sleep 1
      fswebcam -c webcam0.cfg
      ncftpput -f ftp.cfg /folder/on/your_webserver live0.jpg
      rm live0.jpg
    • Replace the references “live0.jpg” and “webcam0.cfg” with the same reference as your first webcam device you created earlier.  Put the folder reference (from the root of the FTP user’s directory) to where you want each uploading.
    • Also, repeat these lines in this file for each different webcam device.
  • Now we need to write the “webcam0.cfg” (etc.) and “ftp.cfg” files:
    • FTP config file (all cams use same FTP):
      • nano ftp.cfg
      • Contents:host HOSTNAME_OR_IP
        user
        USERNAME
        pass
        PASSWORD
    • Webcam0.cfg (name multiple):
      • nano webcam0.cfg
      • Contents:device /dev/webcam1
        jpeg 95
        resolution
        640×480
        title "
        TITLE OF CAM"
        delay 1
        set "White Balance Temperature, Auto"=True
        set "Backlight Compensation"=0
        set "Brightness"=40%
        set "Contrast"=60%
        set "Saturation"=30%
        set "Gamma"=3%
        frames 10
        save "
        live1.jpg"
      • change the “webcam1”, “live1.jpg” references to match the device you want and jpg reference in the .sh batch script for upload.  This was the best settings for an old camera, have a look round for settings and play - we found these were not exactly a two minute affair to get the best result, and you can edit these files later.
  • Once you’ve written a webcam config file for each cam and an FTP config, you can test the script:
    • ./webcamrun.sh
    • If you get any errors, fix them.
  • Now, we do the cron.
    • I found it easier to switch to root, and create from there, so:
      • su
      • crontab -u webcam -e
      • Change “webcam” to the user in which you set up the .sh batch file.
      • Add the following line for every minute, of every hour, of every day:
        • * * * * * ~/webcamrun.sh
      • ctrl+o, ctrl+x
  • Done!
    • Restart and if it didn’t fail when you tested before all should be hunky dory in the cron.


A more modern webcam that we found easiest to install


Sources
While I was fighting through doing this I used several guides, but none of them supplied the whole answer, hence this guide.  The following (in no particular order) were completely indispensable though: