May 112010
 

I’ve mentioned my Panasonic BL-C1A network cameras before in a post about monitoring the garage door. I happen to have two of these cameras, and I have automated them to do quite a lot for me. The software that comes with the cameras is pretty lousy, and it makes you think you have to use Internet Explorer and nothing else to look at the images coming out of the camera. Well, I can tell you it’s not true. Although, if you want to use the ActiveX controlling software that comes with the camera, you are limited to only IE. Not good enough for me. I want to be able to see the images on my cell phone, and I don’t like being tied to a single browser, especially IE. For instance, wget (as I used in yesterday’s post about pulling images from a web site) could be used to pull the images from the camera. I also want the images to be saved on a web server so that if my cameras themselves are stolen, or if my home computer is stolen, I will still have a backup of the images. Now, I don’t normally store or watch video from the cameras, but instead focus on storing still images. I can watch video, but I don’t currently know of an easy way to save the video to my web server.

There will be several steps to this process. First install the camera. Next, set up the port forwarding on your router so you can view the camera from outside your local network. Then we will set up some cron jobs on the web server to retrieve and save the images. Finally we will set up a web page so we can view the images that have been saved. If desired, the entire system can be controlled by the home automation system, and I will show you how I did that as well.

The first thing to do is install the cameras. Install the cameras using the software provided, but don’t worry. We won’t be sticking with that software. Make sure you can connect to your camera from a computer on your local network, using the software provided. I would now recommend that you set static IP addresses for your cameras. It defaults that way, so this should not be a problem. The default IP address should be something like 192.168.x.253, where ‘x’ is the same number as the rest of your networked computers, probably a 1 or a 0. Also, set the port to some high number, such as 8001. You will also want to set usernames and passwords for the camera. Next, using the IP address for the camera, use your NON-Internet Explorer web browser to view the images by going to this website:
192.168.x.253:8001?mode=local
If that works, then we have lots of other options:

http://192.168.x.253:8001/SnapshotJPEG?Resolution=320×240&Quality=Precision&mode=local

http://192.168.x.253:8001/SnapshotJpeg?Resolution=640×480&Quality=Standard&mode=local

http://192.168.x.253:8001/ImageViewer?Resolution=640×480&Quality=Standard&mode=local

There is a little more information about these addresses here:

http://tatethatcher.com/wp/archives/57

Great. Now we can see the images with any web browser. Video still requires a web browser that can handle java. Now let’s set it up so we can view the images from outside our local network by using port forwarding.

If you have a cable modem or DSL that is connected to the internet all the time, then you can probably set up port forwarding with that device. I use the world famous Linksys WRT-54G with the upgraded firmware DD-WRT. I certainly can’t tell you how to do this on every device out there, but port forwarding is quite common and searching google for “port forwarding yourdevicename” should give you a good place to start. However, the idea is simple. You want your router to recognize incoming traffic on a certain port and then automatically forward it to another port, such as 8001 in this case. The idea here is that you could be on a public computer in your library and go to http://some_site_yet_to_be_named.com:someportnumber and you will see the video on that camera. If you have more than one camera, you would go to the same site, but a different port number, such as http://some_site_yet_to_be_named.com:someotherportnumber. I used the same portnumber, 8001, but you could use a different one. So I can go to http://mysecretsite:8001 from any browser and see the video. So I need to go into the firmware settings for the router, and I will want to forward any traffic that comes into http://mysecretsite:8001 to http://192.168.x.253:8001. The port forwarding rules will not need to know anything about “mysecretsite”, so you won’t find any place to enter that setting. All you will have to enter is the incoming port, outgoing IP address and outgoing port. The incoming and outgoing ports in this case are both 8001 and the outgoing IP address is 192.168.x.253. At this point you could check and make sure the port forwarding is working by going to your router’s IP address (find it by going to http://whatismyip.com) followed by :8001, such as http://123.45.67.890:8001.

Related to the port forwarding is dynamic DNS. If you are lucky enough to have a static IP address, you can skip this paragraph. Otherwise you will need to follow the steps here to create a dynamic DNS host name. You can set up a free account at http://dyndns.com. Once your account is set up, add a host service with a hostname that you can remember. Have it point to your current IP address for now, but you will want to configure automatic updating. You can either use free software or even easier, you might be able to configure the automatic updating right within your router. If it works, you should be able to go to your new host:

http://mynewhost.homedns.org:8001/SnapshotJpeg?Resolution=640×480&Quality=Standard&mode=local

and see the images from the camera. At this point step two is complete. You can save that URL and you will always be able to view your camera from any web browser on the internet.

The last step is to set up some cron jobs on your web server to grab the images from your camera and save them to a specific directory on your web server. This way you will be able to review past images as needed. It will require you to have a web server that you have shell access to. Some web hosts out there that do allow shell access do not allow scripts to run for extended periods of time. I use dreamhost (http://dreamhost.com), which works perfectly.

#!/bin/bash
# getfamroomwebcam.sh

while :
do
THISFILE=`date +/home/httpdocs/FamilyRoomWebCam/%Y%m%d%H%M%S.jpg`
wget --http-user=camera_user --http-passwd=topsecret -O ${THISFILE} -q http://mynewhost.homedns.org:8001/SnapshotJpeg?Resolution=640x480&Quality=Standard&mode=local
sleep 20
chmod 644 ${THISFILE}
done

As long as this script is running it will grab a new image from the camera every 20 seconds. It saves the images with a timestamped file name. You could configure this to start running at server startup, maybe have a cron job that checks to see if it is running periodically (like once an hour) and if it finds that the script is not running, restart it. I have it set up so that whenever I arm my burglar alarm (Elk M1G), the elk sends an email to my web server with a special code. Procmail reads the email and if it sees the special code, it starts (or stops, on disarming) the script. Here is my Procmail script to start the web cam:
:0
* ^Subject:.*SecretStartCode
{
:0w
| /home/script/getfamroomwebcam.sh &

:0
/dev/null
}

Finally, I have another cron job to delete old pictures every night. Otherwise the picture directory would get very full very fast. I don’t think dreamhost would like that at all.

find /home/httpdocs/FamilyRoomWebCam -mtime +3 -exec rm {} \;

This will delete any pictures older than three days old.

The very last step is I wrote a small web page to display the images. It uses javascript to play the images in a slideshow, or it can display all images from a specific time period. For now I will leave that up to you, but I will post the code for it in a few days.

Leave a Reply