Use Raspberry Pi to build LAN monitoring

Today, I will introduce how to use Raspberry Pi and a USB camera to build a simple monitoring. With it, you can view the dynamic images captured by the camera on the computer.

1. Camera detection

Raspberry Pi supports many common USB cameras, such as the one used by Liang Xu:

This type of camera can be directly powered by USB and communicate data through the USB cable. Its connection with the Raspberry Pi is also very simple, just plug it directly into the USB port of the Raspberry Pi.

How do you know if it is recognized by the Raspberry Pi after plugging it in? We have two methods to determine:

Method 1: Check if there is a video0 file in the /dev/ directory

pi@raspberrypi:~ $ ls /dev/video*
/dev/video0

Method 2: Check the USB device to see if there is a new device

pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 0458:706d KYE Systems Corp. (Mouse Systems) Genius iSlim 2000AF V2    #识别到的 USB 摄像头
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

2. Install the motion program

Here we take the official system Raspbian as an example. To install motion, just enter the following command:

sudo apt-get install motion

If you cannot install, you may have to execute the following two commands first:

sudo apt-get update
sudo apt-get upgrade

3. Configure motion daemon

Use vim to modify /etc/default/motion. If vim is not installed on the system, you need to install it in advance, or use the nano editor.

sudo vim /etc/default/motion

We change the no inside to yes to make the daemon run in the background all the time:

# set to 'yes' to enable the motion daemon
start_motion_daemon=yes

4. Modify the configuration file of motion

First, open the motion configuration file with vim or nano:

sudo vim /etc/motion/motion.conf

The configuration file is a bit long, but there are several options that must be changed, and the rest can be defaulted.

We need to change daemon off to daemon on and stream_localhost on to stream_localhost off. These two are not in the same location and need to be searched to determine.

# Start in daemon (background) mode and release terminal (default: off)
daemon on

# Restrict stream connections to localhost only (default: on)
stream_localhost off

Of course, we can also change its screen display size:

# Image width (pixels). Valid range: Camera dependent, default: 352
width 800

# Image height (pixels). Valid range: Camera dependent, default: 288
height 600

Use: wq to save and exit after changing.

5. Start configuration

First, start the motion service:

sudo service motion start

Then, start motion again:

pi@raspberrypi:~ $ sudo motion
[0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started
[0:motion] [NTC] [ALL] motion_startup: Logging to file (/var/log/motion/motion.log)

6. View the effect

After completing the above steps, you can view the effect in the browser. However, when Liang Xu uses the 360 ​​browser, he can't see the effect, and when he uses the Google browser , everything is normal. It is said on the Internet that Firefox can also be used, but I haven't tried it.

Open the Google browser and enter the URL: http://Raspberry Pi IP:8081 , you can view the image captured by the camera. The IP address of the Raspberry Pi can be seen in the background management of the router, or it can be searched using an IP scanner, so I won’t go into details here.

Finally, recently many friends asked me for the Linux learning roadmap , so based on my experience, I spent a month staying up late in my spare time and compiled an e-book. Whether you are in an interview or self-improvement, I believe it will help you! The directory is as follows:

Give it to everyone for free, just ask you to give me a thumbs up!

Ebook | Linux development learning roadmap

I also hope that some friends can join me to make this e-book more perfect!

Gain? I hope the old irons will have a three-strike combo so that more people can read this article

Recommended reading:

Guess you like

Origin blog.csdn.net/yychuyu/article/details/108132935