I blogged briefly about building a security camera back in a previous post. It worked so well I decided to build another, but with a few improvements based on past experience…
I used this WiFi adapter (from Aazon): TRENDnet Wireless N 150 Mbps Mini USB 2.0 Adapter, TEW-649UB. It’s supported out-of-the box by th OS, PLUS, you can easily pop open the housing and their a standard (tiny) wifi antenna connector on the circuit board. This let by connect a full, external antenna I had from dismantling and old router or something.
And finally, I added the startup to /etc/rc.local so that the service will start up automatically when the system starts:
A note about power: The IR led array and fan take 12v. The housing comes with a convenient DC “bullet” plug that connects to the IR assembly, and there is another pair of wires that come off the IR assembly to supply your camera, but they supply the same 12V. I connected these to a buck an adjustable buck regulator – a really convenient and efficient regulator that costs about 5 bucks on Amazon and can take a variety of input voltage and output whatever you adjust it to…in my case 5V. I then fed the 5V in to the USB power connector on the Pi by cutting up a USB cable and splicing it in.
To improve stability a bit more, I tweaked the restart scripts (already reflected in the code, above). I also changed the output redirection, so it doesn’t spit stuff out to the console and redirects it to vlc.log properly.
Next, I created a script to check that the WiFi is connected, and force an attempt to reconnect if not. Then I set that up to run every five minutes via cron.
if [ $count -eq 0 ]; then
# 100% failed
echo “Restarting wifi”
sudo /sbin/ifdown wlan0
sudo /sbin/ifup –force wlan0
echo “Wifi looks good!”
5 * * * * root /home/pi/check-wifi.sh
Finally, created a monitor in iSpy, so that if the connection is lost and reconnect failes, iSpy will launch a script to automatically try to restart the service.
First, I set up my pc so you can ssh to the PiCam without entering a password. After installing cygwin and making sure the cygwin\bin directory is in my default system PATH, I set up an encrypted keypair using this example on StackOverflow: http://stackoverflow.com/questions/16928004/how-to-enter-ssh-password-using-bash
Then I created a batch file to call the service restart command remotely and registerrd it as the “Reconnect Failed” Action in iSpy:
rem try 5 times set /A count = 5 :DoWhile if %count% == 0 goto EndDoWhile set /A count = %count% -1 ssh email@example.com sudo service vlc-streamer restart if %errorlevel% == 0 goto EndDoWhile if %count% GTR 0 goto DoWhile :EndDoWhile exit \B