One day I was looking at my fishtank and thought it would be nice to see my fish behaving naturally. The problem with sitting in front of the tank is they recognise someone is there and go into their “feeding” pattern – rising to the top of the tank in expectation of food.
If I added a webcam, I could push my RPi temperature display into service. As a bonus, I could measure the temperature of the tank at the same time.
I found a convenient fork of mjpg-streamer that works well with the Pi and my webcam (A Logitech QuickCam Pro 9000). In the README, mjpg-streamer it says it needs cmake and libjpeg-dev, so let’s prepare with:
apt-get install cmake libjpeg62-dev
git clone https://github.com/jacksonliam/mjpg-streamer.git cd mjpg-streamer make clean install
Assuming it compiles correctly and you ran it as root, this installs:
- Binaries to /usr/local/bin
- Library files to /usr/local/lib
- The web root directory to /usr/local/www
You can test it by running a command like this as root:
/usr/local/bin/mjpg_streamer -b -i "/usr/local/lib/input_uvc.so -r 640x480 -f 5" -o "/usr/local/lib/output_http.so -w /usr/local/www"
It should tell you it enabled daemon mode and forked to background. Then try and access your rPi’s IP address on port 8080 and you should get the MJPG-streamer demo pages and be able to see your webcam images.
Problem! My webcam was out of focus. Solution:
apt-get install uvcdynctrl uvcdynctrl -i /usr/share/uvcdynctrl/data/046d/logitech.xml
For some reason uvcdynctrl ships with an XML file including the focus feature but is not enabled by default. Importing it enables the focus control.
The mjpg-streamer and uvcdynctrl commands can now be added to /etc/rc.local so they run at boot time.
I also replaced the demo pages with a very simple index.html file. This is the relevant image tag to display the stream:
<img src="/?action=stream" />
Success! (This is a screencap, not a live stream!)
2,998 total views, 3 views today