- 2006-11-05: I did a quick presentation to the Scarborough Linux Group about how I got the webcam to work, so I may as well write it up here.
- The webcam is a Neu Fusion enhanced SohoCam NCS-330W from network-camera.co.uk, which tells you a few things. The first is, it isn't a camera you just attach to your PC, it's a camera that can be connect directly to the network. I thought that was more likely to be accepted by Linux. The second is it's wireless, so I can site it anywhere in the house without having to do the cabling, and I can move it around if I want.
- I didn't want to punch a hole in my firewall to open up the camera to the outside world, I wanted to take the images from the camera and FTP them to my web server. I feel that's more secure.
- I did get it working on Fedora Core 4, but I've just installed 6 and this is me trying to get it to work there.
- The first thing is the camera has a web interface, so I stretched a 30metre Belkin ethernet cable from my office to the camera, opened a browser, and connected to its IP address. This showed the image from the camera, confirming it's working and creating an image .. it has power, it's in focus, it's pointing in the right direction and so on. Focussing this camera during initial setup was a real bitch.
- Because the IP addresses on my network are allocated by DHCP, the address is often different from what I've written in my notes from last time, but since my router only has four ethernet ports there are only four addresses to choose from so it doesn't take long to work out which it's currently using.
- In System Administration>configuration there are a few settings to think about. Under Video are the quality settings for the camera, and under Wireless are all the settings to allow the camera to connect over wireless to my wireless router; obviously those settings need to match. Under Network I set the camera to get its address using DHCP. There's the date and time to set, and then there's Upload, which I set to FTP the picture every minute to my home directory. It needs to know the IP address of the FTP server, so on my main machine I found that from a terminal screen by typing /sbin/ifconfig. It gave me two addresses, 127.0.0.1 which is my local loopback address, and 192.168.nnn.nnn which is my actual IP address, and will remain so until I power something down. Yes, OK, this bit could be improved, but since I installed the camera I rarely power down, so I still prefer the plug and play benefits of DHCP over having to set IP addresses manually. I put that address into the FTP server host address field of the webcam's configuration screen and saved it. Now, if I disconnect the ethernet cable, the camera should be attempting to deliver its image every minute to my main machine's FTP server.
- Do I have an FTP server on my machine? On my Fedora machine, under System>Administration>Server Settings>Services, it took me a while, originally, to work out that vsftpd is the FTP server daemon, the software that sits around waiting for an FTP server request to handle. That needed to be clicked and started and saved.
- So now we should have an image being delivered every minute from the camera to my home directory. I used ls -l to get a full listing of that directory in a terminal window to see if the webcam image file date and time kept changing. I had to wait for more than two minutes before I knew for sure.
- Nothing was appearing. I thought Fedora's firewall was probably stopping it. Under System>Administration>Security level and firewall, it shows FTP as a trusted service, so it should be working. SE Linux is installed here, whereas I didn't install it under FC4. I turned off the firewall to see if that's the problem. No, still nothing.
- I powered up another machine to see if I could connect to my main machine's FTP service. The other machine's Linux too, I'm glad I could still remember my password to get in. I use a Linksys KVM 2-part switch so I can use the same keyboard and screen and switch between the two machines. I ran ifconfig on that machine too to check I was on the network, then tried to ping my first machine with 'ping 192.168.nnn.nnn'. That returned one line of data OK, then just stopped. Not sure what that means, but at least one line of data means we have a connection.
- I tried manually FTPing my main machine. 'ftp' dropped me into that mode, and 'help' got me a bunch of options. 'open' seems reasonable, so I tried 'open 192.168.nnn.nnn'. It asked me for my username and password, that's a good sign that means I'm talking to the FTP server. I logged in using my normal username and password, and it gave me an error: "500: OOPS, cannot change directory:/home/John". Hmm. That needs a ponder. It sounds like a permissions thing, but it won't let me log in as 'root' to check.
- A Google on the error turns up a few opinions, SE Linux may be the culprit, a look into the logfile with 'tail /var/log/messages' reveals a series of errors I don't really understand from vsftpd but including the word 'denied' which again suggests permissions.
- Another wander around the security level menu revealed that, although I'd stopped the firewall, SE Linux was still operating, so I disabled that, and within a minute an image file appeared in my home directory. That opened and looked about right.
- I put the firewall back up to check if I could run like that for now, and yes, the file refreshed.
- So now I had to get that file to my web server. I needed two things for that, a terminal-based command to send the file over FTP to my server, and a cron job to call that every minute.
- Previously I'd created a file called putCam.txt which contained the FTP commands, but it wasn't where I expected it to be after I transferred everything over to my new hard disc, so I used 'find / -name putCam.txt' to find it. Obviously its permissions needed to be set to make it executable (chmod). Here are the contents (you'll have to use the right URL and file names for your server):
put /home/John/webcam.jpg /www/webcam.jpg
- So we're almost there, we just need to set up the cron job. 'man cron' reminded me to look in 'man crontab' because that's the file I needed to edit, and that reminded me that 'crontab -l' lists my cron jobs (currently giving "There are no cron jobs for John"), and 'crontab -e' allows me to edit it using a vi style editor. I need to add a line '* * * * * /home/John/putCam.txt', which in Vi means i to get into insert mode, type in that line, then ESC to get back to command mode, then :w and :q (obviously). Then wait and see if the web page gets refreshed. I don't like Vi, apparently the type of editor you get is set in the 'editor' system variable .. I know nothing about that.
- It wasn't refreshing. Running /home/John/putCam.txt directly told me login was being rejected. I remembered why. The FTP program looks to a file to collect the username and password it needs to log in, and I hadn't set that up. Maybe 'man ftp' will help .. oh yes, near the end it said I need to set up a file called .netrc in my home directory containing machine johnallsopp.co.uk login [name] password [password]. That didn't work. Hmm. It turned out I'd saved it to the wrong directory. Duh!
- Running putCam.txt directly I got 'Error - .netrc file not correct mode. Remove password or correct mode'. I checked the content is the same as the file on my old system. The solution turned out to be in the man page where it says that if .netrc contains a password for you, only you should be able to read the file. So chmodding 'read' off for group and other, meant the darn jiggly thing worked.
- So now you can watch the Scarborough fireworks. Well, if you can make them out among the artifacts. Pity, there are supposed to be beach fireworks tonight, and that's the direction the camera is pointing. Maybe you'll see something. Ooooh. Aaaaaah. I just spotted one. No really, I did.
- Oh, I'd forgotten to disconnect the network cable, so I just had to check it's still transferring the file OK from the camera to my server over wireless, and it was. Hurrah.
By John Allsopp
Back to blog list