Configuring a Node (Webcam) - jonatello/farmalytics GitHub Wiki
In addition to the sensors a webcam can be easily added to a node for streaming and capturing timelapses.
In this example we are using a USB webcam (Logitech C270) and a package called Motion. Motion streams by default on port 8081
Configure the hardware
All we need to do here is connect the USB webcam to the micro USB port on the Pi, we can then make sure it's identified with the following command, which should list out some information about any USB devices
lsusb
If using a Raspberry Pi camera (non-USB) you can enable it via 'raspi-config' and then selecting "Interfacing Options" > "Camera" > "Enabled"
Configure Motion
First we will install the package via apt
sudo apt-get install motion
Next we will update the configuration with the following lines (you can also use motion.conf):
- Enable the daemon (skip this step for Bookworm, was only necessary in previous versions)
sudo sed -i 's/daemon off/daemon on/g' /etc/motion/motion.conf
- Set the framerate to 30 if desired (I skip this since they're still images)
sudo sed -i 's/framerate 2/framerate 30/g' /etc/motion/motion.conf
- Allow streaming from non-localhost
sudo sed -i 's/stream_localhost on/stream_localhost off/g' /etc/motion/motion.conf
- Allow control connections from non-localhost
sudo sed -i 's/webcontrol_localhost on/webcontrol_localhost off/g' /etc/motion/motion.conf
- Set the width to 1280 and height to 720
sudo sed -i 's/width 320/width 1280/g' /etc/motion/motion.conf
sudo sed -i 's/height 240/height 720/g' /etc/motion/motion.conf
- Disable saving pictures to prevent storage from filling up
sudo sed -i 's/output_pictures off/output_pictures on/g' /etc/motion/motion.conf
- Set motion threshold so that it never triggers
sudo sed -i 's/threshold 1500/threshold 2147483647/g' /etc/motion/motion.conf
- Enable the daemon to start
sudo sed -i 's/start_motion_daemon=no/start_motion_daemon=yes/g' /etc/motion/motion.conf
There are many different configuration changes and tweaks that can be made for Motion, I won't attempt to cover them all here but this is a good reference - https://motion-project.github.io/motion_config.html#basic_setup_picam
Enable and start the daemon
sudo systemctl enable motion
sudo systemctl start motion
Now that the daemon is started we can browse to the IP on port 8080 and 8081 to view the output of the webcam.