A couple weeks ago, woot was selling these network cameras (Hawking Technology HNC210, not that you care, but to help google find this page). This is something I have always wanted to play with. The difference between these and a normal web-cam is that these don't plug into your computer; they run their own HTTP server and plug in to the network directly. They were $40, and I decided why buy one when I could have two at twice the price.
As always when your computer world is as weird as mine, there was a healthy chance that these things would not be usable at all. There's never any way to know, except to look for some random forum post where somebody has bought one and tells you how it actually works. (That's what this is.)
So first thing, throw away the Windows setup CD which is worthless to you. The manual is helpful, though, because you can figure out from the screenshots that this thing boots up with a hard coded IP address of 192.168.2.3. All you need to do to talk to it is to ifconfig yourself an IP in the same network:
mikey@ember:~$ ifconfig eth0 inet 192.168.2.1 netmask 255.255.255.0 mikey@ember:~$ ping -c 1 192.168.2.3 PING 192.168.2.3 (192.168.2.3) 56(84) bytes of data. 64 bytes from 192.168.2.3 (192.168.2.3): icmp_seq=1 ttl=64 time=0.701 ms --- 192.168.2.3 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.701/0.701/0.701/0.000 ms
Ok, now that you can see it, just go to http://192.168.2.3 in a browser and you should get in (username admin, password 1234). Click Network Settings and you can set it to whatever you need to make it get along on your network. In my case, and probably yours, I just wanted to enable DHCP. Note that as soon as you click the Apply button, the thing is going to reboot with no warning and come back on a different IP, so it is going to look like it disappeared in your browser. Not the greatest user experience; you'll just have to find it again on its new IP.
If you brick it somehow, there is a hardware reset button on the device that should put it back on 192.168.2.3. All in all, not an unreasonable way for this kind of embedded device to work. You might wish DHCP was the default, but that can be a major pain if you don't have DHCP, or can't control it in your environment for some reason.
Using the little built in web interface, you can also see the live images from the camera if you have a working java plugin. That's not very useful, so the next question is how to pull images from it. Some tcpdump, easily confirmed with some google searches, reveals that this thing is speaking a weird but simple protocol on port 4321: Open a socket, send the ASCII characters "0110", and get back 2 bytes which are a 16 bit big-endian int, telling you how many bytes to expect. Immediately after that, you will get the promised number of bytes, which are a finished JPEG. That's it. If you want "video," you can say 0110 again and get another JPEG, as fast as you want. That's all the Java "video" viewer is doing.
Knowing how to get JPEGs out (a process that completely ignores the little password check built in to the web interface, by the way), you can now make it do whatever you want. I found a ruby script by a guy named Tim Haynes which knows how to unpack the data, and modified it (ham-fistedly, since I don't know ruby at all) to work as a CGI. The script is right here.
All that's left is to hook up the CGI to a web server somewhere. I used an Apache that I already had locally, and gave it another VirtualHost that binds a normal-looking URL to my cheesy CGI:
<VirtualHost 192.168.47.2:80> ServerName cams.singingtree.com ServerAdmin mikey@singingtree.com DocumentRoot /var/www/proxy ScriptAlias /cam1.jpg /var/www/proxy/cam.cgi ErrorLog /var/log/apache2/webcams.error.log LogLevel warn # Logging every GET creates a lot of crap when you are running # javascript loops that reload the image N times per second.. #CustomLog /var/log/apache2/webcams.access.log combined </VirtualHost>
That's it. If the whole Rube Goldberg apparatus is working, you can now put the camera URL in an img tag anywhere you want. Gentlemen, behold!
11 Feb 2007 23:45 PT - persistent link - trackback - 0 comments

4171622

