<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Divaricating Systems</title>
	<atom:link href="http://johnarthur.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnarthur.wordpress.com</link>
	<description>Hardware and software design services</description>
	<lastBuildDate>Mon, 23 Jan 2012 00:36:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='johnarthur.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/7e97e949066f8d34b80ef819fbfdf23d?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Divaricating Systems</title>
		<link>http://johnarthur.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://johnarthur.wordpress.com/osd.xml" title="Divaricating Systems" />
	<atom:link rel='hub' href='http://johnarthur.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A dual-camera server for Zoneminder</title>
		<link>http://johnarthur.wordpress.com/2011/10/04/a-dual-camera-server-for-zoneminder/</link>
		<comments>http://johnarthur.wordpress.com/2011/10/04/a-dual-camera-server-for-zoneminder/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 20:08:42 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ZoneMinder]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=133</guid>
		<description><![CDATA[A while ago I managed to acquire a used Asus WL500G Premium wireless router for $50. Its a rather useful device as it is supported by OpenWRT and has two USB 2.0 ports. That&#8217;s quite unusual for a wireless router and it was a lucky find. My idea was to use it to run two [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=133&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A while ago I managed to acquire a used Asus WL500G Premium wireless router for $50. Its a rather useful device as it is supported by OpenWRT and has <strong>two</strong> USB 2.0 ports. That&#8217;s quite unusual for a wireless router and it was a lucky find. My idea was to use it to run two USB webcams as IP cameras connected over the household LAN to a machine I have running the very good <a href="http://www.zoneminder.com/">Zoneminder</a> security software. The idea was to get better resolution than the conventional analog CCD camera + capture card system that I was using, which tops out at about 640 x 480.</p>
<p>I&#8217;m going to describe the process I went through to get this working in the hope that it might be useful to anyone else trying to assemble an OpenWRT-based multi-camera server. Its a pity that relatively few devices are available that will run OpenWRT and have multiple USB 2.0 ports, but they do exist and I hope to show they are worth pursuing.</p>
<p>So, I bought a Logitech S5500 webcam, which was capable of 960 x 720, connected it to the router, installed OpenWRT and mjpg-streamer, and&#8230; got very mediocre results. The video stream kept breaking up, triggering Zoneminders alarms, and the image couldn&#8217;t be expanded much beyond 512 x 384 before the load on the Zoneminder machines CPU went over 1.0, indicating Imminent Problems. I assumed that the issue was with the Zoneminder machine being underpowered; it was a 256Mbyte 1.2GHz Pentium III.</p>
<p>So when I eventually replaced it with a nice new Pentium dual-core E6500 with 1Gbyte, I was surprised to find that the problems remained. Some checking of the Zoneminder logs soon turned up some evidence; repeated complaints of &#8220;Invalid JPEG file structure: two SOI markers&#8221;. So. Clearly either the camera, or mjpg-streamer was generating bad JPEGs&#8230;</p>
<p>There is a moral here; always Google your error messages. I omitted to do this, or wasn&#8217;t thorough enough.</p>
<p>So I proceeded to build the latest stable version of OpenWRT Backfire for the WL50oG. OpenWRTs build process has been steadily improving; here is all that was needed. I did this build on a Atom-based netbook running Ubuntu Lucid:</p>
<pre>sudo apt-get update
sudo apt-get install subversion build-essential libncurses5-dev zlib1g-dev gawk flex git-core quilt
mkdir openwrt
cd openwrt
svn checkout svn://svn.openwrt.org/openwrt/branches/backfire</pre>
<p>When svn completes its downloads you can edit buildsystem/feeds.conf.default and save some time and bandwidth by taking out feeds you won&#8217;t use.  For this build I commented out the feeds for LuCI and the Xwrt WebUI.</p>
<pre>cd backfire
./scripts/feeds update -a
./scripts/feeds install -a
make defconfig
make menuconfig</pre>
<p>This will present a menu interface, in which I selected the following items: (pressing space twice to set to &#8216;*&#8217;, not &#8216;M&#8217;). I could have done all the customisation of OpenWRT after building with the default settings, but its easy to do here. I didn&#8217;t want to use the wireless connectivity, and I wanted mjpg-streamer and the ability to write to external USB drives (in case I wanted to configure the router as a time-lapse camera system), so:</p>
<pre>Target System: (Broadcom BCM947xx/953xx)
Target Profile: (ASUS WL-500g Premium v1 (Atheros WiFi))
Base System:
     select block-mount
     deselect dnsmasq, firewall
Network:
     deselect iptables,ppp,wpad-mini
Kernel modules:
     select USB support: kmod-usb-core, kmod-usb-storage, kmod-usb2, kmod-usb-video, kmod-uhci
     select Video Support; kmod-video-core, kmod-video-uvc
     select Filesystems-&gt;kmod-fs-vfat, kmod-nls-xxxx
Multimedia:
     select mjpg-streamer

make V=99 2&gt;&amp;1 | tee build.log | grep -i error</pre>
<p>After this build (which may take some time, as it needs to download quite a lot of source), the firmware image can be found in backfire/bin/brcm47xx/openwrt-brcm47xx-squashfs.trx. The fancy make invocation ensures that if things go wrong the console should show errors and the build.log file has the complete log of the build.</p>
<p>Installing the image, given that OpenWRT was already running on the router, was easy. First, I set up an ftp server on the build machine with anonymous access enabled:</p>
<pre>sudo useradd -d /home/ftp/ftp -s /bin/false ftp
sudo mkdir -p /home/ftp/upload
sudo apt-get install vsftpd
sudo vi /etc/vsftpd.conf</pre>
<p>I edited the configuration to set anonymous_enable=YES, then restarted the server to get it to reread the configuration file.</p>
<pre>sudo service vsftpd restart</pre>
<p>and copied the image into the server directory so the router could find it:</p>
<pre>cp bin/brcm47xx/openwrt-brcm47xx-squashfs.trx /home/ftp/ftp</pre>
<p>From here its a matter of logging in to OpenWRT on the router, and telling it to load the image over ftp and update to it:</p>
<pre>cd /tmp
wget ftp://192.168.2.3/openwrt-brcm47xx-squashfs.trx
sysupgrade /tmp/openwrt-brcm47xx-squashfs.trx</pre>
<p>192.168.2.3 happened to be the address the development machine had been given by my DHCP server; your mileage may vary.</p>
<p>OpenWRT Backfire doesn&#8217;t actually have the latest version of mjpg-streamer, but it swiftly became apparent that it hadn&#8217;t solved the problem. So my next step was to add some code to mjpg-streamer to filter out bad frames, on the assumption that these were coming from the webcam. The JPEG format is well documented (the <a href="http://en.wikipedia.org/wiki/JPEG">Wikipedia</a> article is a good source), and it it isn&#8217;t difficult to parse the basic structure without diving into the compressed data. Two SOI markers should be easy to detect.</p>
<p>To cut a long story short, my filter code, once running on the router, didn&#8217;t find any such thing.</p>
<p>At this point I did what I should have done much earlier, which was to Google &#8220;zoneminder&#8221; and &#8220;Invalid JPEG file structure: two SOI markers&#8221; a bit more thoroughly. And there in the Zoneminder FAQ is the answer:</p>
<h3><span style="color:#999999;">What causes &#8220;Invalid JPEG file structure: two SOI markers&#8221; from zmc (1.24.x)</span></h3>
<p><span style="color:#999999;">Some settings that used to be global only are now per camera. On the Monitor Source tab, if you are using Remote Protocol &#8220;HTTP&#8221; and Remote Method &#8220;Simple&#8221;, try changing Remote Method to &#8220;Regexp&#8221;.</span></p>
<p>This was indeed the fix. It was nothing to do with the camera or mjpg-streamer, but an internal problem in Zoneminder. I could now use the camera, but after only a day of testing a new problem became apparent. Some webcams, and the S5500 is one of them, have trouble with darkness. Here is a sample frame from the S5500 at night.</p>
<div id="attachment_140" class="wp-caption alignnone" style="width: 968px"><a href="http://johnarthur.files.wordpress.com/2011/10/2011_08_27_18_28_52_picture_000001854.jpg"><img class="size-full wp-image-140" title="2011_08_27_18_28_52_picture_000001854" src="http://johnarthur.files.wordpress.com/2011/10/2011_08_27_18_28_52_picture_000001854.jpg?w=958&#038;h=718" alt="" width="958" height="718" /></a><p class="wp-caption-text">Night, badly rendered.</p></div>
<p>The little 8&#215;8 blocks in this image are a giveaway that this really is a problem with the JPEG encoding. This time it was easy to prove that it was coming from the webcam, whose internal processor evidently can&#8217;t encode a uniformly black frame. Unfortunately, it doesn&#8217;t produce a consistent image like the one shown above, but a kaliedoscopic variety of them. This triggers Zoneminders motion detection, and you wind up with huge alarm events that last for hours and eat up your storage.</p>
<p>Fortunately, this problem is common enough that mjpg-streamer has a solution. The bad frames are all relatively small, there being no detail to encode, so a simple size test can detect them. The -minimum-size parameter allows us to throw away frames that are smaller than a certain size, and a little testing quickly revealed that at 960 x 720, any frame under 21000 bytes could be assumed to be bad. So:</p>
<pre>/usr/bin/mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 960x720 -m 21000" -o "output_http.so -p 80"</pre>
<p>should be the solution? Well, nearly. The trouble is that what mjpg-streamer does with the bad frames is skip over them and not return a result until it gets a good frame. Which is fine for occasional bad frames, but when the camera produces a continuous stream of them &#8211; at night &#8211; mjpg-streamer may not return a result for hours. Zoneminder doesn&#8217;t like this either, and is prone to disable the camera altogether. This problem is apparently addressed in Zoneminder 1.25, but I&#8217;m running 1.24.2, so another solution was needed. The easiest thing to do was to edit input_uvc.c in the mjpg-streamer source so that instead of skipping the frame, mjpg-streamer returned the last good frame that it had. This was a matter of changing the lines</p>
<pre>        if(pcontext-&gt;videoIn-&gt;buf.bytesused &lt; minimum_size) {
            DBG("dropping too small frame, assuming it as broken\n");
            continue;
        }</pre>
<p>to:</p>
<pre>        if(pcontext-&gt;videoIn-&gt;buf.bytesused &lt; minimum_size) {
            DBG("dropping too small frame, assuming it as broken\n");
            /* Provide the previous frame, as this condition might last some time... */
            pthread_cond_broadcast(&amp;pglobal-&gt;in[pcontext-&gt;id].db_update);
            continue;
        }</pre>
<p>This change isn&#8217;t really suitable for all uses as it means that the camera server may return an image of what was visible several hours ago when the scene was adequately lit, rather than current darkness. A more elegant solution would be to return a synthetic JPEG that was just a uniform field of black, but this was a quick workaround for my purposes.</p>
<p>Changing the code in the OpenWRT source and getting it recompile without ignoring or overwriting the changes was a bit tricky. The combination of OpenWRTs interesting build system as it interacts with mjpg-streamers makefile means that just changing input_uvc.c deep down in the build_dir directory and doing a make won&#8217;t work. After some trial and error I wrote a script to do the rebuild:</p>
<pre>#!/bin/sh
MJPGDIR="build_dir/target-mipsel_uClibc-0.9.30.1/mjpg-streamer-r136"
touch $MJPGDIR/mjpg_streamer.c
rm $MJPGDIR/ipkg-brcm47xx/mjpg-streamer/usr/lib/*.so
rm $MJPGDIR/*.so
make V=99 &gt;build.log</pre>
<p>Having fixed this, I bought a second webcam (a Logitech C905) as it was now clear the whole idea would work as intended. The differences between the two webcams when looking at the same scene were surprising. Here is the S5500:</p>
<p><a href="http://johnarthur.files.wordpress.com/2011/10/s5500-sample.jpeg"><img class="alignnone size-full wp-image-142" title="Logitech S5500 sample" src="http://johnarthur.files.wordpress.com/2011/10/s5500-sample.jpeg?w=958&#038;h=718" alt="" width="958" height="718" /></a></p>
<p>The C905 wins on detail, but also has quite different colour rendering.</p>
<p><a href="http://johnarthur.files.wordpress.com/2011/10/c905-sample.jpeg"><img class="size-full wp-image-148 alignnone" title="Logitech C905 sample" src="http://johnarthur.files.wordpress.com/2011/10/c905-sample.jpeg?w=958&#038;h=718" alt="" width="958" height="718" /></a></p>
<p>The final step was to get both webcams to start up when OpenWRT booted.</p>
<p>OpenWRTs initialisation is a little complicated, and is controlled by the files in /etc/rc.d, /etc/init.d, and /etc/config. The mjpg-streamer package includes appropriate entries in each of these directories to automatically start up a single instance, but there is nothing to prevent us from running two versions provided that we tell them to serve to different TCP ports. The two webcams appear as /dev/video0 and /dev/video1. So we edit /etc/config/mjpg-streamer and add a couple more config options for device2 and port2:</p>
<pre>config mjpg-streamer core
        option device           "/dev/video0"
        option device2          "/dev/video1"
        option resolution       "960x720"
        option minimumsize      "21000"
        option fps              "10"
        option port             "80"
        option port2            "8080"                                
        option enabled          "true"</pre>
<p>Then we add an entry in init.d; the easiest way is to duplicate the existing script:</p>
<pre>cd /etc/init.d
cp mjpg-streamer mjpg-streamer2</pre>
<p>and edit the second script to use the device2 and port2 options, plus its own PID file name.</p>
<pre>#!/bin/sh /etc/rc.common
# Copyright (C) 2009 OpenWrt.org
START=50

SSD=start-stop-daemon
NAME=mjpg_streamer
PIDF=/var/run/$NAME.2.pid
PROG=/usr/bin/$NAME

start() {
        config_load mjpg-streamer
        config_get device core device2
        config_get resolution core resolution
        config_get fps core fps
        config_get port core port2
        config_get_bool enabled core enabled
        config_get minimumsize core minimumsize
        [ $enabled -gt 0 -a -c $device ] &amp;&amp; sleep 3 &amp;&amp; $SSD -S -m -p $PIDF -q -x $PROG\
         -- --input "input_uvc.so --device $device --fps $fps --resolution $resolution"\
         --output "output_http.so --port $port" &amp;
}

stop() {
        $SSD -K -p $PIDF
}</pre>
<p>Finally we need to add a link in the rc.d directory to the new init.d script:</p>
<pre>cd /etc
ln rc.d/S50mjpg-streamer2 ../init.d/mjpg-streamer2</pre>
<p>This will start up the WL500 with both cameras if both are present, and serve them on port 80 and port 8080. The images and movie streams can therefore be found at:</p>
<p>http://<em>&lt;IP address&gt;</em>/?action=snapshot</p>
<p>http://<em>&lt;IP address&gt;</em>:8080/?action=snapshot</p>
<p>and</p>
<p>http://<em>&lt;IP address&gt;</em>/?action=stream</p>
<p>http://<em>&lt;IP address&gt;</em>:8080/?action=stream</p>
<p>respectively. Entering the snapshot URLs above into Zoneminder has produced a working system. The only remaining issue was setting up  Zoneminder to minimise the CPU usage, which is an art in itself and better covered in the Zoneminder forums&#8230;</p>
<br />Filed under: <a href='http://johnarthur.wordpress.com/category/openwrt/'>OpenWRT</a>, <a href='http://johnarthur.wordpress.com/category/ubuntu/'>Ubuntu</a>, <a href='http://johnarthur.wordpress.com/category/zoneminder/'>ZoneMinder</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=133&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2011/10/04/a-dual-camera-server-for-zoneminder/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2011/10/2011_08_27_18_28_52_picture_000001854.jpg" medium="image">
			<media:title type="html">2011_08_27_18_28_52_picture_000001854</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2011/10/s5500-sample.jpeg" medium="image">
			<media:title type="html">Logitech S5500 sample</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2011/10/c905-sample.jpeg" medium="image">
			<media:title type="html">Logitech C905 sample</media:title>
		</media:content>
	</item>
		<item>
		<title>Trouble at t&#8217;phone</title>
		<link>http://johnarthur.wordpress.com/2011/02/07/trouble-at-tphone/</link>
		<comments>http://johnarthur.wordpress.com/2011/02/07/trouble-at-tphone/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 22:54:23 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=125</guid>
		<description><![CDATA[I have been revising my file server/firewall/ZoneMinder system that I described in some of my first blog posts and it has all gone pretty smoothly. I bought a new motherboard and CPU, mostly to get gigabit Ethernet support, but in the hope that ZoneMinder would work better with my IP camera (another story for later [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=125&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been revising my file server/firewall/ZoneMinder system that I described in some of my first blog posts and it has all gone pretty smoothly. I bought a new motherboard and CPU, mostly to get gigabit Ethernet support, but in the hope that ZoneMinder would work better with my IP camera (another story for later post). The new board is an Asus G41-based M-ATX part with a 2.9GHz Pentium Dual-Core E6500 on it. The bump in CPU power from a 1.2GHz Pentium 3 is substantial. I was able to reuse the old HP box and power supply, and power consumption has only gone up from 45W to ~53W, which is pretty good. Its running Ubuntu Lucid Lynx (10.04) and installation and setup went very smoothly apart from some confusion with shorewall, whose default two-interface setup assumes that the local net is eth1 and the Internet is on eth0. I have it the other way around and you need to change <em>all</em> the config files.</p>
<p>This post, however, is about a new idea I wanted to try, which was to install my old Telecom CDMA phone in the server cupboard and use it to send and receive text messages to and from the server.</p>
<p>On the face of it this didn&#8217;t look difficult. There is a Linux/Windows/MacOS package called gnokii that does practically everything with a phone, provided that the phone supports Bluetooth or has a data cable, that you could possibly want. My Nokia 6165i has Bluetooth, so the first step was to buy a cheap Bluetooth adapter (Dick Smith, $20), plug it in, and fire up Bluetooth support:</p>
<p><strong>sudo apt-get install bluez</strong></p>
<p>Once I had that, I turned on the phone, told it to be discoverable on Bluetooth (down in Settings/Connectivity/Bluetooth/Bluetooth Settings) and told Bluetooth to look for it:</p>
<p><strong>hcitool scan</strong></p>
<p>Scanning &#8230;<br />
00:12:D1:3F:00:8F    Michael H 6165i</p>
<p>It found it! Now to get gnokii:</p>
<p><strong>sudo apt-get install gnokii</strong></p>
<p>The version of gnokii that comes with Ubuntu 10.04 is 0.6.28, which has its preferences in ~/.gnokiirc or /etc/gnokiirc. Later versions change this, but for the moment it was enough to edit the heavily commented /etc/gnokiirc and use the Bluetooth ID given by hcitool so that the following lines were active:</p>
<p>port = 00:12:d1:3f:00:8f<br />
model = series40<br />
connection = bluetooth</p>
<p>debug = on</p>
<p>Debug is useful if you run into problems, as I did&#8230;</p>
<p><strong>gnokii &#8211;identify</strong></p>
<p>should then talk to the phone, whereupon we run into our first problem. The phone needs to pair to the Bluetooth transceiver on the PC, and if we were running desktop Ubuntu a nice dialog would come up on the desktop as well as the phone, we enter the same PIN into each dialog and all would be well. But this is running on a file server and I can&#8217;t do that. Some Googling eventually found a solution, which is to use one of the bluez examples to get the PIN code handshake done:</p>
<p><strong>sudo /usr/share/doc/bluez/examples/simple-agent hci0 00:12:d1:3f:00:8f</strong><br />
This prompts for the PIN code, you enter it, the phone prompts, you enter the same number, all is well.<strong> </strong></p>
<p>Now sending a text message should be as simple as:</p>
<p><strong>echo &#8220;This is a text message from the file server&#8221; | gnokii &#8211;sendsms <em>number</em> -r</strong></p>
<p>But life isn&#8217;t that simple. It seems to work, but the text messages simply don&#8217;t go. It took a good deal of debugging, updating, and fiddling about before I discovered the simple truth:</p>
<p>gnokii doesn&#8217;t support CDMA phones. CDMA is an older technology and the commands to send text messages are there &#8212; but subtly different. The only thing that might have worked was using gnokii AT mode, which I could get at by changing model = series40 to model = AT in the preferences. But the answer to that is short and final:</p>
<p>PDU mode is not supported by the phone. This mobile supports only TEXT mode<br />
while gnokii supports only PDU mode.<br />
SMS Send failed (Unknown error &#8211; well better than nothing!!)</p>
<p>So there we are, it isn&#8217;t going to work. It wasn&#8217;t going to work for long anyway, as the old CDMA network is going to be turned off next year, so the next step is to buy a  GSM Bluetooth phone and try again (ones with cracked but otherwise functional screens can be had very cheap on Trademe, I  see&#8230;). I hope to extend this post with better news at some point in the future.</p>
<br />Filed under: <a href='http://johnarthur.wordpress.com/category/linux/'>Linux</a>, <a href='http://johnarthur.wordpress.com/category/ubuntu/'>Ubuntu</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=125&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2011/02/07/trouble-at-tphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>
	</item>
		<item>
		<title>Now what?</title>
		<link>http://johnarthur.wordpress.com/2011/01/05/now-what/</link>
		<comments>http://johnarthur.wordpress.com/2011/01/05/now-what/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 00:31:34 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=74</guid>
		<description><![CDATA[If you have seen this blog before, you may be wondering at its changed appearance and title.  What has happened is that I am setting myself up as an independent contractor/consultant in embedded systems design.  I hope this change will benefit the blog, as I have a number of ideas I want to pursue which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=74&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have seen this blog before, you may be wondering at its changed appearance and title.  What has happened is that I am setting myself up as an independent contractor/consultant in embedded systems design.  I hope this change will benefit the blog, as I have a number of ideas I want to pursue which I should be able to write about. Its quite a change and I expect to be pretty busy for a while setting things up&#8230;</p>
<p>&#8211; Michael J A Hamel</p>
<br />Filed under: <a href='http://johnarthur.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=74&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2011/01/05/now-what/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>
	</item>
		<item>
		<title>My Netbook runneth over; dual booting Ubuntu on the Eee 1000HA</title>
		<link>http://johnarthur.wordpress.com/2009/03/03/my-netbook-runneth-over-dual-booting-ubuntu-on-the-eee-1000ha/</link>
		<comments>http://johnarthur.wordpress.com/2009/03/03/my-netbook-runneth-over-dual-booting-ubuntu-on-the-eee-1000ha/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 07:40:59 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=42</guid>
		<description><![CDATA[I have recently acquired one of the newly popular netbook machines, an Asus Eee 1000HA. This is one of a startling variety of Asus Eee models which seem to be being turned out as quickly as Asus can come up with new arrangements of netbook components. This particular version has a 10&#8243; screen, 1G of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=42&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have recently acquired one of the newly popular netbook machines, an Asus Eee 1000HA. This is one of a startling variety of Asus Eee models which seem to be being turned out as quickly as Asus can come up with new arrangements of netbook components. This particular version has a 10&#8243; screen, 1G of RAM and a 160G hard drive. It comes with Windows XP.</p>
<p>Windows XP is all very well, but I wanted to try running Linux on the Eee as well. 160G of hard drive is more than enough to run two different operating systems, so why not? There are several Linux distributions specifically designed for the Eee, so this should be easy, you might think. As it turns out, its not completely straightforward. Hence this post.</p>
<p><strong>Installation</strong></p>
<p>The first hurdle you encounter is that the Eee doesn&#8217;t have an optical drive, so there is no way to burn a CD and boot from it, which is the usual way to install Linux. The 1000HA does however have USB ports and an SD card slot. It turns out it is capable of booting from either a USB flash drive or an SD card; I happened to have an 4Gbyte SDHC card which I acquired for backup already in the SD slot. I decided to install the aptly-named Eeebuntu 2.0 Standard distribution via this card.</p>
<p>So, under Windows, it was simply a matter of downloading the eebuntu-2.0-standard.iso file (880Mbyte). The .iso file is an archive file containing a bootable disk image, so you can&#8217;t just copy it onto the SD card and expect it to boot. An application called UNetbootin is needed to unpack it onto the SD card correctly; I downloaded unetbootin-windows-312.exe and ran it. UNetbootin presents a single window where you can select Diskimage format, and browse to select the eebuntu .iso file. The SD card appears as a USB drive at letter I:\ (UNetbootin is clever enough to preselect this for you). Clicking on OK sets UNetbootin running copying the .iso across to the SD card, which takes several minutes and may appear to hang at the extra-large filesystem.squashfs file.</p>
<p>Once this process completes, click on the &#8216;Reboot Now&#8217; option that UNetbootin conveniently presents and as soon as Windows has shut down, hold down the ESC key. As the Eee starts up it should bring up the boot device menu. The SD card is described rather misleadingly as &#8220;USB:Single Flash Reader&#8221;. Select this and the UNetbootin menu will follow. Select &#8216;Default&#8217;, or wait for it select itself for you, and the Eeebuntu splash screen should follow. After a moment or so the Eeebuntu desktop comes up with the &#8216;Install&#8217; icon at the top left. Opening this starts the installer. This asks some straightforward questions up to the point where it asks how to partition the disk.</p>
<p>Here we need to be a bit careful, because the disk layout is not quite what the installer expects. Asus for some reason divides the disk into three usable partitions; the first 80Gbyte partition contains Windows XP and all its associated files. The second is also formatted for Windows, but is empty and appears under XP as the D: drive. The third is a recovery partition for booting from when Windows borks itself as it sometimes does. The installer will default to resizing the first Windows partition to 17.5Gbyte and installing Eeebuntu in the remaining space. This is workable, but not very even-handed. I prefer to install Eeebuntu over the unused second Windows partition. To do this — assuming that your D: drive under XP is empty —  select the Manual option and click Forward.</p>
<p>In the next dialog, select the second partition (/dev/sda2, about 65711Mbyte) and click on &#8216;Delete partition&#8217;. This is necessary because the partition is formatted for NTFS, which Ubuntu can&#8217;t install to. You will also need a swap partition, and we must make space for that.  Select the resulting free space and click &#8216;New partition&#8217;. Make a logical swap area partition that is larger than your RAM size (1024Mbyte in my case) I used a rather arbitrary 3000 Mbyte. Then make a logical ext3 partition with a mount point of &#8216;/&#8217; covering the remaining 62709 Mbytes. These should be /dev/sda5 and /dev/sda6. Select the format checkbox for the ext3 partition. Click Forward only after checking the above carefully as a mistake here could ruin your Windows install.</p>
<p>After answering a few more questions the install should run smoothly. On restarting (you can ignore the instruction to remove the nonexistent disc and close the nonexistent tray and just hit Enter) the Eee should display the Grub boot menu that allows you to select Ubuntu (or just wait and it will default to Ubuntu itself)</p>
<p><strong>Assorted fixes</strong></p>
<p>All is not completely plain sailing with Eeebuntu from the start, however.</p>
<p>Your first stop should be to plug into a wired LAN with Internet access and run the Update Manager. This will offer to do a bunch of updates (151 when I tried). For some reason it will complain that these <strong>can&#8217;t be authenticated</strong> when you click on Apply; you have to ignore this and apply anyway. Restart.</p>
<p>Under Applications/System Tools you will find an application called Eeebuntu Config. You should run it. It doesn&#8217;t have a setting for the Eee 1000HA (or it didn&#8217;t when I tried, you might get an updated version) I selected the 1000H, clicked on ALL and Execute. This runs a bunch of scripts that should customise Ubuntu better for the Eee.</p>
<p>If you start Firefox you may be startled by a license agreement for an add-on called DownThemAll, which you have to accept as it comes up again and again if you try to decline it. This was mistakenly added to Eeebuntu when it was built. You can remove it by accepting the license agreement, then clicking Disable and Restart Firefox in the Add-ons window that comes up when you do so.</p>
<p>The grub boot menu can be made friendlier (and you can pick what it defaults to and when) by editing /boot/grub/menu.lst. This needs to be done with supervisor privileges; I started a terminal session and entered &#8216;sudo gedit /boot/grub/menu.lst&#8217; which gives you a nice visual editor. The file is reasonable self-explanatory.</p>
<p>The mouse pointer when busy is for some reason a rather ugly monochrome wristwatch instead of the normal Ubuntu rotating pattern. I haven&#8217;t been able to figure out why so far.</p>
<p>Wireless performance is, irritatingly enough, not very good. Signal strengths are lower and performance is spottier than Windows XP, by a considerable margin. You might wonder how such a thing is possible. It turns out to be because the open-source ath5k drivers for the onboard 802.11 wireless card don&#8217;t work very well &#8211; Atheros, who make the wireless chip, don&#8217;t distribute detailed information about it, or driver source code. So the open-source driver has been written in the dark, as it were, and its a wonder that it works at all. There is actually an end-user solution to this which involves using a tool called ndiswrapper to run the XP drivers inside Linux. But getting that working is another story&#8230;</p>
<br />Posted in Linux, Ubuntu  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=42&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2009/03/03/my-netbook-runneth-over-dual-booting-ubuntu-on-the-eee-1000ha/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>
	</item>
		<item>
		<title>A Battery-powered Time-Lapse Camera</title>
		<link>http://johnarthur.wordpress.com/2008/06/26/a-battery-powered-time-lapse-camera/</link>
		<comments>http://johnarthur.wordpress.com/2008/06/26/a-battery-powered-time-lapse-camera/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 09:09:29 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[kamikaze]]></category>
		<category><![CDATA[NSLU2]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[UVC]]></category>
		<category><![CDATA[battery powered]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[time-lapse]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=36</guid>
		<description><![CDATA[Introduction The time-lapse camera system described in my earlier post is fine where mains power is available, but for remote locations and longer durations it rather falls down. At 5-6W power consumption it will flatten even a large wet-cell lead-acid battery in 3-4 days. Taking pictures less frequently does little to reduce the power consumption [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=36&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>The time-lapse camera system described in my earlier post is fine where mains power is available, but for remote locations and longer durations it rather falls down. At 5-6W power consumption it will flatten even a large wet-cell lead-acid battery in 3-4 days. Taking pictures less frequently does little to reduce the power consumption as the camera and NSLU2 run all the time.</p>
<p>Unless we turn the system off — or rather, get it to turn itself off. The NSLU2 has an onboard power supply switch controlled by a separate piece of circuitry that turns power on to the main processor when the power button is pressed. The power button cannot, however, turn the switch off. Instead the switch is designed so that the processor itself has to commit electronic suicide and turn its own power off by sending a signal to the switch. In the &#8216;off&#8217; state — which as you can see, isn&#8217;t really off — only the power switch circuitry uses power, and it uses very little, only 1.3mA. The main processor and anything connected to the USB ports are simply disconnected from the supply voltage. So turning the power off is easy &#8211; OpenWRT provides the <em>poweroff</em> command, which does just what it says. The question then becomes, how do we turn the power back on at regular intervals?</p>
<p><strong>A hardware modification</strong></p>
<p>The NSLU2 has an X1205 real-time clock chip that keeps the time and date. It runs continuously, even when the power supply is physically unplugged &#8211; that is its 3V battery in the middle of the board. This chip has an alarm facility; it has a pin that can be programmed to send an interrupt signal to the main processor at a specific time and date, up to a year ahead. On the NSLU2 board, this interrupt signal pin is not connected to anything. If we connect it to &#8216;on&#8217; input of the power supply switch, the X1205 can turn the NSLU2 on when the alarm time is reached. This turns out to be a fairly simple hardware mod. A wire connecting pin 3 of the X1205 to the U15 side of R94 will do the job. The wire has to run from one side of the board to the other, and requires a fine-tipped soldering iron as R94 and the X1205 are both surface mount devices. The photographs below show where it goes.</p>
<p><a href="http://johnarthur.files.wordpress.com/2008/06/rtc-mod-front.jpg"><img class="aligncenter size-full wp-image-37" src="http://johnarthur.files.wordpress.com/2008/06/rtc-mod-front.jpg?w=958" alt="RTC power switch mod, front"   /></a></p>
<p><a href="http://johnarthur.files.wordpress.com/2008/06/rtc-mod-rear.jpg"><img class="aligncenter size-full wp-image-38" src="http://johnarthur.files.wordpress.com/2008/06/rtc-mod-rear.jpg?w=958" alt="RTC power switch mod rear"   /></a></p>
<p><strong>Software changes</strong></p>
<p>Having added this wire, all we need is some software to set the alarm time and all sorts of interesting possibilities appear. The software turned out to be a little more complicated than I had expected, as it turned out that the low-level Linux driver for the X1205 wasn&#8217;t quite working properly. It didn&#8217;t correctly set the alarm values or provide a way to enable the interrupt pin. Nor, having fixed the driver, is there a standard Linux tool for setting up the alarm in the way we need. Fortunately there is a program out there called <em>rtcwake</em> that does nearly the job we want, and I was able to modify it to make a similar program I have called <em>rtcalarm</em>.</p>
<p>With <em>rtcalarm</em>, the fixed driver, and the wire in place, we can now have the NSLU2 turn on, take a single photo, and turn itself off again at any interval. Well, almost any interval. It takes a little over a minute to start up, so the smallest sensible interval would be longer than that, say 90 seconds. The longer the interval, the lower the power consumption.</p>
<p>There was one small remaining problem with this setup. When the time came to make a movie out of the contents of the flash drive, the file renaming strategy described in my earlier <a href="http://johnarthur.wordpress.com/2008/05/24/a-megapixel-time-lapse-camera-system/">post</a> on time-lapse cameras no longer worked. Now the serial number part of the filename is always 000000000, because MJPG-streamer is being restarted every time. The solution to this was to make a small change to the output_file plugin of MJPG-streamer to omit the serial number and the underscore characters separating the time fields. The file names now have the form<em> yyyyymmddmmhhss</em>.jpg. This makes converting them to movies with QuickTime Pro straightforward &#8211; no file name changes are required.</p>
<p><strong>The end result: a power-cycling time-lapse camera</strong></p>
<p>An OpenWRT firmware build with the rtcalarm tool and the driver patch, <a href="http://www.mediafire.com/?zgzvbjnwvmd">openwrt-nslu2-uvc-webcam3.bin</a> is available <a href="http://www.mediafire.com/?zgzvbjnwvmd">here</a>. It provides the same three modes as the build described in A MegaPixel Time-Lapse Camera System &#8211; webcam, dual webcam, and time-lapse. In time-lapse mode, however, it now requires the hardware mod, and takes pictures every six minutes, turning itself off for five minutes out of six.</p>
<p>The net power consumption of the new time-lapse mode is a little tricky to work out, as the camera only starts using power quite late in the boot-photograph-shutdown cycle, so the full 1100mA is only used for about ten seconds at the end. I used a data acquisition system to monitor the current draw at 5V over a single photo cycle, and it looks like this:</p>
<p><a href="http://johnarthur.files.wordpress.com/2008/06/nslu2-timelapse-no-net1.png"><img class="aligncenter size-full wp-image-40" src="http://johnarthur.files.wordpress.com/2008/06/nslu2-timelapse-no-net1.png?w=958" alt="NSLU2 power profile"   /></a></p>
<p>This shows that it takes 47.6 A/secs to take a photo, if I can be excused for employing such units. The profile above is for a unit not connected to Ethernet. With Ethernet, power use is slightly higher but the cycle runs some ten seconds shorter and uses 44.6 A/secs. At 5V thats 238W/secs per photo with no network. With these figures in hand, we can estimate how many photos we can get from a battery. For example, a 12V 7AH gel cell running the NSLU2 through my <a href="http://johnarthur.wordpress.com/2008/06/08/an-efficient-voltage-regulator/">switching voltage regulator</a> contains 12&#215;7 = 84W/hours. If the regulator is 88% efficient we get 73.9W/hours delivered to the NSLU2, which is 266112W/secs and therefore about 1118 photos. This number is largely independent of the interval between photos, because the power consumption of the NSLU2 while off is so low.</p>
<p><strong>Internal details</strong></p>
<p>This build is based on a later version of the OpenWRT trunk, revision 11566. It has a later version (r63) of the MJPG-streamer software, which has some bug fixes and should behave better when streaming to a web browser. I had to apply a patch I found <a href="http://lists.openwrt.org/pipermail/openwrt-devel/2008-June/002528.html">here</a> to the /sbin/usb-storage script to get the flash drive to mount correctly at power-on. As usual, most of the controlling code is in /etc/init.d/done. The only exception is the script at /root/whoa which sets the RTC alarm and turns the power off. If you want to change the number of seconds between pictures, edit the rtcalarm command in this script. The /root/whoa script is called by the MJPG-streamer output_file plugin via the -c option</p>
<p>The source for the rtcalarm tool can be found <a href="http://www.mediafire.com/?zibnf3jbtsf">here</a>, along with the patched rtc-x1205.c driver and the other patches.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/johnarthur.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/johnarthur.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=36&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2008/06/26/a-battery-powered-time-lapse-camera/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2008/06/rtc-mod-front.jpg" medium="image">
			<media:title type="html">RTC power switch mod, front</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2008/06/rtc-mod-rear.jpg" medium="image">
			<media:title type="html">RTC power switch mod rear</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2008/06/nslu2-timelapse-no-net1.png" medium="image">
			<media:title type="html">NSLU2 power profile</media:title>
		</media:content>
	</item>
		<item>
		<title>An Efficient Voltage Regulator</title>
		<link>http://johnarthur.wordpress.com/2008/06/08/an-efficient-voltage-regulator/</link>
		<comments>http://johnarthur.wordpress.com/2008/06/08/an-efficient-voltage-regulator/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 08:37:47 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[circuit]]></category>
		<category><![CDATA[schematic]]></category>
		<category><![CDATA[switching]]></category>
		<category><![CDATA[voltage regulator]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=26</guid>
		<description><![CDATA[Voltage regulators are circuits for converting one DC voltage to another, and these days they are pretty easy to make. There are a wide variety of integrated circuits that make the job very simple. In this case, I wanted to run the NSLU2/QuickCam combination that I have been posting about from a 12V battery. It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=26&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Voltage regulators are circuits for converting one DC voltage to another, and these days they are pretty easy to make. There are a wide variety of integrated circuits that make the job very simple. In this case, I wanted to run the NSLU2/QuickCam combination that I have been posting about from a 12V battery. It draws somewhere in the range of 600-1100mA, depending on whether or not the camera is running, so I need something that can convert an input that could be up to 15V (if the battery is being charged at the time), down to 5V, at up to 1.2A.</p>
<p><span id="more-26"></span>The simplest way of doing this is with a linear regulator IC, and a circuit like this:</p>
<p><a href="http://johnarthur.files.wordpress.com/2008/06/linear1.png"><img class="alignnone size-medium wp-image-29" src="http://johnarthur.files.wordpress.com/2008/06/linear1.png?w=300&#038;h=156" alt="" width="300" height="156" /></a></p>
<p>The LM317 is actually an adjustable regulator whose output voltage is defined by the two resistors. The values shown yield 5V. The trouble with this design is that although its very simple &#8211; five parts &#8211; there is another component required which isn&#8217;t shown. Its a substantial chunk of metal that has to be bolted to the LM317 to act as a heatsink. It needs to dissipate up to 12W. This really means buying the LM317K version of the regulator and using a heatsink rated at 2°C/W or better, which is going to be a chunk of finned aluminium at least 100mm long. This has to be mounted somewhere and ventilated, and the regulator has to be bolted to it with an insulating pad and isolating washers. The simple circuit has turned into a piece of engineering, and all because its only 42% efficient at 12V. More than half of the energy supplied is being turned into heat. If we are running from a battery this is not good news.</p>
<p>We can, however, do much better than this, by using a switching regulator IC. These used to be very tricky things to use, but modern parts have simplified the process to the point where they are relatively easy to apply. They do require some care in component selection and layout, but in return efficiencies are far higher, and no heatsink is needed. The circuit I have built is based on the National Semiconductor <a href="http://www.national.com/pf/LM/LM2672.html">LM2672</a>, and has all of nine components. It looks like this:</p>
<p><a href="http://johnarthur.files.wordpress.com/2008/06/switcher2.png"><img class="aligncenter size-full wp-image-34" src="http://johnarthur.files.wordpress.com/2008/06/switcher2.png?w=958" alt=""   /></a></p>
<p>This design is about 88% efficient at 1A: 12V at 480mA in produces 5V at 1A out. The minimum input voltage at 1A is 7V, the maximum voltage before component changes would be advisable is 15V.  The enable input can be left floating, or used to disable the regulator, if required, by pulling it down to ground. In the disabled state the regulator draws only 100μA. Enabled, but with nothing connected, the quiescent draw is 3.4mA. Again, its adjustable &#8211; the output voltage is set by R1 and R2.</p>
<p>I built this on a 46mm x 28mm piece of single-sided PCB material in about 30 minutes using a miniature electric hand tool to drill holes and rout channels on the copper side of the PCB. That was actually the easy part. The tricky bit is getting hold of the right components and putting them in the right places.</p>
<p>I think because switching regulators have had a reputation for being difficult in the past, they aren&#8217;t commonly used, so the components aren&#8217;t commonly about &#8211; so they aren&#8217;t often used, and so on. You will need to go to a larger electronics retailer to get the parts, and although none of them are particularly expensive, you will need to take care about the specifications of nearly all of them.</p>
<p>The LM2672N-ADJ is an 8-pin DIP package. Take care not to get the surface mount version, the LM2672M-ADJ, unless you like that kind of thing.</p>
<p>The 1N5822 Schottky diode is widely available in a DO27 package, but in this case you actually want the surface mount version for reasons I will explain shortly.</p>
<p>The 330μF (or more) input capacitor should be rated at 25V (or more) and at least 600mA ripple current. If the supplier doesn&#8217;t specify the ripple current, you should assume its not adequate. Good capacitors have a ripple current specification.</p>
<p>The 220μF output capacitor should be rated at 10V or more, and must be a high-frequency type with a low ESR at 100kHz. I used a Panasonic FC series part, EEUFC1A221, which manages 0.25Ω at 100kHz. The FM series are better, if you can get them.</p>
<p>C2 and C3 must be high-frequency ceramic types, preferably X7R. C2 can be more than 0.1μF, but C3 must be 0.01μF.</p>
<p>The inductor must be a type intended for use in switching power supplies, with a current rating of at least 1.4A. I used a TDK part, SLF12575T-330M3R2-PF, from RS Components. Its rated at 3.2A so was a bit of overkill and is larger than necessary. It is also surface mount which meant running a couple of wire loops through the board to solder it to, as it would have been awkward having it on the copper side.</p>
<p>The two resistors can be any 1/8W type.</p>
<p>Having got hold of the specified bits, the other critical consideration is the board layout. If this isn&#8217;t right, the regulator can be unstable in various exciting ways. Fortunately National Semiconductor have a comprehensive application note on the subject, <a href="http://www.national.com/an/AN/AN-1229.pdf">AN-1229</a>. Two components need to be as close as possible to the IC; the 0.1μF capacitor, C2, and the 1N5822 diode. The easiest way to achieve this is to mount the capacitor right beside pins 6 and 7, and the diode on the underside of the board right beside pins 6 and 8. The rest of the layout follows the National Semiconductor notes. Here is the back of the PCB before soldering, and the front after mounting the components.</p>
<p><a href="http://johnarthur.files.wordpress.com/2008/06/pcb-back-2.jpg"><img class="aligncenter size-full wp-image-32" src="http://johnarthur.files.wordpress.com/2008/06/pcb-back-2.jpg?w=958" alt=""   /></a></p>
<p>The surface-mount 1N5822 is soldered onto the back of the board, directly under the IC, bridging the horizontal channel visible in the photo.</p>
<p>I have now built a couple of these and they seem to perform very well. They are probably best suited to digital circuitry as there is about 35mV of switching noise at 240kHz on the outputs, although this could presumably be filtered pretty effectively with an LC filter if it was a problem.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/johnarthur.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/johnarthur.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=26&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2008/06/08/an-efficient-voltage-regulator/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2008/06/linear1.png?w=300" medium="image" />

		<media:content url="http://johnarthur.files.wordpress.com/2008/06/switcher2.png" medium="image" />

		<media:content url="http://johnarthur.files.wordpress.com/2008/06/pcb-back-2.jpg" medium="image" />
	</item>
		<item>
		<title>A Megapixel Time-lapse Camera System</title>
		<link>http://johnarthur.wordpress.com/2008/05/24/a-megapixel-time-lapse-camera-system/</link>
		<comments>http://johnarthur.wordpress.com/2008/05/24/a-megapixel-time-lapse-camera-system/#comments</comments>
		<pubDate>Sat, 24 May 2008 07:34:21 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[kamikaze]]></category>
		<category><![CDATA[NSLU2]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[UVC]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[time-lapse]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=22</guid>
		<description><![CDATA[Introduction The NSLU2 running OpenWRT and the QuickCam Pro 9000 combine to make a very versatile device. In this post I&#8217;m going to describe how to use them as a time-lapse camera which takes photos every ten seconds at 1600&#215;1200 resolution and stores them on a flash drive. The photos occupy anywhere from 80K to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=22&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
The NSLU2 running OpenWRT and the QuickCam Pro 9000 combine to make a very versatile device. In this post I&#8217;m going to describe how to use them as a time-lapse camera which takes photos every ten seconds at 1600&#215;1200 resolution and stores them on a flash drive. The photos occupy anywhere from 80K to 400K each depending on the complexity of the scene. This means that around 10,000 to 15,000 will fit on a 4GByte flash drive, corresponding to 20-40 hours of coverage.  All that is required is an NSLU2, a UVC-compatible webcam, a flash drive, and an OpenWRT firmware build, which is available <a href="http://www.mediafire.com/download.php?rl2ko9zdtzk">here</a>. A brief sample movie (30 seconds, 8.5Mbytes, DivX) is available <a href="http://www.mediafire.com/?5wg0tz33lm0">here</a>.</p>
<p><span id="more-22"></span><strong>A simple hardware mod</strong></p>
<p>The first step in building this arrangement is to bypass a hardware limitation of the NSLU2. As provided, only one of the two USB ports has power. If we want to attach both a webcam and a flash drive, we need both ports to supply power. The solution is a very simple hardware mod (a single jumper) which is described <a href="http://www.nslu2-linux.org/wiki/HowTo/UseTwoBusPoweredDevices">here</a>. A good description of how to open the case can be found <a href="http://www.nslu2-linux.org/wiki/HowTo/OpenTheCase">here</a>.</p>
<p><strong>Installing the firmware</strong></p>
<p>This process is described in <a href="http://johnarthur.wordpress.com/2008/03/25/a-high-resolution-ip-webcam">&#8220;A High-Resolution IP Camera&#8221;</a>, but for completeness here it is again. You will need:</p>
<ol>
<li>An NSLU2</li>
<li>A host computer, best running Linux</li>
<li>The firmware image, <a href="http://www.mediafire.com/download.php?rl2ko9zdtzk">openwrt-nslu2-uvc-webcam2.bin</a></li>
</ol>
<p>You will need to run a tool called UpSlug2 to install the firmware. UpSlug2 is described <a href="http://www.nslu2-linux.org/wiki/Main/UpSlug2" target="UpSlug2">here</a>. I would recommend running it from Linux. I used my Ubuntu machine, but booting a Knoppix Live CD on a Windows machine should work fine. Under Ubuntu, getting UpSlug2 is as simple as:</p>
<pre>apt-get install upslug2</pre>
<p>The next step is to power-up the NSLU2 in &#8220;upgrade mode&#8221;. It should be connected to the same LAN as your Linux machine, but do not plug in the camera or flash drive at this stage. Use a straightened paper clip or other thin probe inserted in the Reset hole at the back of the NSLU2. Apply gentle pressure and the reset switch will click in. Hold it down and press the power button at the front. The Ready/Status LED will come on orange, but after nine or ten seconds will turn red. Release the reset switch as soon as this happens. The Ready/Status LED should start alternating red and green, indicating that the device is ready to upgrade. Now issue the command:</p>
<pre>sudo upslug2 --image="openwrt-nslu2-uvc-webcam2.bin"</pre>
<p>If all is well and UpSlug2 can find the NSLU2 you should see a nice animated summary of the upgrade process, which will take about one minute twenty seconds. When it finishes you should wait for about two more minutes for it to perform initial setup &#8211; eventually the Disk 1 and Disk 2 LEDs should go out and the Ready/Status come on red. You can then disconnect the power, plug in the webcam and the flash drive, and power it up again. After about 60 seconds the red ring light on the camera, indicating that it is recording, should come on.</p>
<p><strong>Recording images</strong></p>
<p>Once the firmware is installed, the NSLU2 will start recording images as soon as it has started up. The recording is done with Tom Stöveken&#8217;s versatile MJPG-streamer software. MJPG-streamer is capable of writing images to external storage at regular intervals. It names each image with a rather long but unique name of the form:</p>
<p><em>year</em>-<em>month</em>-<em>day</em>-<em>hour</em>-<em>minute</em>-<em>second</em>-picture-<em>serialnum</em>.jpg</p>
<p>e.g    2008_05_11_08_38_50_picture_000000046.jpg.</p>
<p>The <em>serialnum</em> increments by 1 for each successive image. The firmware has been set up to write these files to a normal flash drive filesystem; that is, in MS-DOS or more properly FAT32 format. Its not the worlds best filesystem, but it is ubiquitous and works with almost everything. Most flash drives come formatted this way, so should work immediately. Note that the firmware does not make subdirectories; all the files are written to the top directory of the drive. There are limits to how many files can be placed in one directory like this &#8211; officially 65536 is the limit for FAT32, but I haven&#8217;t tested this and would advise caution.</p>
<p>The firmware makes use of the LEDs on the NSLU2 to describe its status. It will look at what resources are available when it starts up, and select one of the following four modes:</p>
<p>- No-camera mode. If no UVC-compatible webcam is found, the Ready/Status LED will turn red and nothing interesting will happen.</p>
<p>- IP-camera mode, where it streams the camera images to a web page. This is pretty much the same as the system described in my earlier post &#8220;A High-Resolution IP Camera&#8221;. The Ready/Status LED will be green and the Disk 1 LED will be on.</p>
<p>- Dual IP-camera mode. If it finds two cameras, it will try to stream both of them to two separate web pages. The second web page is at the same address as the first, but on port 8080. The Ready/Status LED will be green and both the Disk 1 and Disk 2 LED will come on. I haven&#8217;t actually tested this as I only have one camera.</p>
<p>- Time-lapse camera mode, which is the main subject of this post. In this case no web page will be available and the NSLU2 will start storing images on the flash drive every ten seconds. The Ready/Status LED will be green, the Disk 2 LED will come on, and you should see activity every ten seconds on the flash drive&#8217;s LED (if it has one).</p>
<p>The Ethernet LED will, in all modes, as usual,  indicate whether or not the NSLU2 is connected to a LAN. In time-lapse camera mode the NSLU2 does not need to be connected to a LAN and can operate independently.</p>
<p>Time-lapse camera mode runs at the full 1600&#215;1200 resolution of the camera, which is possible because we are only processing an image every ten seconds. The NSLU2 can&#8217;t cope with these images at much speed (see <a href="http://johnarthur.wordpress.com/2008/03/29/further-notes-on-the-nslu2-and-quickcam-pro-9000/">this post</a> for a discussion of why). The disadvantage of the high resolution is that it can&#8217;t do a web page as well. MJPG-streamer is quite capable of doing both, but the resolution has to be reduced to 960 x 720 in JPEG mode, and as I expect the time-lapse mode to be used for unattended long-term recording, I have adopted the higher resolution.</p>
<p><strong>Trouble at mill; filling up the disk<br />
</strong></p>
<p>It would be nice to be able to delete the oldest images once the flash drive filled up, so that the camera could run continuously and keep only the new images. This turns out to be difficult to do. With 10,000 files on the drive, the &#8216;ls&#8217; command that would find the oldest becomes glacially slow, taking over twenty minutes to complete. It also risks crashing the NSLU2. Instead, I have installed a script that checks for a nearly-full drive and issues the &#8216;poweroff&#8217; command when there is only 15Mbytes free.</p>
<p><strong>Viewing the images</strong></p>
<p>A flash drive with 13,859 JPEGs on it is not actually a very usable thing. Even though the images are labelled with dates and times, looking through them is tedious at best. A much better way of reviewing them is to turn them into a movie. I spent some time looking for the best way to do this, and in the end discovered that Apple&#8217;s <a href="http://www.apple.com/quicktime/pro/">QuickTime Pro</a> software has an &#8220;Open Image Sequence&#8230;&#8221; command that does a very good job of it indeed. Its also a good tool for viewing, single-stepping, rewinding, editing and generally working with time-lapse movies, and I can recommend it as worth the money (US$30). The only piece of trickery required is that QuickTime Pro expects to be pointed at the first file of a series of files with numerical sequence numbers for names, and the date prefixed onto the file names by MJPG-streamer confuses it. This is best dealt with by applying a shell script to strip off the date prefix. Writing one that runs at a reasonable speed and can cope with 20,000 files in one directory turned out to be a little tricky, but eventually I found the powerful incantation:</p>
<pre>find . -name '*.jpg' -print | sed 's/.*_picture_\(.*\).jpg$/mv "&amp;" "\1.jpg"/' | sh</pre>
<p>This can strip paint off bargeboards at twenty metres and will convert about 12,000 filenames a minute on my Mac Mini. For ease of use under Mac OS X I have packaged it up into an AppleScript application that will convert folders of files that are dropped onto it. It is available <a href="http://www.mediafire.com/download.php?ynkmj0hmgyn">here</a>. Be warned that if there are multiple sequences in the folder (i.e more than one file that ends with 0000001.jpg) the earlier ones will be overwritten. Quicktime Pro also seems to object to the zero-size .jpg files that the recording process sometimes leaves at the end &#8211; you should remove these manually. To strip date prefixes under Windows, I am advised that the Cygwin environment will probably support the incantation above.</p>
<p><strong>Internal details and making changes</strong></p>
<p>openwrt-nslu2-uvc-webcam2.bin is a normal build of a selection of packages from OpenWRT Kamikaze taken from the current &#8216;trunk&#8217;, with a couple of simple shell scripts added. The main script can be found in /etc/init.d/done. Checking for &#8220;disk full&#8221; is done by a second script which can be found in /root/stopwhenfull, and the cron entry that runs it every three minutes is added to /etc/crontabs/root by the &#8216;done&#8217; script. A copy of the two scripts and a list of the packages in use can be found <a href="http://johnarthur.wordpress.com/sources/time-lapse-camera-details/">here</a>. You can telnet directly into the OpenWRT shell, which has no password. You should set a password and use ssh thereafter.</p>
<p>Many things can be changed if you log in and edit the scripts. The time between images is controlled by the -d parameter to mjpg_streamer (in milliseconds). I wouldn&#8217;t advise setting it to less than five seconds at 1600&#215;1200 on the Pro 9000, as the NSLU2 is likely to crash.  Image size is controlled by the -r parameter and image type by -y. The stopwhenfull script assumes that you won&#8217;t generate more than 5Mbytes/minute and should be adjusted if this is not the case.</p>
<p>The firmware does not have to write to a flash drive, but is not likely to work with a USB hard drive as they are usually formatted with NTFS or somesuch, which it does not understand. It does understand the Linux ext3 filesystem, though, which might be more suitable for larger applications anyway, as it doesn&#8217;t seem to have a limit to the number of files that can be in one directory.</p>
<p>The firmware includes an NTP client which will try to keep accurate time if the NSLU2 can find Internet access. As provided it will keep UTC time. If you aren&#8217;t in the Greenwich time zone you will need to add an appropriate /etc/TZ file for your timezone taken from <a href="http://wiki.openwrt.org/OpenWrtDocs/Configuration#head-a7708420e79025405daa939605108397c2bd7343">here</a>.</p>
<p>I have experimented with Samba and vsftpd with the idea of being able to look at the images on the flash drive as they are recorded over the LAN connection. Performance in both cases turns out to be somewhere between glacial and completely fossilised if there are very many files on the disk. I have left vsftpd in as it can be useful for checking that the images are OK just after startup, but I can&#8217;t recommend using it once there are more than a few hundred images. To use vsftpd you will need to login over telnet and set a root password, then use that password and the username &#8216;root&#8217; to gain access over ftp. The firmware uses DHCP to obtain an IP address, as described in &#8220;A High-Resolution IP Camera&#8221;.</p>
<p><strong>Limitations and improvements</strong></p>
<p>The firmware as it stands has a few deficiencies which I would like to address.</p>
<p>- There is no way of turning the NSLU2 off, which would be a good idea, as its not really very nice to just unplug the flash drive as it runs. With any luck OpenWRT will someday get the power button working as an off switch.</p>
<p>- The focus controls on the QuickCam aren&#8217;t accessible in time-lapse mode. The camera can actually focus down to a few centimetres and it would be useful for studying very small slow things if the focus was available.</p>
<p>- A simple web page that at least gave a static image would be handy in time-lapse mode for checking the field of view.</p>
<p>- A better way of storing files than the present single directory would be nice, and the best way to do it would be to modify MJPG-streamer.</p>
<p>- Battery-driven operation is possible but a bit demanding; the combination of the NSLU2, the Quickcam Pro 9000, and a 4GByte flash drive draws 900-1100 mA at 5V while recording, which is rather a lot for batteries. I want to look into reducing this for remote recording applications.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/johnarthur.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/johnarthur.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=22&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2008/05/24/a-megapixel-time-lapse-camera-system/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>
	</item>
		<item>
		<title>Further notes on the NSLU2 and QuickCam Pro 9000</title>
		<link>http://johnarthur.wordpress.com/2008/03/29/further-notes-on-the-nslu2-and-quickcam-pro-9000/</link>
		<comments>http://johnarthur.wordpress.com/2008/03/29/further-notes-on-the-nslu2-and-quickcam-pro-9000/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 06:48:36 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[kamikaze]]></category>
		<category><![CDATA[NSLU2]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[UVC]]></category>
		<category><![CDATA[quickcam]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=21</guid>
		<description><![CDATA[I have been playing around with the webcam firmware that was the subject of my last post and have a number of random notes that I should put up here on using it. Power-on and Power off The NSLU2 running OpenWRT has some odd characteristics. First, it will not automatically turn on when power is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=21&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with the webcam firmware that was the subject of my last post and have a number of random notes that I should put up here on using it.<span id="more-21"></span></p>
<p><strong>Power-on and Power off</strong><br />
The NSLU2 running OpenWRT has some odd characteristics. First, it will not automatically turn on when power is applied, and you can&#8217;t make it do so without modifying the hardware (see <a href="http://www.nslu2-linux.org/wiki/HowTo/ForcePowerAlwaysOn" target="_blank">here</a> for a lengthy discussion of how to do so). You have to press the power-on button to get it to start up. Thats true of the NSLU2 generally and not OpenWRTs fault.  Second, under OpenWRT, pressing the power button again won&#8217;t turn it off. Thats something that isn&#8217;t implemented, yet, in OpenWRT. Pressing the reset button will turn it off, but thats kind of awkward. Logging in (see below) and issuing the &#8220;poweroff&#8221; command will do so too.<br />
I&#8217;m looking into ways of reducing the boot time from the present 55 seconds from power-on to first image, but I don&#8217;t expect to get it down to less than 30 seconds.</p>
<p><strong>Resolution</strong><br />
In my first post I skated lightly over the question of why the QuickCam is running at 960&#215;720 if its supposed to be capable of doing 1600&#215;1200. The answer turns out to be a bit complicated. The QuickCam can generate images in two formats, an uncompressed one known as YUY2, and a compressed form, M-JPEG. Compressing the images is quite hard work for the camera, and at the maximum resolution it simply can&#8217;t do it, either because it takes too long or it doesn&#8217;t have enough onboard RAM. And the difference in size between the compressed and uncompressed images is pretty huge, as you can see in the following table. These are all the available image formats &gt;= 640&#215;480 for the Pro 9000:</p>
<table border="1">
<tbody>
<tr>
<th>Resolution</th>
<th>Format</th>
<th>Frames/second</th>
<th>Kbytes/frame</th>
<th>Kbytes/second</th>
</tr>
<tr>
<td>1600&#215;1200</td>
<td>YUY2</td>
<td>5</td>
<td>3840</td>
<td>19,200</td>
</tr>
<tr>
<td>960&#215;720</td>
<td>YUY2</td>
<td>10</td>
<td>1382</td>
<td>13,820</td>
</tr>
<tr>
<td>800&#215;600</td>
<td>YUY2</td>
<td>25</td>
<td>480</td>
<td>12,000</td>
</tr>
<tr>
<td>640&#215;480</td>
<td>YUY2</td>
<td>30</td>
<td>614</td>
<td>18,432</td>
</tr>
<tr>
<td>960&#215;720</td>
<td>MJPEG</td>
<td>15</td>
<td>~85</td>
<td>1275</td>
</tr>
<tr>
<td>800&#215;600</td>
<td>MJPEG</td>
<td>30</td>
<td>~85</td>
<td>2550</td>
</tr>
<tr>
<td>640&#215;480</td>
<td>MJPEG</td>
<td>30</td>
<td>~85</td>
<td>2550</td>
</tr>
</tbody>
</table>
<p>The problem with the YUY2 format is that its simply huge and generates 12-20 Mbytes/second. We can&#8217;t move this over 100Mbit Ethernet, which will do 10-12 MBytes/second, tops. Even if we did, browsers don&#8217;t understand it. It is possible to ask MJPG-streamer to read YUY2 and do the compression to MJPEG itself, but its hard work for the NSLU2 as well. At 1600&#215;1200 it generates one image about every five seconds and seems to buffer about six images, so what you see is thirty seconds in the past. It also falls over with segmentation faults fairly frequently (less frequently with lower quality images). So full resolution is pretty much limited to snapshots (another subject I want to get into). The 960&#215;720 JPEGs direct from the camera are pretty heavily compressed and the quality of the picture does suffer a bit. Less severe compression doesn&#8217;t seem to be available from the camera, but I&#8217;m hoping I can find a way of getting it.</p>
<p><strong>Autofocus</strong><br />
The Pro 9000 has a variable focus control. This is unusual on webcams, and allows it to focus on objects as little as 4-5 cm away. The MJPG-streamer software has an option that automates focusing, but having experimented with it I have not activated it in the firmware build. The reason for this is that the default focus seems to manage perfectly well between about 30cm and infinity, and the auto-focus is a bit painful to watch. It operates by checking the sharpness of the picture every ten seconds or so. If the sharpness deteriorates, it triggers a procedure that runs through the whole range of focus settings, and then picks the sharpest one. This works, but it can take at least ten seconds, and is easily fooled by movement. Unless you need this facility, its probably best left turned off.</p>
<p>Note that the manual focus controls in MJPG-streamer work just fine and let you focus down to a few centimeters.</p>
<p><strong>Modifying the camera</strong></p>
<p>If you want to know how to take the Pro 9000 apart, mount it in a box, and do things like attach a large lens to it you can photograph, say, craters on the moon, look no further than <a href="http://ghonis2.ho8.com/Pro9000a.html">here</a></p>
<p><strong>Low-level firmware access</strong><br />
If you have some Linux experience and want to get in and add packages or change settings, you can telnet into the firmware and edit the configuration files with <em>vi</em>. The firmware will advise you to set a secure root password, and thereafter you will need to log in using ssh and that password (this is, incidentally, <em>essential</em> if you are going to make the camera visible to the Internet at all). To switch to a static IP at 192.168.1.2, for example, you would edit  /etc/config/network and change the line</p>
<pre>	option proto dhcp</pre>
<p>to</p>
<pre>	option proto    static

        option ipaddr   192.168.1.2

        option netmask  255.255.255.0</pre>
<p>The startup commands that run MJPG-streamer are in /etc/init.d/done. MJPG-streamer takes the following parameters:</p>
<p>-i | &#8211;input &#8220;&lt; input-plugin.so &gt; [parameters]&#8220;<br />
-o | &#8211;output &#8220;&lt; output-plugin.so &gt; [parameters]&#8220;<br />
[-h | --help ]&#8230;&#8230;..: display this help<br />
[-v | --version ]&#8230;..: display version information<br />
[-b | --background]&#8230;: fork to the background, daemon mode</p>
<p>The UVC input plugin, <em>input_uvc.so</em>, takes these parameters:</p>
<p>[-d | --device ]&#8230;&#8230;.: video device to open (your camera)<br />
[-r | --resolution ]&#8230;: the resolution of the video device, can be one of the following strings:<br />
QSIF QCIF CGA QVGA CIF VGA SVGA XGA SXGA<br />
or a custom value like 640&#215;480<br />
[-f | --fps ]&#8230;&#8230;&#8230;.: frames per second<br />
[-y | --yuv ]&#8230;&#8230;&#8230;.: enable YUYV format and disable MJPEG mode<br />
[-q | --quality ]&#8230;&#8230;: JPEG compression quality in percent (activates YUYV format, disables MJPEG)<br />
[-m | --minimum_size ].: drop frames smaller then this limit, useful if the webcam produces small-sized garbage frames which may happen under low light conditions<br />
[-n | --no_dynctrl ]&#8230;: do not initialise dynctrls of Linux-UVC driver</p>
<p>The output HTTP plugin, <em>output_http.so</em>, takes these parameters:</p>
<p>[-w | --www ]&#8230;&#8230;&#8230;..: folder that contains webpages in a flat hierarchy (no subfolders)<br />
[-p | --port ]&#8230;&#8230;&#8230;.: TCP port for this HTTP server<br />
[-c | --credentials ]&#8230;: ask for &#8220;username:password&#8221; on connect<br />
[-n | --nocommands ]&#8230;.: disable execution of commands</p>
<p>The file output plugin, <em>output_file.so</em>, takes:</p>
<p>[-f | --folder ]&#8230;&#8230;..: folder to save pictures<br />
[-d | --delay ]&#8230;&#8230;&#8230;: delay after saving pictures in ms<br />
[-b | --bytes ]&#8230;&#8230;&#8230;: save only on change in picture-size<br />
[-c | --command ]&#8230;&#8230;.: execute command after saving picture</p>
<p>And the autofocus output plugin, <em>output_autofocus.so</em> takes just</p>
<p>[-d | --delay ]&#8230;&#8230;&#8230;: delay after saving pictures in ms</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/johnarthur.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/johnarthur.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=21&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2008/03/29/further-notes-on-the-nslu2-and-quickcam-pro-9000/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>
	</item>
		<item>
		<title>A High-Resolution IP Webcam</title>
		<link>http://johnarthur.wordpress.com/2008/03/25/a-high-resolution-ip-webcam/</link>
		<comments>http://johnarthur.wordpress.com/2008/03/25/a-high-resolution-ip-webcam/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 00:31:42 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[kamikaze]]></category>
		<category><![CDATA[NSLU2]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[UVC]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=18</guid>
		<description><![CDATA[Web cams are fairly ubiquitous things these days and by no means expensive. They can be good or bad depending on how much money you want to spend, but there is one almost-universal rule, which is that they connect to a host PC over USB. IP-based cameras that connect to a LAN via an RJ45 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=18&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Web cams are fairly ubiquitous things these days and by no means expensive. They can be good or bad depending on how much money you want to spend, but there is one almost-universal rule, which is that they connect to a host PC over USB. IP-based cameras that connect to a LAN via an RJ45 connector or wirelessly over 802.11 are quite a bit more useful, because they can be put almost anywhere, but they tend to cost a surprising amount and not provide much resolution. A low-end one like the LevelOne FCS1030 is NZ$260, and they go a lot more expensive than that. For example, the wireless D-Link DCS5300 sells for NZ$930 and it only does 320&#215;240 pixels.<span id="more-18"></span></p>
<p>After all, IP cameras have a processor in them, and do web serving, and that&#8230; well, that really isn&#8217;t a reason for them to be expensive. Some sort of premium seems to go on anything connected with the security industry.</p>
<p>As an illustration of this, the Linksys NSLU2 is a little network storage controller which does web and file serving. It sells here for about NZ$145. Its a complete computer with a 266MHz RISC CPU, 8M of flash and 32M of RAM, two USB ports, and an RJ-45 connector. Not much by todays standards, but not very many years ago those would have been respectable specs for a desktop. It runs off a 5V plugpack. The really interesting thing about it is that the open source community has developed something like five alternative firmware distributions for it which are very capable, and can do almost anything that the hardware will allow. Including acting as a camera server for an attached webcam.</p>
<p>Webcams have also made some interesting strides forward recently. A number of new webcams with true resolutions greater than 1 megapixel have appeared, and a standard for USB web cameras has finally been agreed on. This standard, known as the USB Video Class or UVC, means that newer webcams no longer require proprietary drivers but will work with a generic UVC driver. The Logitech Quickcam Pro 9000 is a good example of a UVC camera, capable of up to 1600&#215;1200 pixels complete with optics to match. It sells here for about NZ$128.</p>
<p>I have been working on combining these two devices with one of the open-source firmwares that has the rather disconcerting name of OpenWRT Kamikaze. Despite the name it has proved to be quite reliable and full-featured, although not terribly well documented, as it is constantly being worked on and improved. Recently it has got to the point where it can easily make the NSLU2 and the QuickCam 9000 work together to make a high-resolution IP camera server, for a total of NZ$275. As it stands the combination is only suitable for indoor use, and it has some limitations, but it still produces a very good image for the money and it works with any web browser &#8212; or with my Linux-based ZoneMinder security camera software. If you want indoor high-resolution imaging over a LAN, this could be quite useful. Compiling OpenWRT and selecting the necessary bits is a bit involved and can take a few hours, so I am making the end product, a firmware build called openwrt-nslu2-uvc-webcam1.bin, available <a href="http://www.mediafire.com/?zkn1bglgmid" target="_blank">here</a>.</p>
<p>To use it yourself you will need:</p>
<ol>
<li>An NSLU2</li>
<li>A UVC-compatible webcam such as the QuickCam 9000</li>
<li>A host computer running Linux</li>
<li>The firmware image</li>
<li>Access to a DHCP server on your LAN</li>
</ol>
<p>Installing the replacement firmware on the NSLU2 is a Bit Technical, but not difficult. You will need to run a tool called UpSlug2 to install the firmware. UpSlug2 is described <a href="http://www.nslu2-linux.org/wiki/Main/UpSlug2" target="UpSlug2">here</a>. I would recommend running it from Linux. I used my Ubuntu machine, but booting a Knoppix Live CD on a Windows machine should work fine. UpSlug2 can also be used directly under Mac OS X: see <a href="http://www.nslu2-linux.org/wiki/Main/UpSlug2onOSX">here</a>. Under Ubuntu, getting UpSlug2 is as simple as</p>
<pre>apt-get install upslug2</pre>
<p>The next step is to power-up the NSLU2 in &#8220;upgrade mode&#8221;. It should be connected to the same LAN as your Linux machine, but do not plug the camera in at this stage. Use a straightened paper clip or other thin probe inserted in the Reset hole at the back of the NSLU2. Apply gentle pressure and the reset switch will click in. Hold it down and press the power button at the front. The Ready/Status LED will come on orange, but after nine or ten seconds will turn red. Release the reset switch as soon as this happens. The Ready/Status LED should start alternating red and green, indicating that the device is ready to upgrade. Now issue the command:</p>
<pre>sudo upslug2 --image="openwrt-nslu2-uvc-webcam1.bin"</pre>
<p>If all is well and UpSlug2 can find the NSLU2 you should see a nice animated summary of the upgrade process, which will take about one minute twenty seconds. When it finishes you should wait for three more minutes for it to perform initial setup. You can then disconnect the power, plug in the USB webcam (to the USB port nearest the LAN socket &#8211; the other one isn&#8217;t powered), and power it up again. After about 55 seconds the red ring light on the camera indicating that it is recording should come on.</p>
<p>The firmware has been set to use DHCP to dynamically determine its IP address. This has the advantage of working in almost all network setups, but it does mean that you will need access to the DHCP server log on your local LAN to find out what IP address it has been given. The logs should show a DHCP discover/offer/request/ack sequence at the time the NSLU2 powers up, which will tell you what IP address it was given.</p>
<p>The log will also give its Ethernet or MAC address (which is on a label on the outside of the box as well, if you still have it). If you have access to the DHCP servers configuration files, you can tell the DHCP server to give the NSLU2 with that Ethernet address a consistent IP address at which it can always be found.</p>
<p>Once you have the IP address, use any web browser to go to http://&lt;IP address&gt; (e.g http://192.168.10.154) and you will find an About page for the M-JPEG streamer software, offering various forms of static or moving images from the webcam, which is running at a resolution of 960&#215;720. For an unadorned single frame, try http://&lt;IP address&gt;/?action=snapshot.</p>
<p>A sample image looks like <a href="http://johnarthur.files.wordpress.com/2008/03/x2.jpeg">this</a></p>
<p>Which is not bad for a webcam at all. A bit fuzzy around the edges, but resolution in the middle is fine. Your cat may look different.</p>
<p>This firmware should work with any UVC-compatible webcam, which includes a number of models from Logitech, Creative, Philips, and other manufacturers. A list of compatible ones can be found <a href="http://linux-uvc.berlios.de/" target="_blank">here</a> [Warning; the Microsoft Lifecam NX-6000 is listed, but I am told it doesn't work]. The firmware will not work on anything other than an NSLU2. I intend in due course to describe how to build the firmware in another post, but I had to build the &#8220;trunk&#8221; version to do this and I&#8217;m hoping that a formal release of OpenWRT that supports the mjpg-streamer package that makes this possible will come out and make the whole process much easier.</p>
<p>The NSLU2/QuickCam combination is a powerful one that could obviously be used for a good deal more than a simple image server. The NSLU2 isn&#8217;t powerful enough to run anything like the ZoneMinder software except at low resolutions, but it could still be used as a stand-alone remote survey camera with a few additions. I also intend to post about this in the future.</p>
<p>I won&#8217;t actually be using this camera with my ZoneMinder setup because it is a bit too demanding. IP cameras require more CPU cycles from ZoneMinder than directly-connected cameras, because ZoneMinder has to decode the JPEG format that the images are sent over the network in. My 1.2GHz Pentium III can only just manage 4 frames a second from this camera at 640&#215;480 with not enough margin to handle another camera. I would guess that if you wanted to use several of these with a ZoneMinder setup nothing short of a 2.5GHz dual-core CPU would be enough.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/johnarthur.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/johnarthur.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=18&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2008/03/25/a-high-resolution-ip-webcam/feed/</wfw:commentRss>
		<slash:comments>111</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>
	</item>
		<item>
		<title>A Proportional 12V Fan Controller</title>
		<link>http://johnarthur.wordpress.com/2008/03/09/a-proportional-12v-fan-controller/</link>
		<comments>http://johnarthur.wordpress.com/2008/03/09/a-proportional-12v-fan-controller/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 07:27:29 +0000</pubDate>
		<dc:creator>michaelhamel</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Microprocessors]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[circuit]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[fan]]></category>
		<category><![CDATA[htpc]]></category>
		<category><![CDATA[schematic]]></category>

		<guid isPermaLink="false">http://johnarthur.wordpress.com/?p=13</guid>
		<description><![CDATA[The Ubuntu machine covered in my previous post lives in a cupboard with a wireless router and a DSL modem. Its not a very big cupboard, and&#8230; it gets rather warm in there. Even though the computer doesn&#8217;t use a lot of power, the heat doesn&#8217;t have anywhere much to go. Thats not good for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=13&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The Ubuntu machine covered in my previous post lives in a cupboard with a wireless router and a DSL modem. Its not a very big cupboard, and&#8230; it gets rather warm in there. Even though the computer doesn&#8217;t use a lot of power, the heat doesn&#8217;t have anywhere much to go. Thats not good for longevity or reliability. I made a couple of 100mm diameter vents of the kind you use to vent clothes dryers, high and low, from the back of the cupboard into an adjacent storage room, but convection just didn&#8217;t seem to be doing enough, especially on warm days.</p>
<p>The answer was, of course, to add a fan. <span id="more-13"></span>The PC can provide 12V power, and a standard 92mm PC case fan will fit nicely into the upper vent. Sort of an out-of-case fan. The only disadvantage is the sound of the fan running all the time. And the solution to that is a fan controller, preferably a proportional one which would run the fan only as fast as it needed to to stop the air in the cupboard exceeding some reasonable temperature. It is perhaps a bit of overkill for this particular location, but the design could be useful in other places as well, like an HTPC.</p>
<p>Fan controllers aren&#8217;t difficult to come by, but they seem to me to be surprisingly expensive for what they are. Proportional controllers used to be quite complicated things before microprocessors came along, but now the necessary algorithm can be coded into something very small indeed. I already had an appropriate part, the PIC12F675. This is an 8-pin chip that has a complete processor, 64 bytes of RAM, 1K of flash memory, and an A/D converter. Its one disadvantage is that it has to be programmed in assembler, but I have some experience with the PIC family and this application is simple enough it was worth putting up with assembly language to get the job done. I also had a temperature sensor, the LM34. It puts out 10mV per degree F, which the PIC can read directly to an accuracy of about half a degree F. More than good enough.</p>
<p>Now, the 12F675 may have an A/D to read the temperature with, but it doesn&#8217;t have a D/A converter to generate a voltage to drive the fan with. We can make a virtue of this, though. Fans and motors &#8211; and the circuitry that drives them &#8211; work more efficiently if driven with pulses of power rather than continuous voltages. To increase the speed of the fan, we generate more pulses, or make the pulses wider. This technique, called pulse-width modulation (PWM) is very widely used. The 12F675 can generate pulses just fine, so we drive a small power MOSFET with one pin and we are done.</p>
<p>So my first circuit could hardly have been much simpler, and looked like this:<a href="http://johnarthur.files.wordpress.com/2008/03/fancontroller1.png" title="First Fan Controller Circuit"><img src="http://johnarthur.files.wordpress.com/2008/03/fancontroller1.png?w=958" alt="First Fan Controller Circuit" /></a></p>
<p>The three-pin standard PC fan connectors at the input and output carry a speed signal back to the PC, which can be useful if it lets you monitor the fans.</p>
<p>This design certainly works, and controls temperature, and uses very few components, but unfortunately &#8212; it isn&#8217;t very quiet. The pulses that drive the fan are generated at a frequency of 2kHz and below, which is in the audio range. The fan motor resonates with the pulses and makes various high-pitched squealing sounds. This isn&#8217;t very restful.</p>
<p>The solution is to add another component or two to turn the pulses into a linear drive. What I ended up with was this:</p>
<p><a href="http://johnarthur.files.wordpress.com/2008/03/fancontroller2.png" title="Fan Controller Second Circuit"><img src="http://johnarthur.files.wordpress.com/2008/03/fancontroller2.png?w=958" alt="Fan Controller Second Circuit" /></a></p>
<p>Here the 10K resistor and 1uF capacitor act as an integrator that converts the pulse train into a continuous voltage over the range 0-5V. The op amp and the power transistor convert the 0-5V into 0-12V and provide enough power to drive the fan. The 22uF capacitor across the output stabilises things, and we get a nice continuous voltage range. This isn&#8217;t as efficient &#8212; but its much quieter. I have also added some LEDs attached to the spare I/O pins for debugging. These tell me if the fan is meant to be off (green) or full on (red), plus a yellow one that just blinks to show that the CPU is actually working.</p>
<p>The code that runs all this was assembled with the free MicroChip MPLAB system, and can be found <a href="http://johnarthur.wordpress.com/sources/proportional-fan-source/">here.</a>  The code is best considered in two parts, the PWM generator and the temperature-to-speed code. They communicate only through the Speed variable but are otherwise quite separate.</p>
<p>The PWM generator is interrupt-driven at a fixed rate of about 3900Hz. The frequency isn&#8217;t critical and happens to be what the Timer0 hardware in the PIC can easily generate. The generator makes use of a clever idea that appears in quite a few algorithms, which is to focus not on calculating an ideal result, but on tracking the error created by its approximation of that result. Here we want to convert the Speed value, which is between 0 and 127, into a stream of pulses where the density of high pulses runs from 0/127 (no pulses) to 127/127 (always on). Instead of trying to work out patterns of 1&#8242;s and 0&#8242;s to generate the required density, the code simply accumulates an error value. The error represents the difference between the Speed value (which it can&#8217;t generate) and the actual 0 or 127 that it can generate by doing or not doing a pulse. At each interrupt, it looks at the error and decides to generate a pulse if it is negative and no pulse if it is positive. It then updates the error to reflect what it has done, by adding the difference between the generated value and Speed. If it did a pulse it adds 127-Speed, and if there was no pulse it adds 0-Speed &#8211; or in other words, subtracts Speed.</p>
<p>The temperature-to-speed code uses the same idea. It runs much less frequently &#8211; the temperature can&#8217;t be expected to change very quickly. It also uses 16-bit values and arithmetic so it can cope with the 10-bit A/D conversion result. It determines the difference between the actual and target temperatures and adds it to an accumulated error value. When the error value reaches a positive threshold it increments the fan speed and subtracts the threshold from the error. If the error goes below a negative threshold it decrements the fan speed and adds the threshold to the error. By adjusting the threshold and the frequency at which the code runs it is easy to make the fan react appropriately slowly.</p>
<p>The calculated speed is limited to a suitable range by checking it against a minimum value before decrementing and a maximum value before incrementing, which is where things get slightly more complicated. It would be nice to run the fan through 128 speed steps from stopped to full speed, but real fans won&#8217;t do that. Real fans have a minimum voltage that they will spin at. For 12V case fans it is usually around 5V, but you should check your fan specifications. Below the minimum voltage, the fan will stall, and sit there heating up and possibly damaging itself. The code deals with this by separating the calculated fan speed, FSpeed, from the actual fan speed, Speed. The calculated FSpeed is incremented and decremented over the range kMinSpeed to kMaxSpeed, and Speed is an exact copy of it &#8212; except when FSpeed equals kMinSpeed. Then we set Speed to zero, and the fan stops. A further detail is that the code makes sure that the fan starts when FSpeed goes from stopped to kMinSpeed+1 by actually setting Speed to a higher value, defined in kStartSpeed, for one time interval before falling back to kMinSpeed+1.</p>
<p>This design and code should be adaptable to a wide range of different parts. Any temperature sensor should work with it with a few adjustments. The power transistor isn&#8217;t critical; the TIP 127 is actually a Darlington, but it doesn&#8217;t need to be. A BD140 would be fine. I put a small heatsink on it, but I&#8217;m not sure its necessary unless the fan is running slowly in a hot environment, which shouldn&#8217;t happen.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/johnarthur.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/johnarthur.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnarthur.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnarthur.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnarthur.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnarthur.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnarthur.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnarthur.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnarthur.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnarthur.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnarthur.wordpress.com&amp;blog=2584163&amp;post=13&amp;subd=johnarthur&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnarthur.wordpress.com/2008/03/09/a-proportional-12v-fan-controller/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3bb025d12c44b1ebedf6062a1f65bc3a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnarthur</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2008/03/fancontroller1.png" medium="image">
			<media:title type="html">First Fan Controller Circuit</media:title>
		</media:content>

		<media:content url="http://johnarthur.files.wordpress.com/2008/03/fancontroller2.png" medium="image">
			<media:title type="html">Fan Controller Second Circuit</media:title>
		</media:content>
	</item>
	</channel>
</rss>
